|
1 | 1 | <script lang="ts">
|
2 |
| - import IconButton from '@smui/icon-button'; |
| 2 | + import TextInput from '$lib/components/Form/Inputs/TextInput.svelte'; |
| 3 | + import Paper from '@smui/paper'; |
3 | 4 | import { getFieldConfig, getValue, persistValue } from '$lib/context/FormContext.svelte';
|
4 |
| - import TextInput from '../Inputs/TextInput.svelte'; |
5 | 5 | import FieldTools from '../FieldTools.svelte';
|
6 |
| - import type { ContentDescription } from '$lib/models/metadata'; |
7 | 6 |
|
8 |
| - type ContentDescriptionListEntry = ContentDescription & { listId: string }; |
| 7 | + const KEY = 'isoMetadata.contentDescription'; |
9 | 8 |
|
10 |
| - const KEY = 'isoMetadata.UNKNOWN'; |
11 |
| -
|
12 |
| - const valueFromData = $derived(getValue<ContentDescription[]>(KEY)); |
13 |
| - let values = $state<ContentDescriptionListEntry[]>([]); |
| 9 | + const valueFromData = $derived(getValue<string>(KEY)); |
| 10 | + let value = $state<string>(''); |
14 | 11 | $effect(() => {
|
15 | 12 | if (valueFromData) {
|
16 |
| - values = valueFromData?.map((description) => { |
17 |
| - const listId = (Math.floor(Math.random() * 1000000) + Date.now()).toString(36); |
18 |
| - return { |
19 |
| - listId, |
20 |
| - url: description.url || '', |
21 |
| - description: description.description || '', |
22 |
| - code: 'information' |
23 |
| - }; |
24 |
| - }); |
| 13 | + value = valueFromData; |
25 | 14 | }
|
26 | 15 | });
|
27 |
| -
|
28 | 16 | let showCheckmark = $state(false);
|
29 |
| - const fieldConfig = getFieldConfig<ContentDescription[]>(KEY); |
| 17 | + const fieldConfig = getFieldConfig<string>(KEY); |
30 | 18 |
|
31 |
| - const persist = async () => { |
32 |
| - const response = await persistValue( |
33 |
| - KEY, |
34 |
| - values.map( |
35 |
| - (contentDescription) => |
36 |
| - ({ |
37 |
| - description: contentDescription.description, |
38 |
| - url: contentDescription.url, |
39 |
| - code: 'information' |
40 |
| - }) satisfies ContentDescription |
41 |
| - ) |
42 |
| - ); |
| 19 | + const onBlur = async () => { |
| 20 | + const response = await persistValue(KEY, value); |
43 | 21 | if (response.ok) {
|
44 | 22 | showCheckmark = true;
|
45 | 23 | }
|
46 | 24 | };
|
47 |
| -
|
48 |
| - const addItem = () => { |
49 |
| - const listId = Date.now().toString(36); |
50 |
| - values = [ |
51 |
| - { |
52 |
| - listId, |
53 |
| - url: '', |
54 |
| - description: '', |
55 |
| - code: 'information' |
56 |
| - }, |
57 |
| - ...values |
58 |
| - ]; |
59 |
| - }; |
60 |
| -
|
61 |
| - const removeItem = (listId: string) => { |
62 |
| - // TODO: add popconfirm |
63 |
| - values = values.filter((contentDescription) => contentDescription.listId !== listId); |
64 |
| - persist(); |
65 |
| - }; |
66 | 25 | </script>
|
67 | 26 |
|
68 |
| -<div class="content-description-field"> |
69 |
| - <fieldset> |
70 |
| - <legend |
71 |
| - >{fieldConfig?.label || 'TODO: Inhaltliche Beschreibung'} |
72 |
| - <IconButton |
73 |
| - class="material-icons" |
74 |
| - onclick={() => addItem()} |
75 |
| - size="button" |
76 |
| - title="Quelle hinzufügen" |
77 |
| - > |
78 |
| - add |
79 |
| - </IconButton> |
80 |
| - </legend> |
81 |
| - {#each values as contentDescription (contentDescription.listId)} |
82 |
| - <fieldset class="contentDescription"> |
83 |
| - <legend> |
84 |
| - <IconButton |
85 |
| - class="material-icons" |
86 |
| - onclick={() => removeItem(contentDescription.listId)} |
87 |
| - size="button" |
88 |
| - title="Quelle entfernen" |
89 |
| - > |
90 |
| - delete |
91 |
| - </IconButton> |
92 |
| - </legend> |
93 |
| - <TextInput |
94 |
| - bind:value={contentDescription.url} |
95 |
| - key={KEY} |
96 |
| - label="URL (Dokument oder Website)" |
97 |
| - onblur={persist} |
98 |
| - /> |
99 |
| - <TextInput |
100 |
| - bind:value={contentDescription.description} |
101 |
| - key={KEY} |
102 |
| - label="Beschreibung der Quelle" |
103 |
| - onblur={persist} |
104 |
| - /> |
105 |
| - </fieldset> |
106 |
| - {/each} |
107 |
| - </fieldset> |
| 27 | +<div class="technical-description-field"> |
| 28 | + <Paper> |
| 29 | + <TextInput |
| 30 | + bind:value |
| 31 | + label={fieldConfig?.label} |
| 32 | + onblur={onBlur} |
| 33 | + /> |
| 34 | + </Paper> |
108 | 35 | <FieldTools key={KEY} bind:checkMarkAnmiationRunning={showCheckmark} />
|
109 | 36 | </div>
|
110 | 37 |
|
111 | 38 | <style lang="scss">
|
112 |
| - .content-description-field { |
| 39 | + .technical-description-field { |
113 | 40 | position: relative;
|
114 | 41 | display: flex;
|
115 | 42 | gap: 0.25em;
|
116 | 43 |
|
117 |
| - fieldset { |
| 44 | + :global(.smui-paper) { |
118 | 45 | flex: 1;
|
119 |
| - border-radius: 4px; |
120 |
| -
|
121 |
| - > legend { |
122 |
| - display: flex; |
123 |
| - align-items: center; |
124 |
| - font-size: 0.75em; |
125 |
| - } |
126 |
| - } |
127 |
| -
|
128 |
| - .contentDescription { |
129 |
| - legend { |
130 |
| - text-align: right; |
131 |
| - } |
132 | 46 | }
|
133 | 47 |
|
134 | 48 | :global(.mdc-text-field) {
|
|
0 commit comments