The settings validation now mirrors the bounds of the server, 0.01 to
168 hours and a workday mask of 1 to 127, so a row the client accepts
no longer fails on the server. stopEntry and autoStopStale end an
entry in the timezone of the settings row effective on the entry's
day, as the server does, instead of in today's. updateEntry refuses
to clear end_time while another entry is running.
safeNext falls back for a next path with a backslash, a control
character or "//". The login page opens the OAuth popup itself within
the click and says "The popup was blocked" when the browser refuses
it, where the sign-in used to hang without a word.
The sync keeps a per-collection flag for the pull of the current sync
call instead of counting pulls globally, asks for a minute before the
cursor since the server clock can move backwards, and closeDb()
clears the sync error of the session that ended. The tooltip of the
sync button shows the first line of a multi-line error.
The db tests get an echo server that honours the pull cursor, records
the filter of every pull, answers with a status of the test's choice
and keeps stale answers like the real one. New cases: a second user
opens without the collections, cursors, realtime subscriptions and
sync status of the first; wipeLocal really removes the cursors and the
database so that the next open pulls everything again; a push that
fails after a good pull and a pull that fails before the push both
keep the change records and the cursor, and the next round pushes it
all; a stale answer applies the server record and a newer local change
wins afterwards.
The stress test now compares every local record, tombstones included,
with the mock server after each round, so a divergence between the two
fails the test. closeDb() resets the last sync time for the same
reason: it belonged to the session that just ended.
Only an invalid answer set the sync error: forbidden and readonly were
silent, a stale answer to a deletion silently brought the row back,
the message named no record, and the next automatic round cleared it
before the user saw it.
Every answer the server did not apply now sets the message
"<collection> <record>: <text>", cut to 200 characters, with a text
of its own where the server sends none, and a stale answer to a
deletion says that the server kept a newer version of that record
while that version is applied. The message stays across the automatic
rounds until the user syncs by hand or another rejection replaces it;
the rounds the app starts on its own now run separately from the
manual sync for that.
The worker is registered with autoUpdate and claims its clients, so
after a deploy the new worker took the page over while the old page
kept running with its lazy route chunks purged from the cache:
navigating then failed until the user reloaded by hand.
Once a worker controls the page, a controllerchange now reloads it,
one time per load. The check that a controller already exists keeps
the first visit from reloading, where the brand new worker claims the
page right after registering. The block runs in production only, so
tests never touch it.
autoStopStale only ran through beforeSync, and syncNow skipped that
while offline: an app left open overnight offline kept yesterday's
entry running, and startEntry then threw "an entry is already running"
for an entry the Today view does not show.
A round now runs its preparation whatever the online state and only
leaves out the requests, so the minute tick stops stale entries
offline too, and startEntry stops them itself before it checks for a
running entry.
Every PocketBase event ran its own full sync of the collection, with
rejections nobody caught and around beforeSync and onSyncRound. A
remote change now starts a round through syncNow(), at most one per
300 ms window; one that lands while a round runs gets its own round
after it. The debounced local push is unchanged.
A failed pull or push no longer sets the sync error while the browser
is offline, since the layout shows "Offline" then. A failed round
reports the distinct errors of its syncs on one line instead of the
heading syncAll() puts above them.
When IndexedDB rejected or blocked the open, resolveGate() rejected,
the gate stayed null and the app showed "Loading…" forever. A failed
open now cleans up and rejects with a reason, a blocked open gives up
after eight seconds, and resolveGate() turns that into an error gate:
the layout shows the message with a Retry button instead of the loading
line, and the sign-in itself is kept.
logout() clears the auth store and the session before it closes and
wipes the local data, and swallows a failing wipe, so the user is never
left half logged out. activate() sets the session only after the
database is open and only if the auth store is still valid with the
same token, so a resolution that finishes after a logout or another
sign-in no longer reopens the app for the wrong user. openDb() hands
out an in-flight open only to the same user; another user's open waits
for it and then replaces it.
update() read the record before save() waited for the sync to apply
server state, and the record finally written was that stale read plus
the patch with a fresh client_updated_at: an edit silently reverted
what another device had changed in between, and the server took it as
the newer version.
update() and remove() now patch the record after the wait, so every
field they do not touch keeps the value the pull just applied. The
test holds an update while a round applies a remote change to the same
record and fails on the old code with the reverted field.
A 401 mid-session made the PocketBase SDK drop the auth store, while
session.userId and the gate of the layout stayed set: the user remained
in the app, every round failed, /login was bounced back and a token-less
pull was even taken for a successful round.
The sync layer now ends the session through an onSessionExpired hook
when a round fails with 401 or finds the auth store cleared, and reports
no round as synced without a valid auth store. The session module tries
one token refresh before it clears the session, and the layout resolves
the gate again whenever the auth store is no longer valid, so the user
lands on the login page and the next sign-in brings the data back.
Browsers of users of the Dexie based version still hold its token in
the auth_token key of localStorage and its database named wotra, next
to the per user databases of this version. resolveGate() now removes
both whenever it lets the user into the app, the first open included.
The removal resolves on success, error and block, like wipeLocal, and
never throws, so a browser that denies storage cannot keep the user
out.
The API client and the two stores on Dexie have been dead since the
collections took over every read and write, and nothing imports them
any more. Dexie and workbox-window go with them; the service worker is
registered by hand and needs no client library.
The static adapter wipes build/ on every build, which dropped the
tracked placeholder that keeps the directory in the repository. A
postbuild step writes it back.
The server now answers an invalid change per item instead of failing
the whole batch, and the client dropped such a change silently: the
round went through and nothing told the user that the edit never
reached the server. A rejected change now sets the sync status to
"<collection>: <error>", cut to 200 characters, so the sync button
shows its warning state. The change is not retried, as before.
The message survives the collections that still succeed in the same
round, since each of them used to clear the error. The next round
without a rejection clears it.
The sync manager learns of a local write only from the change record
it creates after the write finished, and it applies the pulled server
state without regard to newer local changes. A write made while a
round was pulling or pushing was therefore replaced by the older
server version, or removed as unknown to the snapshot, until the next
round pushed it again: a deleted adjustment came back, an edit
reverted, a new row vanished for a moment.
Each pull now waits for the writes in flight on the collection and on
the change records, keeps the server version of items whose change
record the round did not push, and local writes wait while the sync
applies server state to their collection; network requests stay
exempt. The stress test writes to four collections for 300 rounds,
with the sync idle and with a push held in flight, and asserts that
reactive and plain reads always show the last write. Without the fix
it fails in the first round.
Every read outside a reactive scope passed { reactive: false } and made
Cursor.depend() log a warning. Such reads now use a silent reactivity
adapter, and all, get, pendingCount and save release the cursor again
with cleanup(), so nothing is registered and nothing leaks. Reads inside
$derived or $effect stay reactive as before.
Vitest now resolves the browser export of Svelte. Without it
svelte/reactivity is the server stub, createSubscriber never starts and
no effect re-runs after a write in tests.
The shared token form is gone. Working hours, workdays and timezone
are edited through the synced settings collection, and a new account
card shows the signed-in user, a password change and sign out.
Closed weeks, closed days, the balance and the adjustments are derived
from the synced collections instead of being loaded once on mount, so
every change shows up without a reload.
The day detail panel no longer loads entries and the closed day on
demand and patches its lists after each mutation. Entries, the closed
day, the running entry and the total are derived from the synced
collections, so they update on local changes and on sync. The ticker
restarts whenever the running entry changes. Closing, marking and
reopening a day rely on the sync the domain functions trigger.
The week view no longer loads its data on demand and patches it after
each mutation. Entries, closed days, the closed week and the settings
are derived from the synced collections, so the view follows local
changes and sync results. Closing and reopening a week report errors
from the server in place.
Only signed-in users reach the working pages. Everyone else lands on
the login page and returns to the page they asked for after signing in.
The manifest link moves into the page template and the service worker
is registered only in production builds.
The app no longer uses a shared bearer token. The page signs users in
or creates an account through PocketBase and offers the configured
OAuth2 providers.
Add PocketBase v0.40.6 as a dependency together with the pieces the
new backend is built from: the list of synced collections with their
client-writable fields, the initial migration that creates the five
per-user collections (entries, closed_days, closed_weeks,
settings_history, balance_adjustments), and empty Register stubs for
the tracking and legacy import packages.
Clients only get read access to their own rows over REST; writes are
meant to go through the sync push endpoint. web/build is now ignored
except for a tracked placeholder so the built SPA can be embedded.
The entry point (main.go) and the UI embedding (ui.go) are not part
of this commit: the repo root is still the legacy "assets" package,
and Go does not allow "package main" in the same directory.
Shows a sync button in the top-right corner of the nav bar with live
status: spinning while syncing, warning icon on error, grey when idle.
Tooltip shows last synced time or error message. An orange badge
appears when there are pending outbox items.
- sync.ts: add syncState store (status, lastSynced, pendingCount,
error); guard against concurrent sync cycles with syncInFlight flag
- layout: sync button wired to triggerSync(); ticks every 15s so the
'Xs ago' label stays current
All reads now come directly from Dexie; all mutations write to Dexie +
outbox immediately without waiting for the server. The background sync
loop (every 30s) pushes the outbox and pulls server changes.
Day/week close and reopen remain server-only (require server-side
computation). triggerSync() is called after them to update Dexie
promptly. The optimistic closedDaysMap update in the week page is kept
separate from the Dexie reload to avoid a race that was causing the
reopen button and day actions to disappear until a page reload.
- client.ts: remove online-first fetch paths; all reads from Dexie
- sync.ts: add triggerSync() and waitForSync() exports
- DayDetail: pass ClosedDay | null to oninvalidate after close/reopen
- week/+page.svelte: update closedDaysMap optimistically on close/reopen;
only reload from Dexie on entry mutations
- settings/+page.svelte: read history() directly (never throws 503);
derive current locally
- layout: remove offline banner and online.ts (behaviour is now
identical online and offline)
Wrap each DayChip in a container-query context so the chip layout
responds to the actual space available rather than the viewport width.
Breakpoints (per-chip width):
- < 72px (mobile, 7 chips in ~320px): compact — label + date + progress bar + badges only
- ≥ 72px (tablet+): show worked duration text below the date number; slightly larger padding/font
- ≥ 100px (desktop, 7 chips in ~750px wide main): larger date number, bigger worked label
The .chip-slot div in week/+page.svelte is the flex child (flex: 1,
min-width: 2.8rem) that feeds width into the container; .chip-wrap
inside DayChip carries container-type: inline-size and fills the slot.
All GET calls in client.ts now fall back to Dexie when a network error
(TypeError) is caught, so pages render from cached data when the server
is unreachable:
- entries.list() → db.entries filtered by day_key range
- days.list() → db.closed_days filtered by day_key range
- weeks.list() → db.closed_weeks filtered by week_key range
- weeks.balance() → computed locally from closed_weeks + balance_adjustments
- balance.list() → db.balance_adjustments ordered by effective_at DESC
- settings.current() → db.settings_history, latest row with effective_from <= today
- settings.history() → db.settings_history ordered by effective_from DESC
Day/week close and reopen remain online-only (they require server-side
computation).
Add isOnline store (navigator.onLine + window online/offline events) and
an amber 'Offline — showing cached data' banner in +layout.svelte shown
whenever the store is false.
- Migration 003: adds logged_at to sync_log for TTL pruning; migrates
settings_history to UUID TEXT PK with updated_at column
- SyncStore: Prune() deletes rows older than 30d and writes a '_pruned'
marker at the boundary version; Pull() calls Prune lazily and returns
ErrSyncStale (410) when the client's since_version is behind the marker
- sync_handler.go: GET /api/sync/pull?since=N; POST /api/sync/push with
last-updated_at-wins conflict resolution for entries, balance_adjustments,
settings_history; closed_days/closed_weeks skipped (server-only mutations)
- router.go: passes entryStore, adjustmentStore, settingsStore to SyncHandler
- settings_store.go: UUID PK, updated_at column, Upsert() for push path
- settings_service.go: generates UUID on create, sets updated_at on update
- settings_handler.go: ID params changed from int64 to string
- domain.go: Settings.ID string, Settings.UpdatedAt added
- client.ts: all mutation methods catch TypeError (offline) and fall back
to Dexie write + outbox enqueue; crypto.randomUUID() for offline creates;
Settings.id type changed to string
- db.ts: Dexie v3 — settings_history key path changed to string UUID;
upgrade handler clears table for repopulation via pull
- sync.ts: real pushOutbox to POST /api/sync/push; pullChanges uses GET
with ?since=N; 410 triggers coldStart() + retry; coldStart() wipes all
tables and resets last_version
- 4 new Go store tests covering normal pull, stale client, empty prune,
client-ahead-of-marker; all tests pass (store + service, 19 Vitest)
Backend:
- ClosedWeekStore.SumDelta: single SQL aggregate returning total delta_ms and
row count across all closed_weeks
- WeekService.Balance: thin passthrough returning BalanceResult{TotalDeltaMs, ClosedWeekCount}
- GET /api/weeks/balance handler; route registered alongside /weeks list/close/reopen
- Tests: store-level SumDelta (empty + populated), service-level Balance (empty + 2 weeks)
Frontend:
- weeks.balance() added to API client
- History page: balance card at top, fetched in parallel with existing data
- Loading state shows '—'; once loaded shows formatDelta value in green/red/gray
- Shows 'across N closed weeks' count alongside the value
Backend:
- SettingsStore: Add GetByID, Update, Delete, Count methods
- SettingsService: Add UpdateSettings (validates same rules as Upsert),
DeleteSettings (guards against deleting the last row → 409)
- New sentinels: ErrSettingsNotFound, ErrLastSettingsRow
- Handler: PUT /api/settings/history/{id} → 200 updated row
DELETE /api/settings/history/{id} → 204 / 404 / 409
Frontend:
- API client: settings.update(id, body) and settings.delete(id)
- Settings page: history table gains edit (pencil) and delete (×) buttons
- Inline edit form expands in place within the table row
- Delete button disabled and hint shown when only one row remains
- maskLabel() helper shows workday names instead of raw bitmask
- After save/delete: full reload to reflect changes in 'current' section
- Today nav link targets /week?week=<currentWeek>&day=<todayKey>
- Today tab active: route=/week AND ?day===todayKey() (not just pathname)
- Week tab active: route=/week AND today tab not active
- Root / redirect updated from /today to /week?week=…&day=…
- /today route hard-deleted (src/routes/today/ removed)
- +layout.svelte imports todayKey/currentWeekKey for link generation
- weekKey and selectedDay driven by ?week=&?day= query params
- Bare /week canonicalizes via replaceState (adds week+day params)
- Chip clicks: replaceState (no history push, no scroll jump)
- Week prev/next: goto with history push (back/forward works)
- Default day when week changes: today if in week, else Monday
- Keyboard navigation: ArrowLeft/Right cycles through chips
- Selected chip scrolls into view on selection change
- DayDetail always rendered for selectedDay (not just today)
- detailCaps reactive on closedDaysMap — updates immediately after
close/reopen/mark without extra load()
- Chips now wired: selected prop, onclick handler
- DayChip tabindex: 0 for selected chip, -1 for others (roving tabindex)
- 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
- New DayChip.svelte component: weekday label, date number, progress
bar (worked/expected), kind badge (H/V/S), closed checkmark, today
highlight, selected state, accessible role=tab/aria-selected
- Week page: replace days-grid with horizontal scroll-snap chip strip
- Per-day workedMs: uses closed_days.worked_ms when closed, else sums
open entries for that day (so in-progress work shows immediately)
- dailyExpectedMs: evenly split hours_per_week across workdays; 0 for
weekends (no progress bar rendered for non-workdays)
- Progress bar turns amber when worked > expected (overtime)
- weekEntries stored in state (was discarded after computing set);
daysWithEntries now derived from weekEntries
- Install vitest + jsdom
- Add test/test:watch scripts to package.json
- Add test:web and test:all tasks to mise.toml
- Add dayCapabilities() to utils.ts — single source of truth for
what actions are permitted per day (future/today/past, open/closed)
- Add DayCapabilities interface to utils.ts
- 11 unit tests: dayCapabilities (5 cases), weekDayKeys (3 cases),
isWorkday (3 cases)
closedWeek.delta_ms is a snapshot taken at close time and goes stale
if entries are edited or days are re-closed afterward. The summary
rows above already use the live totalWorkedMs - expectedMs; the
closed-week banner now uses the same expression.
Fetch entries for the week alongside days/weeks in the week view.
canCloseWeek now mirrors the server rule: every past workday that
has at least one entry must have a closed_days record. Days with
no entries are still skipped (they count as 0h implicitly).
The frontend was blocking week close until every workday had a
closed_days record, which no longer matches the backend's rules
(untracked days are implicitly 0h). Replace the all-workdays-closed
guard with a simple check: week has started (Monday ≤ today) and
is not already closed. The server returns a clear error if a day
with entries still needs closing.
Also fixes a pre-existing TS type narrowing error on currentSettings
and removes the now-unused .hint CSS rule.