feat: add shared overview and harden frontend session state (#407)
This commit is contained in:
@@ -8,6 +8,7 @@ export interface UseMedicationsReturn {
|
||||
saving: boolean;
|
||||
setSaving: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
uploadingImage: boolean;
|
||||
clearMedicationsState: () => void;
|
||||
loadMeds: () => void;
|
||||
deleteMed: (id: number, editingId: number | null, resetForm: () => void) => Promise<void>;
|
||||
uploadMedImage: (medId: number, file: File) => Promise<void>;
|
||||
@@ -20,6 +21,13 @@ export function useMedications(): UseMedicationsReturn {
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [uploadingImage, setUploadingImage] = useState(false);
|
||||
|
||||
const clearMedicationsState = useCallback(() => {
|
||||
setMeds([]);
|
||||
setLoading(false);
|
||||
setSaving(false);
|
||||
setUploadingImage(false);
|
||||
}, []);
|
||||
|
||||
const loadMeds = useCallback(() => {
|
||||
setLoading(true);
|
||||
fetch("/api/medications?includeObsolete=true", { credentials: "include" })
|
||||
@@ -96,6 +104,7 @@ export function useMedications(): UseMedicationsReturn {
|
||||
saving,
|
||||
setSaving,
|
||||
uploadingImage,
|
||||
clearMedicationsState,
|
||||
loadMeds,
|
||||
deleteMed,
|
||||
uploadMedImage,
|
||||
|
||||
Reference in New Issue
Block a user