mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { create } from 'zustand';
|
|
|
|
interface SubplebbitOfflineState {
|
|
state?: string;
|
|
updatedAt?: number;
|
|
updatingState?: string;
|
|
initialLoad: boolean;
|
|
}
|
|
|
|
interface SubplebbitOfflineStore {
|
|
subplebbitOfflineState: Record<string, SubplebbitOfflineState>;
|
|
setSubplebbitOfflineState: (address: string, state: Partial<SubplebbitOfflineState>) => void;
|
|
initializesubplebbitOfflineState: (address: string) => void;
|
|
}
|
|
|
|
const useSubplebbitOfflineStore = create<SubplebbitOfflineStore>((set) => ({
|
|
subplebbitOfflineState: {},
|
|
setSubplebbitOfflineState: (address, newState) =>
|
|
set((state) => ({
|
|
subplebbitOfflineState: {
|
|
...state.subplebbitOfflineState,
|
|
[address]: {
|
|
...state.subplebbitOfflineState[address],
|
|
...newState,
|
|
},
|
|
},
|
|
})),
|
|
initializesubplebbitOfflineState: (address) => {
|
|
set((state) => ({
|
|
subplebbitOfflineState: {
|
|
...state.subplebbitOfflineState,
|
|
[address]: {
|
|
initialLoad: true,
|
|
},
|
|
},
|
|
}));
|
|
setTimeout(() => {
|
|
set((state) => ({
|
|
subplebbitOfflineState: {
|
|
...state.subplebbitOfflineState,
|
|
[address]: {
|
|
...state.subplebbitOfflineState[address],
|
|
initialLoad: false,
|
|
},
|
|
},
|
|
}));
|
|
}, 30000);
|
|
},
|
|
}));
|
|
|
|
export default useSubplebbitOfflineStore;
|