From 2c9ebb954578bb12325452030ea0910e01412cda Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Tue, 19 Mar 2024 01:53:45 +0100 Subject: [PATCH] Force refersh of _all_ questions to fix rendering bugs with svelte --- .../TagRendering/TagRenderingQuestion.svelte | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte b/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte index f156ea9b9..bac3eb9f3 100644 --- a/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte +++ b/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte @@ -30,6 +30,7 @@ import { placeholder } from "../../../Utils/placeholder" import { TrashIcon } from "@rgossiaux/svelte-heroicons/solid" import { Tag } from "../../../Logic/Tags/Tag" + import { get, writable } from "svelte/store" export let config: TagRenderingConfig export let tags: UIEventSource> @@ -46,7 +47,7 @@ // Will be bound if a freeform is available let freeformInput = new UIEventSource(tags?.[config.freeform?.key]) - let freeformInputUnvalidated = new UIEventSource(freeformInput.data) + let freeformInputUnvalidated = new UIEventSource(get(freeformInput)) let selectedMapping: number = undefined /** @@ -112,7 +113,7 @@ unseenFreeformValues.splice(index, 1) } // TODO this has _to much_ values - freeformInput.setData(unseenFreeformValues.join(";")) + freeformInput.set(unseenFreeformValues.join(";")) if (checkedMappings.length + 1 < mappings.length) { checkedMappings.push(unseenFreeformValues.length > 0) } @@ -121,10 +122,10 @@ if (confg.freeform?.key) { if (!confg.multiAnswer) { // Somehow, setting multi-answer freeform values is broken if this is not set - freeformInput.setData(tgs[confg.freeform.key]) + freeformInput.set(tgs[confg.freeform.key]) } } else { - freeformInput.setData(undefined) + freeformInput.set(undefined) } feedback.setData(undefined) } @@ -134,8 +135,8 @@ // We want to (re)-initialize whenever the 'tags' or 'config' change - but not when 'checkedConfig' changes initialize($tags, config) } - - freeformInput.addCallbackAndRun((freeformValue) => { +onDestroy( + freeformInput.subscribe((freeformValue) => { if (!mappings || mappings?.length == 0 || config.freeform?.key === undefined) { return } @@ -151,7 +152,8 @@ if (freeformValue?.length > 0) { selectedMapping = mappings.length } - }) + })) + $: { if ( allowDeleteOfFreeform && @@ -202,7 +204,7 @@ theme: tags.data["_orig_theme"] ?? state.layout.id, changeType: "answer", }) - freeformInput.setData(undefined) + freeformInput.set(undefined) selectedMapping = undefined selectedTags = undefined