I hate this fucking language.
This commit is contained in:
+21
-10
@@ -89,25 +89,36 @@ async function handleSnooze(slotId, minutes) {
|
||||
}
|
||||
}
|
||||
|
||||
const ROAST_CACHE_KEY = "medis-roast-day";
|
||||
const MOTIVATION_CACHE_KEY = "medis-motivation-day";
|
||||
|
||||
async function loadRoast(day) {
|
||||
function showMotivationFromCache(day) {
|
||||
const el = document.getElementById("motivationText");
|
||||
const cached = JSON.parse(sessionStorage.getItem(MOTIVATION_CACHE_KEY) || "null");
|
||||
if (cached?.day === day && cached?.text) {
|
||||
el.textContent = cached.text;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async function loadMotivation(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;
|
||||
const motivation = await api.roast();
|
||||
sessionStorage.setItem(MOTIVATION_CACHE_KEY, JSON.stringify({ day: motivation.day, text: motivation.text }));
|
||||
document.getElementById("motivationText").textContent = motivation.text;
|
||||
} catch {
|
||||
return { text: "Dein Gebrain wartet auf Koffein und Medis." };
|
||||
document.getElementById("motivationText").textContent = "Dein Gehirn ist nicht kaputt. Es wartet nur auf den richtigen Treiber.";
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshDashboard(stats) {
|
||||
const today = await api.today();
|
||||
const roast = await loadRoast(today.day);
|
||||
renderSlots(today.slots, handleTake, handleSnooze);
|
||||
document.getElementById("roastText").textContent = roast.text;
|
||||
|
||||
if (!showMotivationFromCache(today.day)) {
|
||||
document.getElementById("motivationText").textContent = "…";
|
||||
loadMotivation(today.day);
|
||||
}
|
||||
|
||||
const s = stats || await api.stats();
|
||||
updateStats(s);
|
||||
|
||||
Reference in New Issue
Block a user