enh/feat: persist folder state
Co-Authored-By: G30 <50341825+silentoplayz@users.noreply.github.com>
This commit is contained in:
1 parent
bbd48b3638
commit
7e03637446
2 files changed
+76
-68
No files matched your search
@@ -26,6 +26,7 @@
|
|||||||
export let dragAndDrop = true;
|
export let dragAndDrop = true;
|
||||||
|
|
||||||
let folderElement;
|
let folderElement;
|
||||||
|
let loaded = false;
|
||||||
|
|
||||||
let draggedOver = false;
|
let draggedOver = false;
|
||||||
|
|
||||||
@@ -103,6 +104,13 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
const state = localStorage.getItem(`${id}-folder-state`);
|
||||||
|
if (state !== null) {
|
||||||
|
open = state === 'true';
|
||||||
|
}
|
||||||
|
|
||||||
|
loaded = true;
|
||||||
|
|
||||||
if (!dragAndDrop) {
|
if (!dragAndDrop) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -122,70 +130,73 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div bind:this={folderElement} class="relative {className}">
|
<div bind:this={folderElement} class="relative {className}">
|
||||||
{#if draggedOver}
|
{#if loaded}
|
||||||
<div
|
{#if draggedOver}
|
||||||
class="absolute top-0 left-0 w-full h-full rounded-xs bg-gray-100/50 dark:bg-gray-700/20 bg-opacity-50 dark:bg-opacity-10 z-50 pointer-events-none touch-none"
|
|
||||||
></div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if collapsible}
|
|
||||||
<Collapsible
|
|
||||||
bind:open
|
|
||||||
className="w-full "
|
|
||||||
buttonClassName="w-full"
|
|
||||||
onChange={(state) => {
|
|
||||||
dispatch('change', state);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
||||||
<div
|
<div
|
||||||
id="sidebar-folder-button"
|
class="absolute top-0 left-0 w-full h-full rounded-xs bg-gray-100/50 dark:bg-gray-700/20 bg-opacity-50 dark:bg-opacity-10 z-50 pointer-events-none touch-none"
|
||||||
class=" w-full group rounded-xl relative flex items-center justify-between hover:bg-gray-100 dark:hover:bg-gray-900 transition {buttonClassName}"
|
></div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if collapsible}
|
||||||
|
<Collapsible
|
||||||
|
bind:open
|
||||||
|
className="w-full "
|
||||||
|
buttonClassName="w-full"
|
||||||
|
onChange={(state) => {
|
||||||
|
dispatch('change', state);
|
||||||
|
localStorage.setItem(`${id}-folder-state`, `${state}`);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<button class="w-full py-1.5 pl-2 flex items-center gap-1.5 text-xs font-medium">
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||||
{#if chevron}
|
<div
|
||||||
<div class=" p-[1px]">
|
id="sidebar-folder-button"
|
||||||
{#if open}
|
class=" w-full group rounded-xl relative flex items-center justify-between hover:bg-gray-100 dark:hover:bg-gray-900 transition {buttonClassName}"
|
||||||
<ChevronDown className=" size-3" strokeWidth="2" />
|
>
|
||||||
{:else}
|
<button class="w-full py-1.5 pl-2 flex items-center gap-1.5 text-xs font-medium">
|
||||||
<ChevronRight className=" size-3" strokeWidth="2" />
|
{#if chevron}
|
||||||
{/if}
|
<div class=" p-[1px]">
|
||||||
|
{#if open}
|
||||||
|
<ChevronDown className=" size-3" strokeWidth="2" />
|
||||||
|
{:else}
|
||||||
|
<ChevronRight className=" size-3" strokeWidth="2" />
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div class="translate-y-[0.5px] {chevron ? '' : 'pl-0.5'}">
|
||||||
|
{name}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
|
||||||
|
|
||||||
<div class="translate-y-[0.5px] {chevron ? '' : 'pl-0.5'}">
|
|
||||||
{name}
|
|
||||||
</div>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{#if onAdd}
|
|
||||||
<button
|
|
||||||
class="absolute z-10 right-2 invisible group-hover:visible self-center flex items-center dark:text-gray-300"
|
|
||||||
on:pointerup={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
}}
|
|
||||||
on:click={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
onAdd();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Tooltip content={onAddLabel}>
|
|
||||||
<button
|
|
||||||
class="p-0.5 dark:hover:bg-gray-850 rounded-lg touch-auto"
|
|
||||||
on:click={(e) => {}}
|
|
||||||
>
|
|
||||||
<Plus className=" size-3" strokeWidth="2.5" />
|
|
||||||
</button>
|
|
||||||
</Tooltip>
|
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div slot="content" class="w-full">
|
{#if onAdd}
|
||||||
<slot></slot>
|
<button
|
||||||
</div>
|
class="absolute z-10 right-2 invisible group-hover:visible self-center flex items-center dark:text-gray-300"
|
||||||
</Collapsible>
|
on:pointerup={(e) => {
|
||||||
{:else}
|
e.stopPropagation();
|
||||||
<slot></slot>
|
}}
|
||||||
|
on:click={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
onAdd();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Tooltip content={onAddLabel}>
|
||||||
|
<button
|
||||||
|
class="p-0.5 dark:hover:bg-gray-850 rounded-lg touch-auto"
|
||||||
|
on:click={(e) => {}}
|
||||||
|
>
|
||||||
|
<Plus className=" size-3" strokeWidth="2.5" />
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div slot="content" class="w-full">
|
||||||
|
<slot></slot>
|
||||||
|
</div>
|
||||||
|
</Collapsible>
|
||||||
|
{:else}
|
||||||
|
<slot></slot>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
@@ -72,8 +72,6 @@
|
|||||||
let shiftKey = false;
|
let shiftKey = false;
|
||||||
|
|
||||||
let selectedChatId = null;
|
let selectedChatId = null;
|
||||||
let showPinnedChat = true;
|
|
||||||
|
|
||||||
let showCreateChannel = false;
|
let showCreateChannel = false;
|
||||||
|
|
||||||
// Pagination variables
|
// Pagination variables
|
||||||
@@ -354,7 +352,6 @@
|
|||||||
|
|
||||||
let unsubscribers = [];
|
let unsubscribers = [];
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
showPinnedChat = localStorage?.showPinnedChat ? localStorage.showPinnedChat === 'true' : true;
|
|
||||||
await showSidebar.set(!$mobile ? localStorage.sidebar === 'true' : false);
|
await showSidebar.set(!$mobile ? localStorage.sidebar === 'true' : false);
|
||||||
|
|
||||||
unsubscribers = [
|
unsubscribers = [
|
||||||
@@ -892,6 +889,7 @@
|
|||||||
|
|
||||||
{#if ($models ?? []).length > 0 && ($settings?.pinnedModels ?? []).length > 0}
|
{#if ($models ?? []).length > 0 && ($settings?.pinnedModels ?? []).length > 0}
|
||||||
<Folder
|
<Folder
|
||||||
|
id="sidebar-models"
|
||||||
className="px-2 mt-0.5"
|
className="px-2 mt-0.5"
|
||||||
name={$i18n.t('Models')}
|
name={$i18n.t('Models')}
|
||||||
chevron={false}
|
chevron={false}
|
||||||
@@ -903,6 +901,7 @@
|
|||||||
|
|
||||||
{#if $config?.features?.enable_channels && ($user?.role === 'admin' || $channels.length > 0)}
|
{#if $config?.features?.enable_channels && ($user?.role === 'admin' || $channels.length > 0)}
|
||||||
<Folder
|
<Folder
|
||||||
|
id="sidebar-channels"
|
||||||
className="px-2 mt-0.5"
|
className="px-2 mt-0.5"
|
||||||
name={$i18n.t('Channels')}
|
name={$i18n.t('Channels')}
|
||||||
chevron={false}
|
chevron={false}
|
||||||
@@ -931,6 +930,7 @@
|
|||||||
|
|
||||||
{#if folders}
|
{#if folders}
|
||||||
<Folder
|
<Folder
|
||||||
|
id="sidebar-folders"
|
||||||
className="px-2 mt-0.5"
|
className="px-2 mt-0.5"
|
||||||
name={$i18n.t('Folders')}
|
name={$i18n.t('Folders')}
|
||||||
chevron={false}
|
chevron={false}
|
||||||
@@ -982,6 +982,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<Folder
|
<Folder
|
||||||
|
id="sidebar-chats"
|
||||||
className="px-2 mt-0.5"
|
className="px-2 mt-0.5"
|
||||||
name={$i18n.t('Chats')}
|
name={$i18n.t('Chats')}
|
||||||
chevron={false}
|
chevron={false}
|
||||||
@@ -1051,12 +1052,8 @@
|
|||||||
<div class="mb-1">
|
<div class="mb-1">
|
||||||
<div class="flex flex-col space-y-1 rounded-xl">
|
<div class="flex flex-col space-y-1 rounded-xl">
|
||||||
<Folder
|
<Folder
|
||||||
|
id="sidebar-pinned-chats"
|
||||||
buttonClassName=" text-gray-500"
|
buttonClassName=" text-gray-500"
|
||||||
bind:open={showPinnedChat}
|
|
||||||
on:change={(e) => {
|
|
||||||
localStorage.setItem('showPinnedChat', e.detail);
|
|
||||||
console.log(e.detail);
|
|
||||||
}}
|
|
||||||
on:import={(e) => {
|
on:import={(e) => {
|
||||||
importChatHandler(e.detail, true);
|
importChatHandler(e.detail, true);
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in new issue
Block a user