mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-09 07:05:18 +02:00
feat: sync visits when updating adventures in collection page
This commit is contained in:
parent
6c683893e4
commit
b33587e516
1 changed files with 7 additions and 3 deletions
|
@ -538,12 +538,17 @@
|
||||||
const index = adventures.findIndex((adventure) => adventure.id === locationBeingUpdated?.id);
|
const index = adventures.findIndex((adventure) => adventure.id === locationBeingUpdated?.id);
|
||||||
|
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
adventures[index] = { ...locationBeingUpdated };
|
// Ensure visits are properly synced
|
||||||
|
adventures[index] = {
|
||||||
|
...adventures[index],
|
||||||
|
...locationBeingUpdated,
|
||||||
|
visits: locationBeingUpdated.visits || adventures[index].visits || []
|
||||||
|
};
|
||||||
adventures = adventures; // Trigger reactivity
|
adventures = adventures; // Trigger reactivity
|
||||||
} else {
|
} else {
|
||||||
adventures = [{ ...locationBeingUpdated }, ...adventures];
|
adventures = [{ ...locationBeingUpdated }, ...adventures];
|
||||||
if (data.props.adventure) {
|
if (data.props.adventure) {
|
||||||
data.props.adventure.locations = adventures; // Update data.props.adventure.locations as well
|
data.props.adventure.locations = adventures;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -709,7 +714,6 @@
|
||||||
{#if isLocationModalOpen}
|
{#if isLocationModalOpen}
|
||||||
<NewLocationModal
|
<NewLocationModal
|
||||||
on:close={() => (isLocationModalOpen = false)}
|
on:close={() => (isLocationModalOpen = false)}
|
||||||
on:save={saveOrCreateAdventure}
|
|
||||||
user={data.user}
|
user={data.user}
|
||||||
locationToEdit={adventureToEdit}
|
locationToEdit={adventureToEdit}
|
||||||
bind:location={locationBeingUpdated}
|
bind:location={locationBeingUpdated}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue