Force refersh of _all_ questions to fix rendering bugs with svelte

This commit is contained in:
Pieter Vander Vennet 2024-03-19 01:53:45 +01:00
parent 3daac42853
commit 2c9ebb9545

View file

@ -30,6 +30,7 @@
import { placeholder } from "../../../Utils/placeholder" import { placeholder } from "../../../Utils/placeholder"
import { TrashIcon } from "@rgossiaux/svelte-heroicons/solid" import { TrashIcon } from "@rgossiaux/svelte-heroicons/solid"
import { Tag } from "../../../Logic/Tags/Tag" import { Tag } from "../../../Logic/Tags/Tag"
import { get, writable } from "svelte/store"
export let config: TagRenderingConfig export let config: TagRenderingConfig
export let tags: UIEventSource<Record<string, string>> export let tags: UIEventSource<Record<string, string>>
@ -46,7 +47,7 @@
// Will be bound if a freeform is available // Will be bound if a freeform is available
let freeformInput = new UIEventSource<string>(tags?.[config.freeform?.key]) let freeformInput = new UIEventSource<string>(tags?.[config.freeform?.key])
let freeformInputUnvalidated = new UIEventSource<string>(freeformInput.data) let freeformInputUnvalidated = new UIEventSource<string>(get(freeformInput))
let selectedMapping: number = undefined let selectedMapping: number = undefined
/** /**
@ -112,7 +113,7 @@
unseenFreeformValues.splice(index, 1) unseenFreeformValues.splice(index, 1)
} }
// TODO this has _to much_ values // TODO this has _to much_ values
freeformInput.setData(unseenFreeformValues.join(";")) freeformInput.set(unseenFreeformValues.join(";"))
if (checkedMappings.length + 1 < mappings.length) { if (checkedMappings.length + 1 < mappings.length) {
checkedMappings.push(unseenFreeformValues.length > 0) checkedMappings.push(unseenFreeformValues.length > 0)
} }
@ -121,10 +122,10 @@
if (confg.freeform?.key) { if (confg.freeform?.key) {
if (!confg.multiAnswer) { if (!confg.multiAnswer) {
// Somehow, setting multi-answer freeform values is broken if this is not set // 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 { } else {
freeformInput.setData(undefined) freeformInput.set(undefined)
} }
feedback.setData(undefined) feedback.setData(undefined)
} }
@ -134,8 +135,8 @@
// We want to (re)-initialize whenever the 'tags' or 'config' change - but not when 'checkedConfig' changes // We want to (re)-initialize whenever the 'tags' or 'config' change - but not when 'checkedConfig' changes
initialize($tags, config) initialize($tags, config)
} }
onDestroy(
freeformInput.addCallbackAndRun((freeformValue) => { freeformInput.subscribe((freeformValue) => {
if (!mappings || mappings?.length == 0 || config.freeform?.key === undefined) { if (!mappings || mappings?.length == 0 || config.freeform?.key === undefined) {
return return
} }
@ -151,7 +152,8 @@
if (freeformValue?.length > 0) { if (freeformValue?.length > 0) {
selectedMapping = mappings.length selectedMapping = mappings.length
} }
}) }))
$: { $: {
if ( if (
allowDeleteOfFreeform && allowDeleteOfFreeform &&
@ -202,7 +204,7 @@
theme: tags.data["_orig_theme"] ?? state.layout.id, theme: tags.data["_orig_theme"] ?? state.layout.id,
changeType: "answer", changeType: "answer",
}) })
freeformInput.setData(undefined) freeformInput.set(undefined)
selectedMapping = undefined selectedMapping = undefined
selectedTags = undefined selectedTags = undefined