Grapevine_Disease_Detection/VinEye/src/hooks/useHistory.ts
Yanis 720dd34fdd add MyPlantsScreen + ScanDetailScreen + enriched admin + API mobile + project summary
Mobile:
- Replace LibraryScreen with MyPlantsScreen (date-grouped scan list, swipe actions, search, pull-to-refresh)
- Add ScanDetailScreen (immersive hero, confidence bar, cepage card, share/delete)
- Add DiseaseDetailScreen + GuideDetailScreen (hero pattern, animated entry)
- Add useScanDetail, useHistory (useCallback fix), dateGrouping utility
- Connect diseases/guides to admin API with cache + offline fallback
- Add NetworkContext, ToastContext, Skeleton loading components
- Extend ScanRecord type (isFavorite, location)
- Full i18n FR/EN for all new screens

Admin (vineye-admin):
- Enrich Disease/Guide Prisma schema (timeline, conditions, actions, sections)
- Enriched disease-form (7 sections) + guide-form (structured sections editor)
- Add mobile public API endpoints (diseases, guides by slug)
- Add Prisma migration + enriched seed data
- UI polish: sidebar, login, layout updates

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 03:19:39 +02:00

53 lines
1.5 KiB
TypeScript

import { useState, useEffect, useCallback } from 'react';
import { storage } from '@/services/storage';
import type { ScanRecord } from '@/types/detection';
export function useHistory() {
const [history, setHistory] = useState<ScanRecord[]>([]);
const [isLoading, setIsLoading] = useState(true);
const loadHistory = useCallback(async () => {
setIsLoading(true);
const saved = await storage.get<ScanRecord[]>(storage.KEYS.SCAN_HISTORY);
setHistory(saved ?? []);
setIsLoading(false);
}, []);
useEffect(() => {
loadHistory();
}, [loadHistory]);
const addScan = useCallback(async (record: ScanRecord) => {
setHistory((prev) => {
const updated = [record, ...prev];
storage.set(storage.KEYS.SCAN_HISTORY, updated);
return updated;
});
}, []);
const deleteScan = useCallback(async (id: string) => {
setHistory((prev) => {
const updated = prev.filter((r) => r.id !== id);
storage.set(storage.KEYS.SCAN_HISTORY, updated);
return updated;
});
}, []);
const toggleFavorite = useCallback(async (id: string) => {
setHistory((prev) => {
const updated = prev.map((r) =>
r.id === id ? { ...r, isFavorite: !r.isFavorite } : r
);
storage.set(storage.KEYS.SCAN_HISTORY, updated);
return updated;
});
}, []);
const clearHistory = useCallback(async () => {
await storage.remove(storage.KEYS.SCAN_HISTORY);
setHistory([]);
}, []);
return { history, isLoading, addScan, deleteScan, toggleFavorite, clearHistory, reload: loadHistory };
}