diff --git a/packages/presentation/src/components/SpaceSelector.svelte b/packages/presentation/src/components/SpaceSelector.svelte index 41f7d757edb..8af5f62a978 100644 --- a/packages/presentation/src/components/SpaceSelector.svelte +++ b/packages/presentation/src/components/SpaceSelector.svelte @@ -42,9 +42,9 @@ export let create: ObjectCreate | undefined = undefined const dispatch = createEventDispatcher() - let _space = space - $: if (_space !== space) { - _space = space + let oldSpace = space + $: if (oldSpace !== space) { + oldSpace = space dispatch('change', space) } diff --git a/plugins/time-resources/src/components/EditToDo.svelte b/plugins/time-resources/src/components/EditToDo.svelte index e5b1afb1532..fb644fe199b 100644 --- a/plugins/time-resources/src/components/EditToDo.svelte +++ b/plugins/time-resources/src/components/EditToDo.svelte @@ -101,9 +101,13 @@ object.visibility = visibility } - async function spaceChange (space: Ref) { - await client.update(object, { attachedSpace: space }) - object.attachedSpace = space + async function spaceChange (space: Space | null) { + const oldSpace = object.attachedSpace ?? undefined + const newSpace = space?._id ?? undefined + if (newSpace !== oldSpace) { + await client.update(object, { attachedSpace: newSpace }) + object.attachedSpace = newSpace + } } @@ -171,7 +175,7 @@ autoSelect={false} readonly={object._class === time.class.ProjectToDo} space={object.attachedSpace} - on:change={(e) => spaceChange(e.detail)} + on:object={(e) => spaceChange(e.detail)} />