mirror of
https://github.com/danielmiessler/Fabric.git
synced 2026-01-09 14:28:01 -05:00
fix(gui): fix Select binding and empty input handling
- Use bind:value for proper two-way binding with Select component - Handle empty input to clear session when user clears the field - Skip session change if value unchanged to avoid redundant API calls - Track previous session to restore when placeholder selected 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,26 +13,33 @@
|
|||||||
const trimmed = sessionInput.trim();
|
const trimmed = sessionInput.trim();
|
||||||
if (trimmed) {
|
if (trimmed) {
|
||||||
setSession(trimmed);
|
setSession(trimmed);
|
||||||
|
} else {
|
||||||
|
// Clear session when input is empty
|
||||||
|
sessionInput = '';
|
||||||
|
setSession(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleSessionSelect(event: Event) {
|
let previousSessionInput = '';
|
||||||
const target = event.target as HTMLSelectElement;
|
|
||||||
const value = target.value;
|
|
||||||
|
|
||||||
// If the placeholder option (empty value) is selected, do not clear the session.
|
async function handleSessionSelect() {
|
||||||
// Instead, keep the current session and restore the input field to it.
|
// If the placeholder option (empty value) is selected, restore to previous value
|
||||||
if (!value) {
|
if (!sessionInput) {
|
||||||
sessionInput = $currentSession ?? '';
|
sessionInput = previousSessionInput || $currentSession || '';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionInput = value;
|
// Skip if session hasn't changed
|
||||||
setSession(value);
|
if (sessionInput === $currentSession) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
previousSessionInput = sessionInput;
|
||||||
|
setSession(sessionInput);
|
||||||
|
|
||||||
// Load the selected session's message history so the chat reflects prior context
|
// Load the selected session's message history so the chat reflects prior context
|
||||||
try {
|
try {
|
||||||
const messages = await sessionAPI.loadSessionMessages(value);
|
const messages = await sessionAPI.loadSessionMessages(sessionInput);
|
||||||
messageStore.set(messages);
|
messageStore.set(messages);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load session messages:', error);
|
console.error('Failed to load session messages:', error);
|
||||||
@@ -62,7 +69,7 @@
|
|||||||
/>
|
/>
|
||||||
{#if sessionsList.length > 0}
|
{#if sessionsList.length > 0}
|
||||||
<Select
|
<Select
|
||||||
value={sessionInput}
|
bind:value={sessionInput}
|
||||||
on:change={handleSessionSelect}
|
on:change={handleSessionSelect}
|
||||||
class="mt-2 bg-primary-800/30 border-none hover:bg-primary-800/40 transition-colors"
|
class="mt-2 bg-primary-800/30 border-none hover:bg-primary-800/40 transition-colors"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user