aktueller stand

This commit is contained in:
2026-01-29 18:17:13 +01:00
parent 9f2825edd4
commit ad32f299cf
8 changed files with 491 additions and 18 deletions

View File

@@ -39,6 +39,7 @@ function App() {
const [notificationPanelOpen, setNotificationPanelOpen] = useState(false);
const [focusedStoreId, setFocusedStoreId] = useState(null);
const [nearestStoreLabel, setNearestStoreLabel] = useState(null);
const [regularPickupMap, setRegularPickupMap] = useState({});
const minSelectableDate = useMemo(() => startOfDay(new Date()), []);
const weekdays = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'];
@@ -551,6 +552,45 @@ function App() {
const visibleConfig = useMemo(() => config.filter((item) => !item.hidden), [config]);
useEffect(() => {
let cancelled = false;
if (!session?.token || !authorizedFetch || visibleConfig.length === 0) {
return () => {
cancelled = true;
};
}
const uniqueIds = Array.from(new Set(visibleConfig.map((item) => String(item.id))));
const missing = uniqueIds.filter((id) => regularPickupMap[id] === undefined);
if (missing.length === 0) {
return () => {
cancelled = true;
};
}
const fetchSchedules = async () => {
for (const id of missing) {
try {
const response = await authorizedFetch(`/api/stores/${id}/regular-pickup`);
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
const data = await response.json();
const rules = Array.isArray(data) ? data : Array.isArray(data?.rules) ? data.rules : [];
if (!cancelled) {
setRegularPickupMap((prev) => ({ ...prev, [id]: rules }));
}
} catch (err) {
if (!cancelled) {
setRegularPickupMap((prev) => ({ ...prev, [id]: [] }));
}
}
}
};
fetchSchedules();
return () => {
cancelled = true;
};
}, [authorizedFetch, regularPickupMap, session?.token, visibleConfig]);
const activeRangeEntry = useMemo(() => {
if (!activeRangePicker) {
return null;
@@ -736,6 +776,7 @@ function App() {
onToggleStores={() => setAvailableCollapsed((prev) => !prev)}
onStoreSelect={handleStoreSelection}
configMap={configMap}
regularPickupMap={regularPickupMap}
error={error}
onDismissError={() => setError('')}
status={status}