diff --git a/lemmy-translations b/lemmy-translations index abd40d47..b0d80808 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit abd40d4737fa732321fd7b62e42bbfcd51081cb6 +Subproject commit b0d80808047eb547aa995e923e9c742e87cd8be7 diff --git a/src/shared/components/home/home.tsx b/src/shared/components/home/home.tsx index cac283ab..742d40cd 100644 --- a/src/shared/components/home/home.tsx +++ b/src/shared/components/home/home.tsx @@ -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, @@ -288,18 +283,12 @@ export class Home extends Component { postsRes, isIsomorphic: true, }; - - HomeCacheService.postsRes = postsRes; } this.state.tagline = getRandomFromList(this.state?.siteRes?.taglines ?? []) ?.content; } - componentWillUnmount() { - HomeCacheService.activate(); - } - async componentDidMount() { if ( !this.state.isIsomorphic || @@ -812,28 +801,16 @@ export class Home extends Component { 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({ diff --git a/src/shared/services/HomeCacheService.ts b/src/shared/services/HomeCacheService.ts deleted file mode 100644 index 3b767361..00000000 --- a/src/shared/services/HomeCacheService.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { GetPostsResponse } from "lemmy-js-client"; -import { EMPTY_REQUEST, RequestState } from "./HttpService"; - -/** - * Service to cache home post listings and restore home state when user uses the browser back buttons. - */ -export class HomeCacheService { - static #_instance: HomeCacheService; - historyIdx = 0; - scrollY = 0; - posts: RequestState = EMPTY_REQUEST; - - get active() { - return ( - this.historyIdx === window.history.state.idx + 1 && - this.posts.state === "success" - ); - } - - deactivate() { - this.historyIdx = 0; - } - - activate() { - this.scrollY = window.scrollY; - this.historyIdx = window.history.state.idx; - } - - static get #Instance() { - return this.#_instance ?? (this.#_instance = new this()); - } - - public static get scrollY() { - return this.#Instance.scrollY; - } - - public static get historyIdx() { - return this.#Instance.historyIdx; - } - - public static set postsRes(posts: RequestState) { - this.#Instance.posts = posts; - } - - public static get postsRes() { - return this.#Instance.posts; - } - - public static get active() { - return this.#Instance.active; - } - - public static deactivate() { - this.#Instance.deactivate(); - } - - public static activate() { - this.#Instance.activate(); - } -} diff --git a/src/shared/services/index.ts b/src/shared/services/index.ts index bee22f1e..1fe91f98 100644 --- a/src/shared/services/index.ts +++ b/src/shared/services/index.ts @@ -1,5 +1,4 @@ export { FirstLoadService } from "./FirstLoadService"; -export { HomeCacheService } from "./HomeCacheService"; export { HttpService } from "./HttpService"; export { I18NextService } from "./I18NextService"; export { UserService } from "./UserService";