2024-05-31 10:41:44 +02:00
|
|
|
import { create } from 'zustand';
|
|
|
|
|
|
|
|
|
|
interface FeedResetState {
|
|
|
|
|
reset: (() => void) | null;
|
2026-04-27 14:59:24 +07:00
|
|
|
currentResetFunction: (() => void) | null;
|
2024-05-31 10:41:44 +02:00
|
|
|
setResetFunction: (resetFunction: () => void) => void;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-27 14:59:24 +07:00
|
|
|
const invokeCurrentResetFunction = () => {
|
|
|
|
|
useFeedResetStore.getState().currentResetFunction?.();
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-31 10:41:44 +02:00
|
|
|
const useFeedResetStore = create<FeedResetState>((set) => ({
|
|
|
|
|
reset: null,
|
2026-04-27 14:59:24 +07:00
|
|
|
currentResetFunction: null,
|
|
|
|
|
setResetFunction: (resetFunction) =>
|
|
|
|
|
set((state) =>
|
|
|
|
|
state.currentResetFunction === resetFunction && state.reset
|
|
|
|
|
? state
|
|
|
|
|
: {
|
|
|
|
|
currentResetFunction: resetFunction,
|
|
|
|
|
reset: state.reset ?? invokeCurrentResetFunction,
|
|
|
|
|
},
|
|
|
|
|
),
|
2024-05-31 10:41:44 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
export default useFeedResetStore;
|