1 import { GetPostsResponse } from "lemmy-js-client";
2 import { RequestState } from "./HttpService.js";
5 * Service to cache home post listings and restore home state when user uses the browser back buttons.
7 export class HomeCacheService {
8 static #_instance: HomeCacheService;
11 posts: RequestState<GetPostsResponse> = { state: "empty" };
15 this.historyIdx === window.history.state.idx + 1 &&
16 this.posts.state === "success"
25 this.scrollY = window.scrollY;
26 this.historyIdx = window.history.state.idx;
29 static get #Instance() {
30 return this.#_instance ?? (this.#_instance = new this());
33 public static get scrollY() {
34 return this.#Instance.scrollY;
37 public static get historyIdx() {
38 return this.#Instance.historyIdx;
41 public static set postsRes(posts: RequestState<GetPostsResponse>) {
42 this.#Instance.posts = posts;
45 public static get postsRes() {
46 return this.#Instance.posts;
49 public static get active() {
50 return this.#Instance.active;
53 public static deactivate() {
54 this.#Instance.deactivate();
57 public static activate() {
58 this.#Instance.activate();