chore(workspace): move the app to apps/app under a pnpm workspace (step 2)
144 files moved with git mv (pure renames). Root package.json delegates dev/typecheck/test:run/lint/build to the packages; Node 24 LTS and pnpm 10.13.1 pinned (.nvmrc, .node-version, engines, packageManager, root devDependency, engine-strict). Dockerfile builds @faunosteo/app on node:24-alpine and copies apps/app/dist; nginx and runtime config unchanged. CI workflow for Gitea Actions. packages/ reserved (README only). Docs synced: WORKSPACE.md, CLAUDE.md, README, DEPLOY, CHANGELOG, plan. 271/271 tests, typecheck, lint, build green from the root.
This commit is contained in:
1 parent
c8d48ab4cc
commit
8673475293
164 files changed
+348
-128
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import { create } from 'zustand'
|
||||
import type { Locale } from '@/i18n/types'
|
||||
|
||||
export const LOCALE_STORAGE_KEY = 'osteo:locale'
|
||||
|
||||
function detectNavigatorLocale(): Locale | undefined {
|
||||
if (typeof navigator === 'undefined') return undefined
|
||||
const langs: string[] = Array.isArray(navigator.languages)
|
||||
? [...navigator.languages]
|
||||
: []
|
||||
if (typeof navigator.language === 'string') langs.push(navigator.language)
|
||||
for (const tag of langs) {
|
||||
const primary = tag.toLowerCase().split(/[-_]/)[0]
|
||||
if (primary === 'fr') return 'fr'
|
||||
if (primary === 'en') return 'en'
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Locale resolution priority:
|
||||
* 1. Explicit localStorage value (user previously toggled)
|
||||
* 2. Navigator language list (first fr/en hit on the user's prefs)
|
||||
* 3. 'fr' fallback (single-praticien project default)
|
||||
*/
|
||||
function readInitial(): Locale {
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
const raw = localStorage.getItem(LOCALE_STORAGE_KEY)
|
||||
if (raw === 'fr' || raw === 'en') return raw
|
||||
}
|
||||
return detectNavigatorLocale() ?? 'fr'
|
||||
}
|
||||
|
||||
export interface LocaleStore {
|
||||
locale: Locale
|
||||
setLocale: (next: Locale) => void
|
||||
}
|
||||
|
||||
export const useLocaleStore = create<LocaleStore>((set) => ({
|
||||
locale: readInitial(),
|
||||
setLocale: (next) => {
|
||||
set({ locale: next })
|
||||
if (typeof localStorage === 'undefined') return
|
||||
try {
|
||||
localStorage.setItem(LOCALE_STORAGE_KEY, next)
|
||||
} catch {
|
||||
// Quota / private mode — in-memory only.
|
||||
}
|
||||
},
|
||||
}))
|
||||
@@ -0,0 +1,29 @@
|
||||
import {
|
||||
PractitionerSchema,
|
||||
type Practitioner,
|
||||
} from '@/domain/schema/practitioner'
|
||||
|
||||
const STORAGE_KEY = 'osteo:lastPractitioner'
|
||||
|
||||
export function readCachedPractitioner(): Practitioner | undefined {
|
||||
if (typeof localStorage === 'undefined') return undefined
|
||||
const raw = localStorage.getItem(STORAGE_KEY)
|
||||
if (!raw) return undefined
|
||||
try {
|
||||
const data = JSON.parse(raw)
|
||||
const parsed = PractitionerSchema.safeParse(data)
|
||||
return parsed.success ? parsed.data : undefined
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
export function writeCachedPractitioner(practitioner: Practitioner): void {
|
||||
if (typeof localStorage === 'undefined') return
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(practitioner))
|
||||
}
|
||||
|
||||
export function clearPractitionerCache(): void {
|
||||
if (typeof localStorage === 'undefined') return
|
||||
localStorage.removeItem(STORAGE_KEY)
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
import { create } from 'zustand'
|
||||
import { ReportSchema, type Report } from '@/domain/schema/report'
|
||||
import type { Observation } from '@/domain/schema/observation'
|
||||
import type { Practitioner } from '@/domain/schema/practitioner'
|
||||
import type { Animal, Owner } from '@/domain/schema/animal'
|
||||
import { generateId } from '@/lib/id'
|
||||
import { nowIso } from '@/lib/dates'
|
||||
|
||||
export interface ReportStore {
|
||||
report: Report | null
|
||||
activeObservationIndex: number
|
||||
initReport: (draft: Omit<Report, 'id' | 'createdAt' | 'version'>) => void
|
||||
hydrateReport: (report: Report) => void
|
||||
addObservation: () => void
|
||||
removeObservation: (index: number) => void
|
||||
moveObservationUp: (index: number) => void
|
||||
moveObservationDown: (index: number) => void
|
||||
updateObservation: (index: number, obs: Observation) => void
|
||||
setActiveObservation: (index: number) => void
|
||||
setPractitioner: (next: Practitioner) => void
|
||||
setAnimal: (next: Animal) => void
|
||||
setOwner: (next: Owner) => void
|
||||
setConclusion: (text: string) => void
|
||||
setRecommendations: (text: string) => void
|
||||
setNextAppointment: (next: Report['nextAppointment']) => void
|
||||
reset: () => void
|
||||
}
|
||||
|
||||
function emptyObservation(): Observation {
|
||||
return {
|
||||
id: generateId(),
|
||||
zones: [],
|
||||
findings: [],
|
||||
freeTextFindings: [],
|
||||
comment: '',
|
||||
}
|
||||
}
|
||||
|
||||
const DRAFT_KEY = 'osteo:draft'
|
||||
|
||||
/** Reads the auto-saved draft back from sessionStorage (null if absent/invalid). */
|
||||
export function readPersistedDraft(): Report | null {
|
||||
if (typeof sessionStorage === 'undefined') return null
|
||||
const raw = sessionStorage.getItem(DRAFT_KEY)
|
||||
if (!raw) return null
|
||||
try {
|
||||
const parsed = ReportSchema.safeParse(JSON.parse(raw))
|
||||
return parsed.success ? parsed.data : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export const useReportStore = create<ReportStore>((set) => ({
|
||||
// Restore the per-tab draft so a page refresh never loses the session.
|
||||
report: readPersistedDraft(),
|
||||
activeObservationIndex: 0,
|
||||
|
||||
initReport: (draft) =>
|
||||
set({
|
||||
report: {
|
||||
...draft,
|
||||
version: 2,
|
||||
id: generateId(),
|
||||
createdAt: nowIso(),
|
||||
observations:
|
||||
draft.observations.length === 0
|
||||
? [emptyObservation()]
|
||||
: draft.observations,
|
||||
},
|
||||
activeObservationIndex: 0,
|
||||
}),
|
||||
|
||||
hydrateReport: (report) => set({ report, activeObservationIndex: 0 }),
|
||||
|
||||
addObservation: () =>
|
||||
set((s) => {
|
||||
if (!s.report) return s
|
||||
const obs = emptyObservation()
|
||||
const observations = [...s.report.observations, obs]
|
||||
return {
|
||||
report: { ...s.report, observations },
|
||||
activeObservationIndex: observations.length - 1,
|
||||
}
|
||||
}),
|
||||
|
||||
removeObservation: (index) =>
|
||||
set((s) => {
|
||||
if (!s.report) return s
|
||||
const observations = s.report.observations.filter((_, i) => i !== index)
|
||||
const active = Math.min(
|
||||
s.activeObservationIndex,
|
||||
Math.max(0, observations.length - 1),
|
||||
)
|
||||
return {
|
||||
report: { ...s.report, observations },
|
||||
activeObservationIndex: active,
|
||||
}
|
||||
}),
|
||||
|
||||
moveObservationUp: (index) =>
|
||||
set((s) => {
|
||||
if (!s.report || index <= 0) return s
|
||||
const observations = [...s.report.observations]
|
||||
;[observations[index - 1], observations[index]] = [
|
||||
observations[index],
|
||||
observations[index - 1],
|
||||
]
|
||||
return { report: { ...s.report, observations } }
|
||||
}),
|
||||
|
||||
moveObservationDown: (index) =>
|
||||
set((s) => {
|
||||
if (!s.report || index >= s.report.observations.length - 1) return s
|
||||
const observations = [...s.report.observations]
|
||||
;[observations[index], observations[index + 1]] = [
|
||||
observations[index + 1],
|
||||
observations[index],
|
||||
]
|
||||
return { report: { ...s.report, observations } }
|
||||
}),
|
||||
|
||||
updateObservation: (index, obs) =>
|
||||
set((s) => {
|
||||
if (!s.report) return s
|
||||
const observations = s.report.observations.map((o, i) =>
|
||||
i === index ? obs : o,
|
||||
)
|
||||
return { report: { ...s.report, observations } }
|
||||
}),
|
||||
|
||||
setActiveObservation: (index) => set({ activeObservationIndex: index }),
|
||||
|
||||
setPractitioner: (next) =>
|
||||
set((s) => (s.report ? { report: { ...s.report, practitioner: next } } : s)),
|
||||
|
||||
setAnimal: (next) =>
|
||||
set((s) => (s.report ? { report: { ...s.report, animal: next } } : s)),
|
||||
|
||||
setOwner: (next) =>
|
||||
set((s) => (s.report ? { report: { ...s.report, owner: next } } : s)),
|
||||
|
||||
setConclusion: (text) =>
|
||||
set((s) => (s.report ? { report: { ...s.report, conclusion: text } } : s)),
|
||||
|
||||
setRecommendations: (text) =>
|
||||
set((s) =>
|
||||
s.report ? { report: { ...s.report, recommendations: text } } : s,
|
||||
),
|
||||
|
||||
setNextAppointment: (next) =>
|
||||
set((s) =>
|
||||
s.report ? { report: { ...s.report, nextAppointment: next } } : s,
|
||||
),
|
||||
|
||||
reset: () => set({ report: null, activeObservationIndex: 0 }),
|
||||
}))
|
||||
|
||||
useReportStore.subscribe((state) => {
|
||||
if (typeof sessionStorage === 'undefined') return
|
||||
if (state.report) {
|
||||
sessionStorage.setItem(DRAFT_KEY, JSON.stringify(state.report))
|
||||
} else {
|
||||
sessionStorage.removeItem(DRAFT_KEY)
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user