feat(PBI-76): migrate localStorage prefs to user-settings store (Phase 1) (#188)

* feat(PBI-76): one-shot localStorage→user-settings migration helper

Reads all legacy keys (sprint_pb_*, pbi_*, story_sort, debug-mode,
and dynamic *_filter_kind/*_filter_status for jobs columns) and
returns a typed UserSettings patch plus the keys to clear.
Idempotent via scrum4me:settings_migrated=v1 marker. Skips invalid
values silently so existing corrupt entries do not block migration.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): bridge runs one-shot localStorage migration

After hydrate, scans legacy localStorage keys via buildMigrationPatch
and, if any data is found, pushes one bulk patch to the server,
applies it locally, then removes the legacy keys. Demo accounts skip
the migration entirely. Cancellable on unmount to avoid setState on
unmounted component.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): migrate sprint-backlog to user-settings store

Replaces six useState+useEffect+localStorage flows with selectors
from useUserSettingsStore. Defaults are applied at the selector
level (filterStatus 'OPEN', sort 'code', etc) so the component
matches its previous behaviour. The collapsed Set is derived from
the persisted array, falling back to auto-collapse-DONE when no
preference exists yet. setPref calls are fire-and-forget — the
optimistic flow handles the local state update.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): migrate pbi-list to user-settings store

Same pattern as sprint-backlog: replaces local useState +
localStorage hydration/persist with selectors from
useUserSettingsStore. filterPopoverOpen blijft lokaal — die
was nooit gepersisteerd in pbi-list.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): migrate story-panel sort to user-settings store

Single pref (sortMode) — replaces sync localStorage useState
initializer with a selector. Default 'priority' applied at
the read site.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): migrate jobs-column to user-settings store

Per-instance filter state (kinds + statuses) now lives under
views.jobsColumns[storageKeyPrefix] in user-settings. Removes
the local CSV-encoding helpers — store keeps arrays natively.
A single persist() call writes both fields together so the
two arrays cannot drift in optimistic mid-flight updates.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(PBI-76): migrate debug-mode to user-settings store

DebugToggle reads debugMode from user-settings.devTools and
toggles via setPref. Removes the standalone stores/debug-store.ts
(no consumers left). Body classlist update only fires after the
store is hydrated to avoid a flash on initial paint.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(PBI-76): remove unused readLocalStoragePref helper

No consumers left after migrating sprint-backlog, pbi-list,
story-panel, jobs-column, and debug-store to user-settings.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test(PBI-76): mock user-settings action in backlog integration test

PbiList now imports the user-settings store, which transitively
loads actions/user-settings.ts → lib/prisma. The vitest jsdom
environment has no DATABASE_URL, so we add a mock alongside the
existing action mocks.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(docs): allow balanced parens in markdown link URLs

Previously the link-checker regex stopped at the first ')',
breaking on Next.js route-group paths like `app/(app)/...`. The
new regex matches one level of balanced parens inside the URL.

Caught by CI on PR #188 — pre-existing breakage from PBI-78 plan
doc that was already merged on main.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Janpeter Visser 2026-05-10 15:13:39 +02:00 committed by GitHub
parent a1e6ec35e5
commit 852945efa3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 475 additions and 220 deletions

View file

@ -1,25 +1,24 @@
'use client'
import { useEffect } from 'react'
import { useDebugStore } from '@/stores/debug-store'
import { useUserSettingsStore } from '@/stores/user-settings/store'
export function DebugToggle() {
const { debugMode, _hydrated, hydrate, toggleDebugMode } = useDebugStore()
const debugMode = useUserSettingsStore(
(s) => s.entities.settings.devTools?.debugMode ?? false,
)
const hydrated = useUserSettingsStore((s) => s.context.hydrated)
const setPref = useUserSettingsStore((s) => s.setPref)
useEffect(() => {
hydrate(localStorage.getItem('scrum4me:debug-mode') === 'true')
}, [hydrate])
useEffect(() => {
if (!_hydrated) return
localStorage.setItem('scrum4me:debug-mode', String(debugMode))
if (!hydrated) return
document.body.classList.toggle('debug-mode', debugMode)
}, [debugMode, _hydrated])
}, [debugMode, hydrated])
return (
<button
type="button"
onClick={toggleDebugMode}
onClick={() => void setPref(['devTools', 'debugMode'], !debugMode)}
aria-label="Debug-modus togglen"
aria-pressed={debugMode}
data-active={debugMode}

View file

@ -1,8 +1,13 @@
'use client'
import { useEffect } from 'react'
import { updateUserSettingsAction } from '@/actions/user-settings'
import { useUserSettingsStore } from '@/stores/user-settings/store'
import type { UserSettings } from '@/lib/user-settings'
import {
buildMigrationPatch,
clearLegacyLocalStorage,
} from '@/lib/user-settings-migration'
interface Props {
initial: UserSettings
@ -23,6 +28,29 @@ export function UserSettingsBridge({ initial, isDemo }: Props) {
hydrate(initial, isDemo)
}, [hydrate, initial, isDemo])
// One-shot migration: read legacy localStorage prefs, push to server, clear.
// Idempotent via marker; demo accounts skip (no server-write).
useEffect(() => {
if (isDemo) return
const result = buildMigrationPatch()
if (!result.hasData) {
clearLegacyLocalStorage([])
return
}
let cancelled = false
void (async () => {
const res = await updateUserSettingsAction(result.patch)
if (cancelled) return
if ('success' in res && res.success) {
applyServerPatch(result.patch)
clearLegacyLocalStorage(result.legacyKeys)
}
})()
return () => {
cancelled = true
}
}, [isDemo, applyServerPatch])
useEffect(() => {
if (isDemo) return
const es = new EventSource('/api/realtime/user-settings')