Optimize workspace and daily-loop surfaces

This commit is contained in:
2026-04-11 12:03:49 +02:00
parent 27fd70a2d7
commit 33ac4b963b
7 changed files with 474 additions and 224 deletions
+10 -4
View File
@@ -1,4 +1,4 @@
import { DependencyList, Dispatch, SetStateAction, useCallback, useEffect, useMemo, useState } from "react";
import { DependencyList, Dispatch, SetStateAction, useCallback, useEffect, useMemo, useRef, useState } from "react";
import { getApiErrorMessage } from "../api";
@@ -64,12 +64,18 @@ export function useViewResource<T>(
const [refreshing, setRefreshing] = useState(false);
const [hasLoaded, setHasLoaded] = useState(false);
const [error, setError] = useState<ViewResourceError | null>(null);
const hasLoadedRef = useRef(hasLoaded);
useEffect(() => {
hasLoadedRef.current = hasLoaded;
}, [hasLoaded]);
const reload = useCallback(async () => {
if (!enabled) return;
setLoading((current) => !hasLoaded && current);
setRefreshing(hasLoaded);
const alreadyLoaded = hasLoadedRef.current;
setLoading(!alreadyLoaded);
setRefreshing(alreadyLoaded);
try {
const next = await load();
setData(next);
@@ -82,7 +88,7 @@ export function useViewResource<T>(
setLoading(false);
setRefreshing(false);
}
}, [enabled, errorMessage, hasLoaded, load]);
}, [enabled, errorMessage, load]);
useEffect(() => {
if (!enabled) {