Skip to content

Commit

Permalink
Fix back button from posts going back twice instead of once (LemmyNet…
Browse files Browse the repository at this point in the history
  • Loading branch information
SleeplessOne1917 authored Nov 14, 2023
1 parent b40a3c3 commit ad300f1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 96 deletions.
45 changes: 11 additions & 34 deletions src/shared/components/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,7 @@ import {
InitialFetchRequest,
} from "../../interfaces";
import { mdToHtml } from "../../markdown";
import {
FirstLoadService,
HomeCacheService,
I18NextService,
UserService,
} from "../../services";
import { FirstLoadService, I18NextService, UserService } from "../../services";
import {
EMPTY_REQUEST,
HttpService,
Expand Down Expand Up @@ -288,18 +283,12 @@ export class Home extends Component<any, HomeState> {
postsRes,
isIsomorphic: true,
};

HomeCacheService.postsRes = postsRes;
}

this.state.tagline = getRandomFromList(this.state?.siteRes?.taglines ?? [])
?.content;
}

componentWillUnmount() {
HomeCacheService.activate();
}

async componentDidMount() {
if (
!this.state.isIsomorphic ||
Expand Down Expand Up @@ -812,28 +801,16 @@ export class Home extends Component<any, HomeState> {
const { dataType, pageCursor, listingType, sort } = getHomeQueryParams();

if (dataType === DataType.Post) {
if (HomeCacheService.active) {
const { postsRes, scrollY } = HomeCacheService;
HomeCacheService.deactivate();
this.setState({ postsRes });
window.scrollTo({
left: 0,
top: scrollY,
});
} else {
this.setState({ postsRes: LOADING_REQUEST });
this.setState({
postsRes: await HttpService.client.getPosts({
page_cursor: pageCursor,
limit: fetchLimit,
sort,
saved_only: false,
type_: listingType,
}),
});

HomeCacheService.postsRes = this.state.postsRes;
}
this.setState({ postsRes: LOADING_REQUEST });
this.setState({
postsRes: await HttpService.client.getPosts({
page_cursor: pageCursor,
limit: fetchLimit,
sort,
saved_only: false,
type_: listingType,
}),
});
} else {
this.setState({ commentsRes: LOADING_REQUEST });
this.setState({
Expand Down
60 changes: 0 additions & 60 deletions src/shared/services/HomeCacheService.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/shared/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { FirstLoadService } from "./FirstLoadService";
export { HomeCacheService } from "./HomeCacheService";
export { HttpService } from "./HttpService";
export { I18NextService } from "./I18NextService";
export { UserService } from "./UserService";
Expand Down

0 comments on commit ad300f1

Please sign in to comment.