mirror of
https://github.com/open-webui/open-webui.git
synced 2026-12-05 11:07:55 -05:00
refac
This commit is contained in:
1 parent
14da6b83ed
commit
5573fca1f2
3 files changed
+118
-2
No files matched your search
@@ -141,6 +141,7 @@
|
||||
import XMarkIcon from '../icons/XMark.svelte';
|
||||
import ConfirmDialog from '../common/ConfirmDialog.svelte';
|
||||
import MoreHorizontalIcon from './Sidebar/icons/MoreHorizontal.svelte';
|
||||
import EyeSlashIcon from '../icons/EyeSlash.svelte';
|
||||
import PlusIcon from './Sidebar/icons/Plus.svelte';
|
||||
import MobileSwipePanel from '../common/MobileSwipePanel.svelte';
|
||||
|
||||
@@ -522,7 +523,28 @@
|
||||
($settings?.sidebarSectionOrder ?? []).filter((id) => SIDEBAR_SECTIONS.includes(id))
|
||||
);
|
||||
|
||||
$: visibleSections = sectionOrder.filter((id) => {
|
||||
let sectionLabels: Record<string, string>;
|
||||
$: sectionLabels = {
|
||||
teams: $i18n.t('Teams'),
|
||||
models: $i18n.t('Models'),
|
||||
notes: $i18n.t('Notes'),
|
||||
channels: $i18n.t('Channels'),
|
||||
folders: $i18n.t('Folders'),
|
||||
chats: $i18n.t('Chats')
|
||||
};
|
||||
|
||||
$: hiddenSections = $settings?.sidebarSectionHidden ?? [];
|
||||
$: visibleSections = availableSections.filter((id) => !hiddenSections.includes(id));
|
||||
|
||||
const toggleSection = async (id: string) => {
|
||||
const next = hiddenSections.includes(id)
|
||||
? hiddenSections.filter((hidden) => hidden !== id)
|
||||
: [...hiddenSections, id];
|
||||
settings.set({ ...$settings, sidebarSectionHidden: next });
|
||||
await updateUserSettings(localStorage.token, { ui: { sidebarSectionHidden: next } });
|
||||
};
|
||||
|
||||
$: availableSections = sectionOrder.filter((id) => {
|
||||
switch (id) {
|
||||
case 'models':
|
||||
return $visiblePinnedModels.length > 0;
|
||||
@@ -1307,6 +1329,73 @@
|
||||
const isWindows = /Windows/i.test(navigator.userAgent);
|
||||
</script>
|
||||
|
||||
<!-- Which sections show; in every section's ⋯ menu and the user menu, the way back once all are hidden. -->
|
||||
{#snippet sectionChecklist()}
|
||||
<DropdownSub
|
||||
contentClass="select-none z-50 max-h-80 overflow-y-auto"
|
||||
maxWidth={320}
|
||||
sideOffset={6}
|
||||
>
|
||||
<button
|
||||
slot="trigger"
|
||||
type="button"
|
||||
class="flex h-[1.6875rem] w-full cursor-pointer select-none items-center gap-2 rounded-xl px-2 text-left text-[0.8125rem] outline-hidden"
|
||||
>
|
||||
<Sidebar className="size-3.5" />
|
||||
<span class="min-w-0 flex-1 truncate text-left">{$i18n.t('Sidebar')}</span>
|
||||
<ChevronRight className="size-3.5 shrink-0 text-base-400 rtl:rotate-180" />
|
||||
</button>
|
||||
{#each availableSections as section (section)}
|
||||
{@const shown = !hiddenSections.includes(section)}
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemcheckbox"
|
||||
aria-checked={shown}
|
||||
on:click={() => toggleSection(section)}
|
||||
>
|
||||
<span class="flex-1 text-left">{sectionLabels[section]}</span>
|
||||
{#if shown}<CheckIcon className="size-3! shrink-0" />{/if}
|
||||
</button>
|
||||
{/each}
|
||||
</DropdownSub>
|
||||
{/snippet}
|
||||
|
||||
<!-- Every section heading's ⋯ menu ends with these. -->
|
||||
{#snippet sectionVisibilityItems(id: string, close = () => {})}
|
||||
<button
|
||||
class="flex h-[1.6875rem] w-full items-center gap-2 rounded-xl px-2 text-[0.8125rem] select-none cursor-pointer hover:bg-base-100 dark:hover:bg-base-900"
|
||||
on:click={() => {
|
||||
close();
|
||||
toggleSection(id);
|
||||
}}
|
||||
>
|
||||
<EyeSlashIcon className="size-3.5" />
|
||||
<div class="flex items-center">{$i18n.t('Hide from sidebar')}</div>
|
||||
</button>
|
||||
{@render sectionChecklist()}
|
||||
{/snippet}
|
||||
|
||||
<!-- A ⋯ menu for headings that have no other menu items. -->
|
||||
{#snippet sectionMoreMenu(id: string)}
|
||||
<Dropdown align="start">
|
||||
<Tooltip content={$i18n.t('More')}>
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center justify-center w-7 h-7 rounded-lg text-base-300 hover:text-base-500 dark:text-base-600 dark:hover:text-base-400 transition-colors duration-100"
|
||||
aria-label={$i18n.t('More')}
|
||||
>
|
||||
<MoreHorizontalIcon className="size-3.5" strokeWidth="2" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
|
||||
<div slot="content">
|
||||
<DropdownMenu className="min-w-[10.625rem]">
|
||||
{@render sectionVisibilityItems(id)}
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</Dropdown>
|
||||
{/snippet}
|
||||
|
||||
<ConfirmDialog
|
||||
bind:show={showDeleteSelectedConfirm}
|
||||
title={$i18n.t('Delete {{count}} chats?', { count: deleteSelectedIds.length })}
|
||||
@@ -1576,7 +1665,11 @@
|
||||
<div>
|
||||
<div class=" flex justify-center items-center">
|
||||
{#if $user !== undefined && $user !== null}
|
||||
<UserMenu role={$user?.role} profile={$config?.features?.enable_user_status ?? true}>
|
||||
<UserMenu
|
||||
role={$user?.role}
|
||||
profile={$config?.features?.enable_user_status ?? true}
|
||||
>
|
||||
<svelte:fragment slot="sidebar">{@render sectionChecklist()}</svelte:fragment>
|
||||
<button
|
||||
type="button"
|
||||
class=" cursor-pointer flex size-8.5 items-center justify-center transition group"
|
||||
@@ -1829,6 +1922,9 @@
|
||||
name={$i18n.t('Models')}
|
||||
dragAndDrop={false}
|
||||
>
|
||||
<svelte:fragment slot="action">
|
||||
{@render sectionMoreMenu('models')}
|
||||
</svelte:fragment>
|
||||
<PinnedModelList bind:selectedChatId {shiftKey} />
|
||||
</SidebarSection>
|
||||
{:else if sectionId === 'notes'}
|
||||
@@ -1846,6 +1942,9 @@
|
||||
}}
|
||||
onAddLabel={$i18n.t('New Note')}
|
||||
>
|
||||
<svelte:fragment slot="action">
|
||||
{@render sectionMoreMenu('notes')}
|
||||
</svelte:fragment>
|
||||
<PinnedNoteList bind:selectedChatId />
|
||||
</SidebarSection>
|
||||
{:else if sectionId === 'channels'}
|
||||
@@ -1866,6 +1965,9 @@
|
||||
: null}
|
||||
onAddLabel={$i18n.t('Create Channel')}
|
||||
>
|
||||
<svelte:fragment slot="action">
|
||||
{@render sectionMoreMenu('channels')}
|
||||
</svelte:fragment>
|
||||
{#each channelGroups as group, groupIdx}
|
||||
{#if groupIdx > 0}
|
||||
<hr class=" border-base-100/40 dark:border-base-800/10 my-1.5 w-full" />
|
||||
@@ -1895,6 +1997,7 @@
|
||||
>
|
||||
<!-- One +: search the teams to join, or create one. -->
|
||||
<svelte:fragment slot="action">
|
||||
{@render sectionMoreMenu('teams')}
|
||||
{#if canCreateTeams || browsableTeams.length > 0}
|
||||
<AddTeamMenu
|
||||
teams={browsableTeams}
|
||||
@@ -2044,6 +2147,11 @@
|
||||
<PlusIcon className="size-3.5" />
|
||||
<div class="flex items-center">{$i18n.t('New section')}</div>
|
||||
</button>
|
||||
<hr class="border-base-50/30 dark:border-base-800/30" />
|
||||
{@render sectionVisibilityItems(
|
||||
'folders',
|
||||
() => (showFoldersMenu = false)
|
||||
)}
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</Dropdown>
|
||||
@@ -2261,6 +2369,8 @@
|
||||
<CheckIcon className="size-3.5" />
|
||||
<div class="flex items-center">{$i18n.t('Mark all as read')}</div>
|
||||
</button>
|
||||
<hr class="border-base-50/30 dark:border-base-800/30" />
|
||||
{@render sectionVisibilityItems('chats', () => (showChatsMenu = false))}
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</Dropdown>
|
||||
@@ -2538,6 +2648,7 @@
|
||||
profile={$config?.features?.enable_user_status ?? true}
|
||||
className="w-[calc(var(--sidebar-width)-1rem)]"
|
||||
>
|
||||
<svelte:fragment slot="sidebar">{@render sectionChecklist()}</svelte:fragment>
|
||||
<button
|
||||
type="button"
|
||||
class=" flex items-center rounded-xl py-1.5 px-1.5 w-full hover:bg-base-100 dark:hover:bg-base-900 transition"
|
||||
|
||||
@@ -645,6 +645,9 @@
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
<!-- The sidebar's section checklist: the way back once every section is hidden. -->
|
||||
<slot name="sidebar" />
|
||||
|
||||
<hr class="border-base-50/30 dark:border-base-800/30 my-0.5 mx-1 p-0" />
|
||||
|
||||
{#if role === 'admin'}
|
||||
|
||||
@@ -399,6 +399,8 @@ type Settings = {
|
||||
pinnedNotesOrder?: string[];
|
||||
/** Sidebar section ids ('models', 'notes', 'channels', 'folders', 'chats') in display order. */
|
||||
sidebarSectionOrder?: string[];
|
||||
/** Sidebar section ids the user has hidden. */
|
||||
sidebarSectionHidden?: string[];
|
||||
/** Folder page tab ids ('overview', 'files', 'chats', ...) in display order. */
|
||||
folderTabOrder?: string[];
|
||||
/** Folder page tab ids the user has hidden. */
|
||||
|
||||
Reference in new issue
Block a user