fix(todo): homepage loading state + completed date on task items

Homepage fixes:
- Add loading state: show TaskListSkeleton while liveQuery loads
- Fix $derived(() => ...) anti-pattern → $derived.by()
- Stabilize date calculations (compute once, not per re-render)
- Remove double error check (mutation errors shown via toast)

TaskItem improvements:
- Show completed-at date (small, 50% opacity) on right side of
  completed tasks
- Click completed date to toggle showing created-at date above it

Shared: Add `loading` field to useLiveQueryWithDefault (was missing,
prevented proper loading states in consumers)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-03-28 18:15:26 +01:00
parent a81a1535f6
commit d9e2aeff99
3 changed files with 89 additions and 35 deletions

View file

@ -82,8 +82,9 @@ export function useLiveQuery<T>(querier: () => T | Promise<T>): LiveQueryResult<
export function useLiveQueryWithDefault<T>(
querier: () => T | Promise<T>,
defaultValue: T
): { readonly value: T; readonly error: unknown } {
): { readonly value: T; readonly loading: boolean; readonly error: unknown } {
let value = $state<T>(defaultValue);
let loading = $state(true);
let error = $state<unknown>(undefined);
const observable: Observable<T> = liveQuery(querier);
@ -91,10 +92,12 @@ export function useLiveQueryWithDefault<T>(
const subscription = observable.subscribe({
next: (result) => {
value = result;
loading = false;
error = undefined;
},
error: (err) => {
error = err;
loading = false;
},
});
@ -106,6 +109,9 @@ export function useLiveQueryWithDefault<T>(
get value() {
return value;
},
get loading() {
return loading;
},
get error() {
return error;
},