Skip to content

Commit

Permalink
Merge pull request #250 from HootDunk/frontend/fix-service-state-bug
Browse files Browse the repository at this point in the history
update state after mutation and make internal items reactive
  • Loading branch information
HootDunk authored Apr 25, 2024
2 parents 9de51d2 + 172e6e6 commit aec684b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion frontend/src/lib/components/DragAndDrop.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@
export let items: Readonly<ItemsArray>;
let internalItems: ItemsArray = [...items];
let draggingIndex: number | undefined = undefined;
let internalItems: ItemsArray;
// this doesn't work
//$: internalItems = [...items];
// but this does, not sure why
$: updateInternalItems(items);
function updateInternalItems(items: Readonly<ItemsArray>) {
internalItems = [...items];
}
function handleDragStart(index: number) {
draggingIndex = index;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/routes/groups/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
const updatedGroup = e.detail;
let foundIndex = groupList.value.findIndex((x) => x.id == updatedGroup.id);
groupList.value[foundIndex] = updatedGroup;
groupList = groupList;
}
onMount(fetchGroupList);
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/routes/groups/[group_id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@
if (serviceList.type !== 'success') return;
const idx = serviceList.value.findIndex((s) => s.service_code == e.detail.service_code);
serviceList.value[idx] = e.detail;
serviceList = serviceList;
}
function removeServiceFromState(e: ComponentEvents<ServiceListItem>['serviceDeleted']) {
if (serviceList.type !== 'success') return;
serviceList.value = serviceList.value.filter((s) => s.service_code != e.detail.service_code);
serviceList = serviceList;
}
async function updateServicesOrder(e: ComponentEvents<DragAndDrop<Service>>['itemsChanged']) {
Expand Down

0 comments on commit aec684b

Please sign in to comment.