aktueller stand

This commit is contained in:
2026-01-29 21:00:20 +01:00
parent e64edabf85
commit 18891f8525
4 changed files with 1190 additions and 42 deletions

File diff suppressed because one or more lines are too long

View File

@@ -150,6 +150,31 @@ async function fetchProfileWithCache(session, { force = false } = {}) {
}
}
async function buildRegularPickupMapForConfig(session, config) {
try {
const entries = Array.isArray(config) ? config : [];
const storeIds = Array.from(
new Set(entries.filter((entry) => entry?.id && !entry.hidden).map((entry) => String(entry.id)))
);
if (storeIds.length === 0) {
return {};
}
const results = await Promise.all(
storeIds.map(async (storeId) => {
const result = await getRegularPickupSchedule(session, storeId);
return [storeId, Array.isArray(result.rules) ? result.rules : []];
})
);
return results.reduce((acc, [storeId, rules]) => {
acc[storeId] = rules;
return acc;
}, {});
} catch (error) {
console.warn('[PICKUP] Regular-Pickup-Map konnte nicht geladen werden:', error.message);
return {};
}
}
function scheduleWithCurrentSettings(sessionId, config) {
const settings = adminConfig.readSettings();
scheduleConfig(sessionId, config, settings);
@@ -848,9 +873,13 @@ app.post('/api/auth/logout', requireAuth, (req, res) => {
app.get('/api/auth/session', requireAuth, async (req, res) => {
const settings = adminConfig.readSettings();
const { stores } = await loadStoresForSession(req.session, settings, { reason: 'session-check' });
const config = readConfig(req.session.profile.id);
const regularPickupMap = await buildRegularPickupMapForConfig(req.session, config);
res.json({
profile: req.session.profile,
stores,
config,
regularPickupMap,
isAdmin: !!req.session.isAdmin,
adminSettings: req.session.isAdmin ? settings : undefined,
storeRefreshJob: summarizeJob(getStoreRefreshJob(req.session.id)),
@@ -1336,34 +1365,8 @@ app.get('/api/stores/:storeId/regular-pickup', requireAuth, async (req, res) =>
app.get('/api/stores', requireAuth, async (req, res) => {
const stores = req.session.storesCache?.data || [];
let regularPickupMap = {};
try {
const profileId = req.session.profile?.id;
if (profileId) {
const config = readConfig(profileId);
const storeIds = Array.from(
new Set(
(Array.isArray(config) ? config : [])
.filter((entry) => entry?.id && !entry.hidden)
.map((entry) => String(entry.id))
)
);
if (storeIds.length > 0) {
const results = await Promise.all(
storeIds.map(async (storeId) => {
const result = await getRegularPickupSchedule(req.session, storeId);
return [storeId, Array.isArray(result.rules) ? result.rules : []];
})
);
regularPickupMap = results.reduce((acc, [storeId, rules]) => {
acc[storeId] = rules;
return acc;
}, {});
}
}
} catch (error) {
console.warn('[PICKUP] Regular-Pickup-Map konnte nicht geladen werden:', error.message);
}
const config = readConfig(req.session.profile.id);
const regularPickupMap = await buildRegularPickupMapForConfig(req.session, config);
res.json({ stores, regularPickupMap });
});

View File

@@ -40,6 +40,7 @@ function App() {
const [focusedStoreId, setFocusedStoreId] = useState(null);
const [nearestStoreLabel, setNearestStoreLabel] = useState(null);
const [regularPickupMap, setRegularPickupMap] = useState({});
const bootstrapOnceRef = useRef(false);
const minSelectableDate = useMemo(() => startOfDay(new Date()), []);
const weekdays = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'];
@@ -232,9 +233,12 @@ function App() {
setStores(Array.isArray(result.stores) ? result.stores : []);
setAdminSettingsSnapshot(result.adminSettings ?? null);
setConfig(Array.isArray(result.config) ? result.config : []);
if (result.regularPickupMap && typeof result.regularPickupMap === 'object') {
setRegularPickupMap(result.regularPickupMap);
}
return result;
},
[setStores, setAdminSettingsSnapshot, setConfig]
[setStores, setAdminSettingsSnapshot, setConfig, setRegularPickupMap]
);
const resetSessionState = useCallback(() => {
@@ -361,6 +365,10 @@ function App() {
let ticker;
let cancelled = false;
(async () => {
if (bootstrapOnceRef.current) {
return;
}
bootstrapOnceRef.current = true;
const storedToken = getStoredToken();
if (!storedToken) {
return;

View File

@@ -91,7 +91,9 @@ const useSessionManager = ({ normalizeConfigEntries, onUnauthorized, setError, s
progress?.update?.('Betriebe werden geprüft...', 45);
const stores = Array.isArray(data.stores) ? data.stores : [];
const adminSettings = data.isAdmin ? normalizeAdminSettings(data.adminSettings) : null;
const configSource = Array.isArray(data.config) ? data.config : data.config || null;
let config = normalizeConfigEntries(Array.isArray(configSource) ? configSource : []);
if (!configSource) {
const configResponse = await fetch('/api/config', {
headers: { Authorization: `Bearer ${token}` }
});
@@ -104,13 +106,17 @@ const useSessionManager = ({ normalizeConfigEntries, onUnauthorized, setError, s
}
const configData = await configResponse.json();
progress?.update?.('Konfiguration wird geladen...', 75);
const config = normalizeConfigEntries(Array.isArray(configData) ? configData : []);
config = normalizeConfigEntries(Array.isArray(configData) ? configData : []);
} else {
progress?.update?.('Konfiguration wird geladen...', 75);
}
progress?.update?.('Synchronisierung abgeschlossen', 95);
return {
session: sessionData,
stores,
adminSettings,
regularPickupMap: data.regularPickupMap ?? null,
config,
storeRefreshJob: data.storeRefreshJob,
storesFresh: data.storesFresh