mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 00:43:15 +00:00
fix(places): a saved place's edit form no longer undoes its tags and notes
The tags card and the notes tab write a list copy's labels and notes directly, but the edit form still sent the label_ids and notes it was seeded with when the place opened, so saving a name change laid the old tags and note back over them. The form now sends only the fields it shows.
This commit is contained in:
@@ -86,10 +86,7 @@ export function useCollectionPlaceForm({
|
||||
const [name, setName] = useState(shown?.name ?? '');
|
||||
const [categoryId, setCategoryId] = useState<number | null>(shown?.category_id ?? null);
|
||||
const [description, setDescription] = useState(shown?.description ?? '');
|
||||
// The traveller's own notes on the place (#3168), apart from its description.
|
||||
const [notes, setNotes] = useState(shown?.notes ?? '');
|
||||
const [links, setLinks] = useState<CollectionLink[]>(shown?.links ?? []);
|
||||
const [labelIds, setLabelIds] = useState<number[]>(shown?.label_ids ?? []);
|
||||
const [address, setAddress] = useState(shown?.address ?? '');
|
||||
const [lat, setLat] = useState(coordText(shown?.lat));
|
||||
const [lng, setLng] = useState(coordText(shown?.lng));
|
||||
@@ -108,9 +105,7 @@ export function useCollectionPlaceForm({
|
||||
setName(p.name);
|
||||
setCategoryId(p.category_id ?? null);
|
||||
setDescription(p.description ?? '');
|
||||
setNotes(p.notes ?? '');
|
||||
setLinks(p.links ?? []);
|
||||
setLabelIds(p.label_ids ?? []);
|
||||
setAddress(p.address ?? '');
|
||||
setLat(coordText(p.lat));
|
||||
setLng(coordText(p.lng));
|
||||
@@ -194,8 +189,6 @@ export function useCollectionPlaceForm({
|
||||
|
||||
const setLink = (i: number, patch: Partial<CollectionLink>) =>
|
||||
setLinks(links.map((l, idx) => (idx === i ? { ...l, ...patch } : l)));
|
||||
const toggleLabel = (id: number) =>
|
||||
setLabelIds(labelIds.includes(id) ? labelIds.filter((x) => x !== id) : [...labelIds, id]);
|
||||
const cancelEdit = () => {
|
||||
if (shown) resetForm(shown);
|
||||
};
|
||||
@@ -203,13 +196,13 @@ export function useCollectionPlaceForm({
|
||||
|
||||
const save = async () => {
|
||||
if (!shown) return;
|
||||
// Notes and tags are written by their own tabs (PlaceTagsCard, the notes section),
|
||||
// so the form sends only the fields it shows and never lays an old copy over them.
|
||||
const base = {
|
||||
name: name.trim() || shown.name,
|
||||
description: description.trim() || null,
|
||||
notes: notes.trim() || null,
|
||||
links: cleanListLinks(links, normalizeLinkUrl),
|
||||
category_id: categoryId,
|
||||
label_ids: labelIds,
|
||||
address: address.trim() || null,
|
||||
};
|
||||
setSaving(true);
|
||||
@@ -235,13 +228,9 @@ export function useCollectionPlaceForm({
|
||||
setCategoryId,
|
||||
description,
|
||||
setDescription,
|
||||
notes,
|
||||
setNotes,
|
||||
links,
|
||||
setLinks,
|
||||
setLink,
|
||||
labelIds,
|
||||
toggleLabel,
|
||||
address,
|
||||
setAddress,
|
||||
lat,
|
||||
|
||||
Reference in New Issue
Block a user