From 7f4b65f009e362f32a32cd1a3a443722f9590873 Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Tue, 21 Apr 2026 12:02:01 +0200 Subject: [PATCH] fix(faith): angelus slot selection sticks after praying Replaced the auto-selecting $effect that was clobbering manual slot picks with explicit init in onMount and advancement inside pray(). Selecting lunch/evening after praying morning now works. --- package.json | 2 +- .../faith/AngelusStreakCounter.svelte | 21 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index d1861aa2..6a16b588 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homepage", - "version": "1.40.2", + "version": "1.40.3", "private": true, "type": "module", "scripts": { diff --git a/src/lib/components/faith/AngelusStreakCounter.svelte b/src/lib/components/faith/AngelusStreakCounter.svelte index 378c341a..0e038731 100644 --- a/src/lib/components/faith/AngelusStreakCounter.svelte +++ b/src/lib/components/faith/AngelusStreakCounter.svelte @@ -35,19 +35,14 @@ const partialCount = $derived( ); const showFraction = $derived(partialCount > 0 && partialCount < 3); -const autoSlot = $derived(browser ? getCurrentTimeSlot() : 'morning' as TimeSlot); +const SLOT_ORDER: TimeSlot[] = ['morning', 'noon', 'evening']; -// Auto-select the current time slot initially, and advance to next unprayed slot -$effect(() => { - if (!isSlotPrayed(autoSlot)) { - selectedSlot = autoSlot; - } else { - // Find next unprayed slot - const order: TimeSlot[] = ['morning', 'noon', 'evening']; - const next = order.find(s => !isSlotPrayed(s)); - if (next) selectedSlot = next; - } -}); +function pickFirstUnprayed(prayedMask: number): TimeSlot { + const current = browser ? getCurrentTimeSlot() : 'morning'; + const bit = (s: TimeSlot) => ({ morning: 1, noon: 2, evening: 4 }[s]); + if ((prayedMask & bit(current)) === 0) return current; + return SLOT_ORDER.find(s => (prayedMask & bit(s)) === 0) ?? current; +} const slots: { key: TimeSlot; icon: typeof Coffee; color: string }[] = [ { key: 'morning', icon: Coffee, color: 'var(--nord13)' }, @@ -86,11 +81,13 @@ onMount(() => { const s = getAngelusStreak(); s.initWithServerData(streakData, isLoggedIn); store = s; + selectedSlot = pickFirstUnprayed(s.todayPrayed); }); async function pray() { if (!store || isSlotPrayed(selectedSlot)) return; const completed = await store.recordPrayer(selectedSlot); + selectedSlot = pickFirstUnprayed(store.todayPrayed); if (completed) { burst = true; await tick();