Skip to content

Commit 943a56f

Browse files
authored
Merge pull request #376 from iceljc/features/refine-chat-window
Features/refine chat window
2 parents c2e10ee + 9ff2c83 commit 943a56f

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

src/lib/common/Select.svelte

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,18 @@
7272
/** @type {boolean} */
7373
let loading = false;
7474
75+
/**
76+
* @type {number | undefined}
77+
*/
78+
let timer;
79+
7580
onMount(() => {
7681
initOptions();
7782
});
7883
7984
$: {
8085
innerOptions = verifySelectedOptions(innerOptions, selectedValues);
8186
refOptions = verifySelectedOptions(innerOptions, selectedValues);
82-
applySearchFilter();
83-
changeDisplayText();
8487
}
8588
8689
$: {
@@ -105,36 +108,39 @@
105108
...newOptions
106109
];
107110
108-
changeDisplayText();
109-
} else {
110-
applySearchFilter();
111-
changeDisplayText();
112111
}
113112
} else {
114113
innerOptions = verifySelectedOptions(options, selectedValues);
115114
refOptions = verifySelectedOptions(options, selectedValues);
115+
}
116+
}
117+
118+
$: {
119+
if (innerOptions && refOptions) {
116120
applySearchFilter();
117121
changeDisplayText();
118122
}
119123
}
120124
121-
122125
function initOptions() {
123-
innerOptions = options.map(x => {
126+
const newInnerOptions = options.map(x => {
124127
return {
125128
label: x.label,
126129
value: x.value,
127130
checked: false
128131
}
129132
});
130133
131-
refOptions = options.map(x => {
134+
const newRefOptions = options.map(x => {
132135
return {
133136
label: x.label,
134137
value: x.value,
135138
checked: false
136139
}
137140
});
141+
142+
innerOptions = newInnerOptions;
143+
refOptions = newRefOptions;
138144
}
139145
140146
/**
@@ -167,8 +173,15 @@
167173
/** @param {any} e */
168174
function changeSearchValue(e) {
169175
searchValue = e.target.value || '';
170-
applySearchFilter();
171-
verifySelectAll();
176+
177+
if (timer) {
178+
clearTimeout(timer);
179+
}
180+
181+
timer = setTimeout(() => {
182+
applySearchFilter();
183+
verifySelectAll();
184+
}, 500);
172185
}
173186
174187
function applySearchFilter() {
@@ -186,7 +199,7 @@
186199
* @param {any} option
187200
*/
188201
function checkOption(e, option) {
189-
innerOptions = innerOptions.map(x => {
202+
const newInnerOptions = innerOptions.map(x => {
190203
const item = { ...x };
191204
if (item.value == option.value) {
192205
item.checked = e == null ? !item.checked : e.target.checked;
@@ -196,7 +209,7 @@
196209
return item;
197210
});
198211
199-
refOptions = refOptions.map(x => {
212+
const newRefOptions = refOptions.map(x => {
200213
const item = { ...x };
201214
if (item.value == option.value) {
202215
item.checked = e == null ? !item.checked : e.target.checked;
@@ -206,7 +219,9 @@
206219
return item;
207220
});
208221
209-
changeDisplayText();
222+
innerOptions = newInnerOptions;
223+
refOptions = newRefOptions;
224+
210225
sendEvent();
211226
hideOptionList();
212227
}
@@ -219,7 +234,6 @@
219234
});
220235
221236
syncChangesToRef(selectAllChecked);
222-
changeDisplayText();
223237
sendEvent();
224238
}
225239
@@ -320,15 +334,17 @@
320334
}
321335
322336
function clearSelection() {
323-
innerOptions = innerOptions.map(x => {
337+
const newInnerOptions = innerOptions.map(x => {
324338
return { ...x, checked: false }
325339
});
326340
327-
refOptions = refOptions.map(x => {
341+
const newRefOptions = refOptions.map(x => {
328342
return { ...x, checked: false }
329343
});
330344
331-
changeDisplayText();
345+
innerOptions = newInnerOptions;
346+
refOptions = newRefOptions;
347+
332348
sendEvent();
333349
hideOptionList();
334350
}

src/routes/page/instruction/instruction-components/instruction-agent.svelte

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@
2222
let selectedTemplate = null;
2323
2424
$: {
25-
collectAgentOptions(agents);
25+
initAgentOptions(agents);
2626
}
2727
2828
/**
2929
* @param {import('$agentTypes').AgentModel[]} agents
3030
*/
31-
function collectAgentOptions(agents) {
31+
function initAgentOptions(agents) {
32+
agentOptions = [];
33+
templateOptions = [];
34+
selectedAgent = null;
35+
selectedTemplate = null;
36+
3237
agentOptions = agents?.map(x => ({
3338
label: x.name,
3439
value: x.id

0 commit comments

Comments
 (0)