From 2e645d33036d1d2b86ce1072ab1e463dda64d312 Mon Sep 17 00:00:00 2001 From: dannyl1u Date: Tue, 5 Nov 2024 18:50:58 -0800 Subject: [PATCH] feat: search in settings --- src/lib/components/chat/SettingsModal.svelte | 440 +++++++++++-------- 1 file changed, 257 insertions(+), 183 deletions(-) diff --git a/src/lib/components/chat/SettingsModal.svelte b/src/lib/components/chat/SettingsModal.svelte index a2791c41d..058b452bf 100644 --- a/src/lib/components/chat/SettingsModal.svelte +++ b/src/lib/components/chat/SettingsModal.svelte @@ -15,11 +15,54 @@ import Chats from './Settings/Chats.svelte'; import User from '../icons/User.svelte'; import Personalization from './Settings/Personalization.svelte'; + import SearchInput from '../layout/Sidebar/SearchInput.svelte'; const i18n = getContext('i18n'); export let show = false; + interface SettingsTab { + id: string; + title: string; + keywords: string[]; + } + + const searchData: SettingsTab[] = [ + { id: 'general', title: 'General', keywords: ['general', 'theme', 'language', 'notifications', 'system', 'systemprompt', 'prompt', 'advanced', 'settings', 'defaultsettings', 'configuration', 'systemsettings', 'notificationsettings', 'systempromptconfig', 'languageoptions', 'defaultparameters', 'systemparameters'] }, + { id: 'interface', title: 'Interface', keywords: ['defaultmodel', 'selectmodel', 'ui', 'userinterface', 'display', 'layout', 'design', 'landingpage', 'landingpagemode', 'default', 'chat', 'chatbubble', 'chatui', 'username', 'showusername', 'displayusername', 'widescreen', 'widescreenmode', 'fullscreen', 'expandmode', 'chatdirection', 'lefttoright', 'ltr', 'righttoleft', 'rtl', 'notifications', 'toast', 'toastnotifications', 'largechunks', 'streamlargechunks', 'scroll', 'scrollonbranchchange', 'scrollbehavior', 'richtext', 'richtextinput', 'background', 'chatbackground', 'chatbackgroundimage', 'backgroundimage', 'uploadbackground', 'resetbackground', 'titleautogen', 'titleautogeneration', 'autotitle', 'chattags', 'autochattags', 'responseautocopy', 'clipboard', 'location', 'userlocation', 'userlocationaccess', 'haptic', 'hapticfeedback', 'vibration', 'voice', 'voicecontrol', 'voiceinterruption', 'call', 'emojis', 'displayemoji', 'save', 'interfaceoptions', 'interfacecustomization'] }, + { id: 'personalization', title: 'Personalization', keywords: ['personalization', 'memory', 'personalize', 'preferences', 'profile', 'personalsettings', 'customsettings', 'userpreferences', 'accountpreferences'] }, + { id: 'audio', title: 'Audio', keywords: ['audio', 'sound', 'soundsettings', 'audiocontrol', 'volume', 'speech', 'speechrecognition', 'stt', 'speechtotext', 'tts', 'texttospeech', 'playback', 'playbackspeed', 'voiceplayback', 'speechplayback', 'audiooutput', 'speechengine', 'voicecontrol', 'audioplayback', 'transcription', 'autotranscribe', 'autosend', 'speechsettings', 'audiovoice', 'voiceoptions', 'setvoice', 'nonlocalvoices', 'savesettings', 'audioconfig', 'speechconfig', 'voicerecognition', 'speechsynthesis', 'speechmode', 'voicespeed', 'speechrate', 'speechspeed', 'audioinput', 'audiofeatures', 'voicemodes'] }, + { id: 'chats', title: 'Chats', keywords: ['chat', 'messages', 'conversations', 'chatsettings', 'history', 'chathistory', 'messagehistory', 'messagearchive', 'convo', 'chats', 'conversationhistory', 'exportmessages', 'chatactivity'] }, + { id: 'account', title: 'Account', keywords: ['account', 'profile', 'security', 'privacy', 'settings', 'login', 'useraccount', 'userdata', 'api', 'apikey', 'userprofile', 'profiledetails', 'accountsettings', 'accountpreferences', 'securitysettings', 'privacysettings'] }, + { id: 'about', title: 'About', keywords: ['about', 'info', 'information', 'version', 'documentation', 'help', 'support', 'details', 'aboutus', 'softwareinfo', 'release', 'updates', 'updateinfo', 'versioninfo', 'aboutapp', 'terms', 'termsandconditions', 'contact', 'aboutpage'] }, + { id: 'admin', title: 'Admin', keywords: ['admin', 'administrator', 'adminsettings', 'adminpanel', 'systemadmin', 'administratoraccess', 'systemcontrol', 'manage', 'management', 'admincontrols', 'adminfeatures', 'usercontrol'] } + ]; + + let search = ''; + let visibleTabs = searchData.map((tab) => tab.id); + let searchDebounceTimeout; + + const searchSettings = (query: string): string[] => { + const lowerCaseQuery = query.toLowerCase().trim(); + return searchData + .filter( + (tab) => + tab.title.toLowerCase().includes(lowerCaseQuery) || + tab.keywords.some((keyword) => keyword.includes(lowerCaseQuery)) + ) + .map((tab) => tab.id); + }; + + const searchDebounceHandler = () => { + clearTimeout(searchDebounceTimeout); + searchDebounceTimeout = setTimeout(() => { + visibleTabs = searchSettings(search); + if (visibleTabs.length > 0 && !visibleTabs.includes(selectedTab)) { + selectedTab = visibleTabs[0]; + } + }, 200); + }; + const saveSettings = async (updated) => { console.log(updated); await settings.set({ ...$settings, ...updated }); @@ -93,16 +136,8 @@ id="settings-tabs-container" class="tabs flex flex-row overflow-x-auto space-x-1 md:space-x-0 md:space-y-1 md:flex-col flex-1 md:flex-none md:w-40 dark:text-gray-200 text-xs text-left mb-3 md:mb-0" > - - - - - + {:else if tabId === 'interface'} + - - + {:else if tabId === 'personalization'} + - - + {:else if tabId === 'audio'} + - - {#if $user.role === 'admin'} - + {:else if tabId === 'chats'} + + {:else if tabId === 'account'} + + {:else if tabId === 'about'} + + {:else if tabId === 'admin'} + {#if $user.role === 'admin'} + - {/if} - - +
+ + + +
+
{$i18n.t('Admin Settings')}
+ + {/if} + {/if} + {/each}
{#if selectedTab === 'general'}