mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 23:12:04 +00:00
fix(mood): report the tag and factor keys a mood write did not store
An unknown or archived tag key, or a factor the catalog no longer carries, was dropped on the way in while the entry still reported "inserted" (bulk) or 201 (create, edit). A client had no way to tell that part of what it sent never landed. Each write now names those keys: the bulk result per entry, the create and edit responses on the entry, as droppedTagKeys and droppedFactorKeys. Both are present only when non-empty, so a response where everything landed is unchanged. An archived tag an edit preserved is on the entry and is not listed. The web shows a short notice after saving when a picked tag was left off.
This commit is contained in:
1 parent
fdbbd3a84a
commit
a66976874e
22 files changed
+525
-50
No files matched your search
@@ -63,6 +63,10 @@ import {
|
||||
import { dayOfLocalInput, useLinkedDayContext } from "./use-linked-day-context";
|
||||
import { MoodQuickTags } from "./mood-quick-tags";
|
||||
import { useRecentTags } from "./recent-tags";
|
||||
import {
|
||||
droppedAnyLinkKeys,
|
||||
type DroppedLinkKeysWire,
|
||||
} from "@/lib/mood/dropped-link-keys";
|
||||
import { moodFaceIcon } from "./mood-tag-icons";
|
||||
// One catalogue for the chip strip and for every server-side reader of what it
|
||||
// writes. Split apart, the write side gained a locale and the read side did
|
||||
@@ -219,7 +223,7 @@ export function MoodForm({ onSuccess, onCancel, footerSlot }: MoodFormProps) {
|
||||
|
||||
const trimmedNote = note.trim();
|
||||
|
||||
await apiPost("/api/mood-entries", {
|
||||
const saved = await apiPost<DroppedLinkKeysWire>("/api/mood-entries", {
|
||||
mood,
|
||||
tags: tags.length > 0 ? tags : undefined,
|
||||
tagKeys: tagKeys.length > 0 ? tagKeys : undefined,
|
||||
@@ -243,6 +247,9 @@ export function MoodForm({ onSuccess, onCancel, footerSlot }: MoodFormProps) {
|
||||
await invalidateKeys(queryClient, moodDependentKeys);
|
||||
await refetchInactiveDailyReads(queryClient);
|
||||
toast.success(t("common.saved"));
|
||||
// The entry landed, but a tag picked here may have been archived or
|
||||
// deleted elsewhere since the picker loaded; the server says so.
|
||||
if (droppedAnyLinkKeys(saved)) toast.warning(t("mood.tagsNotSaved"));
|
||||
onSuccess?.();
|
||||
} catch (err) {
|
||||
setError(localizedApiError(err, t, "mood.saveError"));
|
||||
|
||||
@@ -112,6 +112,10 @@ import { dayOfLocalInput, useLinkedDayContext } from "./use-linked-day-context";
|
||||
import { apiDelete, apiGet, apiPost, apiPut } from "@/lib/api/api-fetch";
|
||||
import { MOOD_LIST_PAGE_SIZE as PAGE_SIZE } from "@/lib/mood/list-page-size";
|
||||
import { localizedApiError } from "@/lib/api/localized-error";
|
||||
import {
|
||||
droppedAnyLinkKeys,
|
||||
type DroppedLinkKeysWire,
|
||||
} from "@/lib/mood/dropped-link-keys";
|
||||
|
||||
// Re-export the score map under the legacy local name to keep the
|
||||
// rest of this file unchanged. v1.4.27 B6 / BL-P6-11 — the single
|
||||
@@ -471,7 +475,7 @@ export function MoodList({ onAddFirst }: MoodListProps = {}) {
|
||||
note: string | null;
|
||||
moodLoggedAt: string;
|
||||
}) => {
|
||||
await apiPut(`/api/mood-entries/${id}`, {
|
||||
return apiPut<DroppedLinkKeysWire>(`/api/mood-entries/${id}`, {
|
||||
mood,
|
||||
tags,
|
||||
tagKeys,
|
||||
@@ -488,7 +492,10 @@ export function MoodList({ onAddFirst }: MoodListProps = {}) {
|
||||
moodLoggedAt,
|
||||
});
|
||||
},
|
||||
onSuccess: async () => {
|
||||
onSuccess: async (saved) => {
|
||||
// A tag picked in the dialog may have been archived or deleted
|
||||
// elsewhere since it opened; the server names what it did not store.
|
||||
if (droppedAnyLinkKeys(saved)) toast.warning(t("mood.tagsNotSaved"));
|
||||
await invalidateKeys(queryClient, moodDependentKeys);
|
||||
await refetchInactiveDailyReads(queryClient);
|
||||
setEditSeed({
|
||||
|
||||
Reference in new issue
Block a user