notification system implemented

need refinements
This commit is contained in:
dimitar committed 2026-03-11 06:07:16 +01:00
1 parent 612259f020
commit 1143f8ca02
33 files changed
+2221 -222

No files matched your search

+38 -1
View File
@@ -9,6 +9,7 @@ interface StatisticsContextValue {
loading: boolean;
error: Error | null;
refetchStatistics: () => Promise<void>;
forceRefresh: () => Promise<void>;
clearCache: () => void;
}
@@ -56,7 +57,13 @@ export function StatisticsProvider({
setStatistics(stats);
setLastFetchTime(now);
log.debug("Statistics fetched and cached", { stats });
log.debug("Statistics fetched and cached", {
userId: user.id,
hasWeeklyTrend: !!stats.weeklyTrend,
weeklyTrendLength: stats.weeklyTrend?.length || 0,
weeklyTrendSample: stats.weeklyTrend?.[0],
stats,
});
} catch (err) {
const error = err instanceof Error ? err : new Error(String(err));
log.error("Failed to fetch statistics", error);
@@ -73,6 +80,35 @@ export function StatisticsProvider({
log.debug("Statistics cache cleared");
}, []);
const forceRefresh = useCallback(async () => {
if (!user?.id) return;
try {
setLoading(true);
setError(null);
log.debug("Force fetching statistics", { userId: user.id });
const token = await getToken();
const stats = await getUserStatistics(user.id, token);
setStatistics(stats);
setLastFetchTime(Date.now());
log.debug("Statistics force fetched and cached", {
userId: user.id,
hasWeeklyTrend: !!stats.weeklyTrend,
weeklyTrendLength: stats.weeklyTrend?.length || 0,
weeklyTrendSample: stats.weeklyTrend?.[0],
stats,
});
} catch (err) {
const error = err instanceof Error ? err : new Error(String(err));
log.error("Failed to force fetch statistics", error);
setError(error);
} finally {
setLoading(false);
}
}, [user?.id, getToken]);
return (
<StatisticsContext.Provider
value={{
@@ -80,6 +116,7 @@ export function StatisticsProvider({
loading,
error,
refetchStatistics,
forceRefresh,
clearCache,
}}
>