Skip to content

Commit 48b315b

Browse files
author
Jicheng Lu
committed
clean code
1 parent 5ec010a commit 48b315b

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/** @type {boolean} */
1212
export let disabled = false;
1313
14-
/** @type {import('$commonTypes').LlmConfig?} */
14+
/** @type {import('$commonTypes').LlmConfig | null | undefined} */
1515
export let selectedProvider = null;
1616
1717
/** @type {any} */
@@ -46,17 +46,17 @@
4646
function selectProvider(e) {
4747
// @ts-ignore
4848
const selectedValues = e.detail.selecteds?.map(x => x.value) || [];
49-
selectedProvider = llmConfigs?.find(x => x.provider === selectedValues[0]) || null;
49+
selectedProvider = selectedValues.length > 0 ? llmConfigs?.find(x => x.provider === selectedValues[0]) : null;
5050
onProviderChanged();
51-
disPatchEvent();
51+
dispatchEvent();
5252
}
5353
5454
/** @param {any} e */
5555
function selectModel(e) {
5656
// @ts-ignore
5757
const selectedValues = e.detail.selecteds?.map(x => x.value) || [];
58-
selectedModel = modelOptions.find(x => x.id === selectedValues[0]);
59-
disPatchEvent();
58+
selectedModel = selectedValues.length > 0 ? modelOptions.find(x => x.id === selectedValues[0]) : null;
59+
dispatchEvent();
6060
}
6161
6262
/** @param {any?} targetModel */
@@ -75,9 +75,9 @@
7575
}
7676
}
7777
78-
function disPatchEvent() {
78+
function dispatchEvent() {
7979
svelteDispatch('llmSelected', {
80-
provider: selectedProvider,
80+
provider: selectedProvider || null,
8181
model: selectedModel?.name
8282
});
8383
}
@@ -88,12 +88,6 @@
8888
<div class="instruct-setting-item">
8989
<div class="instruct-setting-dropdown">
9090
<div class="text-primary fw-bold mb-1">Provider</div>
91-
<!-- <select class="form-select" id="provider" value={selectedProvider?.provider || null} disabled={disabled} on:change={e => selectProvider(e)}>
92-
<option value={null} disabled selected>{$_('Select Provider')}</option>
93-
{#each providerOptions as op}
94-
<option value={`${op.id}`} selected={op.id === selectedProvider?.provider}>{$_(`${op.name}`)}</option>
95-
{/each}
96-
</select> -->
9791
<Select
9892
tag={'provider-select'}
9993
placeholder={'Select Provider'}
@@ -109,12 +103,6 @@
109103
<div class="instruct-setting-item">
110104
<div class="instruct-setting-dropdown">
111105
<div class="text-primary fw-bold mb-1">Model</div>
112-
<!-- <select class="form-select" id="model" value={selectedModel?.id || null} disabled={disabled} on:change={e => selectModel(e)}>
113-
<option value={null} disabled selected>{$_('Select Model')}</option>
114-
{#each modelOptions as op}
115-
<option value={`${op.id}`} selected={op.id === selectedModel?.id}>{$_(`${op.name}`)}</option>
116-
{/each}
117-
</select> -->
118106
<Select
119107
tag={'model-select'}
120108
placeholder={'Select Model'}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/** @type {any[]} */
1717
let templateOptions = [];
1818
19-
/** @type {import('$agentTypes').AgentModel?} */
19+
/** @type {import('$agentTypes').AgentModel | null | undefined} */
2020
let selectedAgent = null;
2121
/** @type {any} */
2222
let selectedTemplate = null;
@@ -40,7 +40,7 @@
4040
// @ts-ignore
4141
const selectedValues = e.detail.selecteds?.map(x => x.value) || [];
4242
selectedTemplate = null;
43-
selectedAgent = agents?.find(x => x.id === selectedValues[0]) || null;
43+
selectedAgent = selectedValues.length > 0 ? agents?.find(x => x.id === selectedValues[0]) : null;
4444
templateOptions = selectedAgent?.templates?.map(x => ({
4545
id: x.name,
4646
name: x.name,
@@ -56,14 +56,14 @@
5656
function selectTemplate(e) {
5757
// @ts-ignore
5858
const selectedValues = e.detail.selecteds?.map(x => x.value) || [];
59-
selectedTemplate = templateOptions.find(x => x.value === selectedValues[0]) || null;
59+
selectedTemplate = selectedValues.length > 0 ? templateOptions.find(x => x.value === selectedValues[0]) : null;
6060
dispatchEvent();
6161
}
6262
6363
function dispatchEvent() {
6464
svelteDispatch('agentSelected', {
65-
agent: selectedAgent,
66-
template: selectedTemplate
65+
agent: selectedAgent || null,
66+
template: selectedTemplate || null
6767
});
6868
}
6969
</script>

0 commit comments

Comments
 (0)