Skip to content

Commit 88bf3c9

Browse files
authored
Merge pull request #223 from iceljc/features/refine-chat-window
change to key value
2 parents a43bc03 + 53f812a commit 88bf3c9

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

src/lib/common/MultiSelect.svelte

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/** @type {string} */
99
export let tag;
1010
11-
/** @type {any[]} */
11+
/** @type {{key: string, value: string}[]} */
1212
export let options = [];
1313
1414
/** @type {boolean} */
@@ -38,10 +38,10 @@
3838
/** @type {boolean} */
3939
let showOptionList = false;
4040
41-
/** @type {any[]} */
41+
/** @type {{key: string, value: string, checked: boolean}[]} */
4242
let innerOptions = [];
4343
44-
/** @type {any[]} */
44+
/** @type {{key: string, value: string, checked: boolean}[]} */
4545
let refOptions = [];
4646
4747
/** @type {string} */
@@ -53,16 +53,16 @@
5353
onMount(() => {
5454
innerOptions = options.map(x => {
5555
return {
56-
id: x.id,
57-
name: x.name,
56+
key: x.key,
57+
value: x.value,
5858
checked: false
5959
}
6060
});
6161
6262
refOptions = options.map(x => {
6363
return {
64-
id: x.id,
65-
name: x.name,
64+
key: x.key,
65+
value: x.value,
6666
checked: false
6767
}
6868
});
@@ -82,7 +82,7 @@
8282
function changeSearchValue(e) {
8383
searchValue = e.target.value || '';
8484
if (searchValue) {
85-
innerOptions = refOptions.filter(x => x.name.includes(searchValue));
85+
innerOptions = refOptions.filter(x => x.value.includes(searchValue));
8686
} else {
8787
innerOptions = refOptions;
8888
}
@@ -96,13 +96,15 @@
9696
* @param {any} option
9797
*/
9898
function checkOption(e, option) {
99-
const found = innerOptions.find(x => x.id == option.id);
100-
found.checked = e.target.checked;
99+
const found = innerOptions.find(x => x.key == option.key);
100+
const refFound = refOptions.find(x => x.key == option.key);
101101
102-
const refFound = refOptions.find(x => x.id == option.id);
103-
refFound.checked = e.target.checked;
104-
changeDisplayText();
105-
sendEvent();
102+
if (found && refFound) {
103+
found.checked = e.target.checked;
104+
refFound.checked = e.target.checked;
105+
changeDisplayText();
106+
sendEvent();
107+
}
106108
}
107109
108110
/** @param {any} e */
@@ -119,9 +121,9 @@
119121
120122
/** @param {boolean} checked */
121123
function syncChangesToRef(checked) {
122-
const ids = innerOptions.map(x => x.id);
124+
const keys = innerOptions.map(x => x.key);
123125
refOptions = refOptions.map(x => {
124-
if (ids.includes(x.id)) {
126+
if (keys.includes(x.key)) {
125127
return {
126128
...x,
127129
checked: checked
@@ -210,11 +212,11 @@
210212
211213
$: {
212214
if (options.length > refOptions.length) {
213-
const curIds = refOptions.map(x => x.id);
214-
const newOptions = options.filter(x => !curIds.includes(x.id)).map(x => {
215+
const curKeys = refOptions.map(x => x.key);
216+
const newOptions = options.filter(x => !curKeys.includes(x.key)).map(x => {
215217
return {
216-
id: x.id,
217-
name: x.name,
218+
key: x.key,
219+
value: x.value,
218220
checked: false
219221
};
220222
});
@@ -296,7 +298,7 @@
296298
/>
297299
</div>
298300
<div class="line-align-center select-name">
299-
{option.name}
301+
{option.value}
300302
</div>
301303
</li>
302304
{/each}

0 commit comments

Comments
 (0)