refac
This commit is contained in:
1 parent
e05f9fa17e
commit
c1460570b7
5 files changed
+300
-53
No files matched your search
@@ -56,6 +56,7 @@
|
||||
let localDBChats = [];
|
||||
|
||||
let version;
|
||||
let handledSettingsUrl = '';
|
||||
|
||||
const clearChatInputStorage = () => {
|
||||
const chatInputKeys = Object.keys(localStorage).filter((key) => key.startsWith('chat-input'));
|
||||
@@ -194,6 +195,34 @@
|
||||
tools.set(toolsData);
|
||||
};
|
||||
|
||||
const openSettingsFromUrl = async () => {
|
||||
const requestedSettings = $page.url.searchParams.get('settings');
|
||||
if (!requestedSettings) {
|
||||
return;
|
||||
}
|
||||
|
||||
const urlKey = `${$page.url.pathname}${$page.url.search}${$page.url.hash}`;
|
||||
if (handledSettingsUrl === urlKey) {
|
||||
return;
|
||||
}
|
||||
handledSettingsUrl = urlKey;
|
||||
|
||||
showSettings.set(
|
||||
requestedSettings.startsWith('admin:') && $user?.role !== 'admin'
|
||||
? 'general'
|
||||
: requestedSettings
|
||||
);
|
||||
|
||||
const params = new URLSearchParams($page.url.searchParams);
|
||||
params.delete('settings');
|
||||
const query = params.toString();
|
||||
await goto(`${$page.url.pathname}${query ? `?${query}` : ''}${$page.url.hash}`, {
|
||||
replaceState: true,
|
||||
noScroll: true,
|
||||
keepFocus: true
|
||||
});
|
||||
};
|
||||
|
||||
onMount(async () => {
|
||||
if ($user === undefined || $user === null) {
|
||||
await goto('/auth');
|
||||
@@ -367,6 +396,10 @@
|
||||
loaded = true;
|
||||
});
|
||||
|
||||
$: if (loaded) {
|
||||
void openSettingsFromUrl();
|
||||
}
|
||||
|
||||
const checkForVersionUpdates = async () => {
|
||||
version = await getVersionUpdates(localStorage.token).catch((error) => {
|
||||
return {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { onMount, getContext } from 'svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
import { WEBUI_NAME, config, mobile, showSidebar, user } from '$lib/stores';
|
||||
import { WEBUI_NAME, config, mobile, showSettings, showSidebar, user } from '$lib/stores';
|
||||
import { page } from '$app/stores';
|
||||
import Tooltip from '$lib/components/common/Tooltip.svelte';
|
||||
|
||||
@@ -105,7 +105,11 @@
|
||||
class="min-w-fit p-1.5 {$page.url.pathname.includes('/admin/settings')
|
||||
? ''
|
||||
: 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition select-none"
|
||||
href="/admin/settings">{$i18n.t('Settings')}</a
|
||||
href="/admin/settings"
|
||||
on:click={(event) => {
|
||||
event.preventDefault();
|
||||
showSettings.set('admin:general');
|
||||
}}>{$i18n.t('Settings')}</a
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
onMount(() => {
|
||||
goto('/admin/settings/general');
|
||||
goto('/?settings=admin%3Ageneral', { replaceState: true });
|
||||
});
|
||||
</script>
|
||||
@@ -1,5 +1,11 @@
|
||||
<script>
|
||||
import Settings from '$lib/components/admin/Settings.svelte';
|
||||
</script>
|
||||
import { goto } from '$app/navigation';
|
||||
import { page } from '$app/stores';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
<Settings />
|
||||
onMount(() => {
|
||||
const params = new URLSearchParams($page.url.searchParams);
|
||||
params.set('settings', `admin:${$page.params.tab ?? 'general'}`);
|
||||
goto(`/?${params.toString()}`, { replaceState: true });
|
||||
});
|
||||
</script>
|
||||
Reference in new issue
Block a user