Exam generation rework, batch user tables, fastapi endpoint switch

This commit is contained in:
Carlos-Mesquita
2024-11-04 23:29:14 +00:00
parent a2bc997e8f
commit 15c9c4d4bd
148 changed files with 11348 additions and 3901 deletions

View File

@@ -0,0 +1,27 @@
import { Mutate, StoreApi } from "zustand";
import { useEffect } from 'react';
export type StoreWithPersist<T> = Mutate<
StoreApi<T>,
[["zustand/persist", unknown]]
>;
export const usePersistentStorage = <T>(store: StoreWithPersist<T>) => {
useEffect(() => {
const storageEventCallback = (e: StorageEvent) => {
if (e.key === store.persist.getOptions().name && e.newValue) {
store.persist.rehydrate();
}
};
if (typeof window !== 'undefined') {
window.addEventListener("storage", storageEventCallback);
}
return () => {
if (typeof window !== 'undefined') {
window.removeEventListener("storage", storageEventCallback);
}
};
}, [store]);
};