Testing in progress ;)
This commit is contained in:
+16
-4
@@ -89,11 +89,23 @@ async function handleSnooze(slotId, minutes) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ROAST_CACHE_KEY = "medis-roast-day";
|
||||||
|
|
||||||
|
async function loadRoast(day) {
|
||||||
|
try {
|
||||||
|
const cached = JSON.parse(sessionStorage.getItem(ROAST_CACHE_KEY) || "null");
|
||||||
|
if (cached?.day === day && cached?.text) return cached;
|
||||||
|
const roast = await api.roast();
|
||||||
|
sessionStorage.setItem(ROAST_CACHE_KEY, JSON.stringify({ day: roast.day, text: roast.text }));
|
||||||
|
return roast;
|
||||||
|
} catch {
|
||||||
|
return { text: "Dein Gebrain wartet auf Koffein und Medis." };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function refreshDashboard(stats) {
|
async function refreshDashboard(stats) {
|
||||||
const [today, roast] = await Promise.all([
|
const today = await api.today();
|
||||||
api.today(),
|
const roast = await loadRoast(today.day);
|
||||||
api.roast().catch(() => ({ text: "Dein Gebrain wartet auf Koffein und Medis." })),
|
|
||||||
]);
|
|
||||||
renderSlots(today.slots, handleTake, handleSnooze);
|
renderSlots(today.slots, handleTake, handleSnooze);
|
||||||
document.getElementById("roastText").textContent = roast.text;
|
document.getElementById("roastText").textContent = roast.text;
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -74,7 +74,7 @@ async def get_roast_of_the_day(db: aiosqlite.Connection, tz: ZoneInfo) -> dict[s
|
|||||||
source = "fallback"
|
source = "fallback"
|
||||||
else:
|
else:
|
||||||
source = "ai"
|
source = "ai"
|
||||||
await _set_cache(db, key, text)
|
await _set_cache(db, key, text)
|
||||||
|
|
||||||
return {"text": text, "source": source, "day": day}
|
return {"text": text, "source": source, "day": day}
|
||||||
|
|
||||||
@@ -98,6 +98,6 @@ async def get_oracle(db: aiosqlite.Connection, tz: ZoneInfo) -> dict[str, Any]:
|
|||||||
source = "fallback"
|
source = "fallback"
|
||||||
else:
|
else:
|
||||||
source = "ai"
|
source = "ai"
|
||||||
await _set_cache(db, key, text)
|
await _set_cache(db, key, text)
|
||||||
|
|
||||||
return {"text": text, "source": source, "week": week}
|
return {"text": text, "source": source, "week": week}
|
||||||
|
|||||||
Reference in New Issue
Block a user