refactor: extract DayDetail component; render today inside week view
- New DayDetail.svelte: self-contained day panel with full capability gating (canStartStop, canAddInterval, canEditEntries, canMarkKind, canCloseDay, canReopenDay) - Closed-day state: banner + read-only entry list with 'Reopen day to edit' hint; mark-kind buttons still available - Close Day button disabled (with tooltip) when running entry exists - Timer only ticks when dayKey === todayKey() and entry is running; properly cleaned up on dayKey change and component destroy - oninvalidate() callback: called after every mutation so parent (week view) can refetch and update the chip strip - /today route: refactored to thin wrapper using DayDetail - Week page: renders DayDetail below summary when today is in the displayed week; oninvalidate triggers full week reload
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
currentWeekKey, weekDayKeys, formatDurationShort, formatDelta, todayKey, isWorkday
|
||||
} from '$lib/utils';
|
||||
import DayChip from '$lib/components/DayChip.svelte';
|
||||
import DayDetail from '$lib/components/DayDetail.svelte';
|
||||
import { dayCapabilities } from '$lib/utils';
|
||||
|
||||
let weekKey = $state(currentWeekKey());
|
||||
let dayKeys = $derived(weekDayKeys(weekKey));
|
||||
@@ -102,6 +104,15 @@
|
||||
|
||||
function prevWeek() { weekKey = offsetWeek(weekKey, -1); }
|
||||
function nextWeek() { weekKey = offsetWeek(weekKey, 1); }
|
||||
|
||||
// Today in this week?
|
||||
const todayInWeek = $derived(dayKeys.includes(todayKey()));
|
||||
const detailDayKey = $derived(todayInWeek ? todayKey() : null);
|
||||
const detailCaps = $derived(
|
||||
detailDayKey
|
||||
? dayCapabilities(detailDayKey, todayKey(), !!closedDaysMap[detailDayKey])
|
||||
: null
|
||||
);
|
||||
function offsetWeek(wk: string, offset: number): string {
|
||||
const [y, w] = wk.split('-W').map(Number);
|
||||
const date = new Date(y, 0, 4);
|
||||
@@ -163,6 +174,13 @@
|
||||
{:else if canCloseWeek}
|
||||
<button class="btn close-week" onclick={handleCloseWeek}>Close week</button>
|
||||
{/if}
|
||||
|
||||
{#if detailDayKey && detailCaps}
|
||||
<div class="day-detail-panel">
|
||||
<h2 class="detail-heading">{detailDayKey}</h2>
|
||||
<DayDetail dayKey={detailDayKey} capabilities={detailCaps} oninvalidate={load} />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
@@ -188,4 +206,6 @@
|
||||
.btn.close-week { background: #343a40; color: #fff; border: none; padding: 0.55rem 1.4rem; border-radius: 6px; font-size: 1rem; font-weight: 600; }
|
||||
.week-closed { background: #d4edda; border-radius: 8px; padding: 0.75rem 1rem; display: flex; align-items: center; justify-content: space-between; }
|
||||
.week-closed button { background: none; border: 1px solid #155724; color: #155724; border-radius: 6px; padding: 0.3rem 0.6rem; font-size: 0.875rem; }
|
||||
.day-detail-panel { border-top: 2px solid #dee2e6; margin-top: 1.25rem; padding-top: 0.75rem; }
|
||||
.detail-heading { font-size: 1rem; font-weight: 600; color: #495057; margin: 0 0 0.5rem; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user