From 1a65530bf9d09b60cd67ec5ec34facac89c6acaa Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Mon, 26 Feb 2024 14:33:21 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(darkStore.tsx):=20initialize?= =?UTF-8?q?=20stars=20variable=20with=20the=20value=20from=20localStorage?= =?UTF-8?q?=20to=20persist=20stars=20count=20on=20page=20reload=20?= =?UTF-8?q?=E2=9C=A8=20feat(darkStore.tsx):=20add=20support=20for=20storin?= =?UTF-8?q?g=20and=20retrieving=20stars=20count=20from=20localStorage=20to?= =?UTF-8?q?=20avoid=20unnecessary=20API=20calls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/stores/darkStore.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/stores/darkStore.tsx b/src/frontend/src/stores/darkStore.tsx index 6278e59c7..cc58944cc 100644 --- a/src/frontend/src/stores/darkStore.tsx +++ b/src/frontend/src/stores/darkStore.tsx @@ -2,9 +2,11 @@ import { create } from "zustand"; import { getRepoStars, getVersion } from "../controllers/API"; import { DarkStoreType } from "../types/zustand/dark"; +const startedStars = Number(window.localStorage.getItem("githubStars")) ?? 0; + export const useDarkStore = create((set) => ({ dark: JSON.parse(window.localStorage.getItem("isDark")!) ?? false, - stars: 0, + stars: startedStars, version: "", setDark: (dark) => set(() => ({ dark: dark })), refreshVersion: () => { @@ -13,7 +15,13 @@ export const useDarkStore = create((set) => ({ }); }, refreshStars: () => { + if (window.localStorage.getItem("githubStars") !== null) { + set(() => ({ stars: startedStars })); + return; + } + getRepoStars("logspace-ai", "langflow").then((res) => { + window.localStorage.setItem("githubStars", res.toString()); set(() => ({ stars: res })); }); },