Refactored stars and version refreshing
This commit is contained in:
parent
f87379c3d7
commit
4a3035873b
5 changed files with 24 additions and 29 deletions
|
|
@ -17,7 +17,7 @@ import {
|
||||||
} from "./constants/constants";
|
} from "./constants/constants";
|
||||||
import { AuthContext } from "./contexts/authContext";
|
import { AuthContext } from "./contexts/authContext";
|
||||||
import { locationContext } from "./contexts/locationContext";
|
import { locationContext } from "./contexts/locationContext";
|
||||||
import { getHealth, getVersion } from "./controllers/API";
|
import { getHealth, getRepoStars, getVersion } from "./controllers/API";
|
||||||
import Router from "./routes";
|
import Router from "./routes";
|
||||||
import useAlertStore from "./stores/alertStore";
|
import useAlertStore from "./stores/alertStore";
|
||||||
import { useTypesStore } from "./stores/typesStore";
|
import { useTypesStore } from "./stores/typesStore";
|
||||||
|
|
@ -132,10 +132,14 @@ export default function App() {
|
||||||
|
|
||||||
const { isAuthenticated } = useContext(AuthContext);
|
const { isAuthenticated } = useContext(AuthContext);
|
||||||
const refreshFlows = useFlowsManagerStore((state) => state.refreshFlows);
|
const refreshFlows = useFlowsManagerStore((state) => state.refreshFlows);
|
||||||
const setVersion = useDarkStore((state) => state.setVersion);
|
|
||||||
const getTypes = useTypesStore((state) => state.getTypes);
|
const getTypes = useTypesStore((state) => state.getTypes);
|
||||||
|
const refreshVersion = useDarkStore((state) => state.refreshVersion);
|
||||||
|
const refreshStars = useDarkStore((state) => state.refreshStars);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
refreshStars();
|
||||||
|
refreshVersion();
|
||||||
|
|
||||||
// If the user is authenticated, fetch the types. This code is important to check if the user is auth because of the execution order of the useEffect hooks.
|
// If the user is authenticated, fetch the types. This code is important to check if the user is auth because of the execution order of the useEffect hooks.
|
||||||
if (isAuthenticated === true) {
|
if (isAuthenticated === true) {
|
||||||
// get data from db
|
// get data from db
|
||||||
|
|
@ -144,9 +148,6 @@ export default function App() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getVersion().then((data) => {
|
|
||||||
setVersion(data.version);
|
|
||||||
});
|
|
||||||
}, [isAuthenticated]);
|
}, [isAuthenticated]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ export default function Header(): JSX.Element {
|
||||||
const dark = useDarkStore((state) => state.dark);
|
const dark = useDarkStore((state) => state.dark);
|
||||||
const setDark = useDarkStore((state) => state.setDark);
|
const setDark = useDarkStore((state) => state.setDark);
|
||||||
const stars = useDarkStore((state) => state.stars);
|
const stars = useDarkStore((state) => state.stars);
|
||||||
const gradientIndex = useDarkStore((state) => state.gradientIndex);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (dark) {
|
if (dark) {
|
||||||
|
|
@ -167,7 +166,7 @@ export default function Header(): JSX.Element {
|
||||||
<button
|
<button
|
||||||
className={
|
className={
|
||||||
"h-7 w-7 rounded-full focus-visible:outline-0 " +
|
"h-7 w-7 rounded-full focus-visible:outline-0 " +
|
||||||
(userData?.profile_image ?? gradients[gradientIndex])
|
(userData?.profile_image ?? gradients[parseInt(userData?.id ?? "", 30) % gradients.length])
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,7 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
Password{" "}
|
Password{" "}
|
||||||
</Form.Label>
|
</Form.Label>
|
||||||
<InputComponent
|
<InputComponent
|
||||||
|
id="pasword"
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
handleInput({ target: { name: "password", value } });
|
handleInput({ target: { name: "password", value } });
|
||||||
}}
|
}}
|
||||||
|
|
@ -119,6 +120,7 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
</Form.Label>
|
</Form.Label>
|
||||||
|
|
||||||
<InputComponent
|
<InputComponent
|
||||||
|
id="cnfPassword"
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
handleInput({ target: { name: "cnfPassword", value } });
|
handleInput({ target: { name: "cnfPassword", value } });
|
||||||
}}
|
}}
|
||||||
|
|
@ -144,9 +146,9 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
<GradientChooserComponent
|
<GradientChooserComponent
|
||||||
value={
|
value={
|
||||||
gradient == ""
|
gradient == ""
|
||||||
? userData!.profile_image ??
|
? userData?.profile_image ??
|
||||||
gradients[
|
gradients[
|
||||||
parseInt(userData!.id ?? "", 30) % gradients.length
|
parseInt(userData?.id ?? "", 30) % gradients.length
|
||||||
]
|
]
|
||||||
: gradient
|
: gradient
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,20 @@
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import { getRepoStars } from "../controllers/API";
|
import { getRepoStars, getVersion } from "../controllers/API";
|
||||||
import { DarkStoreType } from "../types/zustand/dark";
|
import { DarkStoreType } from "../types/zustand/dark";
|
||||||
|
|
||||||
function gradientIndexInitialState() {
|
|
||||||
const min = 0;
|
|
||||||
const max = 30;
|
|
||||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useDarkStore = create<DarkStoreType>((set) => ({
|
export const useDarkStore = create<DarkStoreType>((set) => ({
|
||||||
dark: JSON.parse(window.localStorage.getItem("isDark")!) ?? false,
|
dark: JSON.parse(window.localStorage.getItem("isDark")!) ?? false,
|
||||||
stars: 0,
|
stars: 0,
|
||||||
gradientIndex: gradientIndexInitialState(),
|
|
||||||
version: "",
|
version: "",
|
||||||
setVersion: (version) => set(() => ({ version: version })),
|
|
||||||
setDark: (dark) => set(() => ({ dark: dark })),
|
setDark: (dark) => set(() => ({ dark: dark })),
|
||||||
setStars: (starts) => set(() => ({ stars: starts })),
|
refreshVersion: () => {
|
||||||
setGradientIndex: (gradientIndex) =>
|
getVersion().then((data) => {
|
||||||
set(() => ({ gradientIndex: gradientIndex })),
|
set(() => ({ version: data.version }));
|
||||||
}));
|
|
||||||
|
|
||||||
getRepoStars("logspace-ai", "langflow").then((res) => {
|
|
||||||
useDarkStore.setState({ stars: res });
|
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
refreshStars: () => {
|
||||||
|
getRepoStars("logspace-ai", "langflow").then((res) => {
|
||||||
|
set(() => ({ stars: res }));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
export type DarkStoreType = {
|
export type DarkStoreType = {
|
||||||
dark: boolean;
|
dark: boolean;
|
||||||
stars: number;
|
stars: number;
|
||||||
gradientIndex: number;
|
|
||||||
version: string;
|
version: string;
|
||||||
setVersion: (version: string) => void;
|
|
||||||
setDark: (dark: boolean) => void;
|
setDark: (dark: boolean) => void;
|
||||||
setStars: (stars: number) => void;
|
refreshVersion: () => void;
|
||||||
setGradientIndex: (gradientIndex: number) => void;
|
refreshStars: () => void;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue