Files
HealthLog/src/lib/query-keys/mood.ts
T
Marc-André Bombeck 058d1d7a69 feat(mood): tags get groups, icons and a home of their own
/settings/mood manages the whole tag vocabulary: own groups (encrypted
labels, twelve per account), custom tags with a searchable icon picker
over a 75-icon catalog, hide and unhide of catalogue tags, archive
semantics that never touch historical entries (hard delete only behind
an explicit second confirm), and drag-or-arrow ordering of groups and
tags shared by the picker. One GET serves the fully ordered tree —
groups, placements, hidden and archived state — so the entry form, the
settings section and a native client all read the same resolved layout.
The picker finally renders custom tag labels (they were ignored since
v1.13.0) and offers inline tag creation per group. The mood-tag API
enters the OpenAPI contract for the first time, and the key-rotation
script now covers both encrypted tag and group labels — custom tag
labels had been missing from it since v1.13.0.
2026-06-12 22:03:01 +02:00

69 lines
2.5 KiB
TypeScript

/**
* Query keys — mood entries, mood analytics, and the tag catalog.
* Part of the centralized factory; aggregated in `./index.ts`.
*/
export const moodKeys = {
moodEntries: () => ["mood-entries"] as const,
/**
* v1.15.13 — the mood management-list read with its filter + sort +
* pagination state baked into the key, mirroring `measurementsList`.
* Rides under the `["mood-entries"]` prefix so `moodDependentKeys`
* (and a bulk-delete invalidation) reaches every slot.
*/
moodEntriesList: (params: {
mood: string | undefined;
source: string | undefined;
from: string | undefined;
to: string | undefined;
page: number;
sortBy: string;
sortDir: string;
}) =>
[
"mood-entries",
"list",
params.mood ?? null,
params.source ?? null,
params.from ?? null,
params.to ?? null,
params.page,
params.sortBy,
params.sortDir,
] as const,
moodAnalytics: () => ["mood-analytics"] as const,
/**
* v1.8.5 — pre-computed mood-insights aggregates (heatmap, distribution,
* weekday, tag breakdown, cross-metric correlations) for the Mood
* Insights page. Read-only; invalidated on a mood write through the
* `moodDependentKeys` fan-out in `./index.ts`.
*/
moodInsights: () => ["mood-insights"] as const,
/**
* v1.8.5 — structured mood-tag taxonomy catalog (global reference
* data, identical for every user). Read by the mood-logging form's
* tag-category capture surface. Not invalidated on a mood write — the
* catalog only changes on a migration / admin edit, so a long
* `staleTime` is fine.
*/
moodTagCatalog: () => ["mood-tag-catalog"] as const,
/**
* v1.17 — the tag-MANAGEMENT read (`/api/mood/tags?include=
* hidden,archived,usage`). Rides under the `["mood-tag-catalog"]`
* prefix so one `invalidateQueries({ queryKey: ["mood-tag-catalog"] })`
* after any management mutation refreshes both this read and the
* picker read above (same trick as `moodEntriesList` under
* `["mood-entries"]`). The scope segment keeps the two queryFn shapes
* on different keys — same-key/different-shape silently poisons the
* cache.
*/
moodTagManage: () => ["mood-tag-catalog", "manage"] as const,
/**
* v1.17 — the per-user picker layout blob (`/api/mood/tags/layout`):
* group order + per-group tag placement. Its own root key — layout
* writes invalidate it alongside the catalog prefix.
*/
moodTagLayout: () => ["mood-tag-layout"] as const,
};