open-webui/src/lib/components/layout/Sidebar/ChatMenu.svelte

155 lines
4.4 KiB
Svelte
Raw Normal View History

2024-03-16 08:57:26 +00:00
<script lang="ts">
import { DropdownMenu } from 'bits-ui';
2024-03-24 22:43:03 +00:00
import { flyAndScale } from '$lib/utils/transitions';
2024-07-02 06:08:01 +00:00
import { getContext, createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
2024-03-16 08:57:26 +00:00
import Dropdown from '$lib/components/common/Dropdown.svelte';
import GarbageBin from '$lib/components/icons/GarbageBin.svelte';
import Pencil from '$lib/components/icons/Pencil.svelte';
2024-03-16 09:35:40 +00:00
import Tooltip from '$lib/components/common/Tooltip.svelte';
2024-04-16 21:31:06 +00:00
import Tags from '$lib/components/chat/Tags.svelte';
2024-04-20 19:40:06 +00:00
import Share from '$lib/components/icons/Share.svelte';
2024-05-15 08:22:15 +00:00
import ArchiveBox from '$lib/components/icons/ArchiveBox.svelte';
2024-05-31 17:30:42 +00:00
import DocumentDuplicate from '$lib/components/icons/DocumentDuplicate.svelte';
2024-07-02 06:08:01 +00:00
import Bookmark from '$lib/components/icons/Bookmark.svelte';
import BookmarkSlash from '$lib/components/icons/BookmarkSlash.svelte';
import { addTagById, deleteTagById, getTagsById } from '$lib/apis/chats';
2024-03-16 08:57:26 +00:00
const i18n = getContext('i18n');
2024-04-20 19:40:06 +00:00
export let shareHandler: Function;
2024-05-31 17:30:42 +00:00
export let cloneChatHandler: Function;
2024-05-15 08:22:15 +00:00
export let archiveChatHandler: Function;
2024-03-16 08:57:26 +00:00
export let renameHandler: Function;
export let deleteHandler: Function;
2024-03-16 09:43:51 +00:00
export let onClose: Function;
2024-04-16 21:31:06 +00:00
export let chatId = '';
let show = false;
2024-07-02 06:08:01 +00:00
let pinned = false;
const pinHandler = async () => {
if (pinned) {
await deleteTagById(localStorage.token, chatId, 'pinned');
} else {
await addTagById(localStorage.token, chatId, 'pinned');
}
dispatch('change');
};
const checkPinned = async () => {
pinned = (
await getTagsById(localStorage.token, chatId).catch(async (error) => {
return [];
})
).find((tag) => tag.name === 'pinned');
};
$: if (show) {
checkPinned();
}
2024-03-16 08:57:26 +00:00
</script>
2024-03-16 09:43:51 +00:00
<Dropdown
2024-04-16 21:31:06 +00:00
bind:show
2024-03-16 09:43:51 +00:00
on:change={(e) => {
if (e.detail === false) {
onClose();
}
}}
>
<Tooltip content={$i18n.t('More')}>
2024-03-16 09:35:40 +00:00
<slot />
</Tooltip>
2024-03-16 08:57:26 +00:00
<div slot="content">
<DropdownMenu.Content
2024-05-31 17:30:42 +00:00
class="w-full max-w-[180px] rounded-xl px-1 py-1.5 border border-gray-300/30 dark:border-gray-700/50 z-50 bg-white dark:bg-gray-850 dark:text-white shadow"
2024-03-18 17:49:39 +00:00
sideOffset={-2}
2024-03-16 08:57:26 +00:00
side="bottom"
align="start"
2024-03-24 22:43:03 +00:00
transition={flyAndScale}
2024-03-16 08:57:26 +00:00
>
2024-07-02 06:08:01 +00:00
<DropdownMenu.Item
class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
on:click={() => {
pinHandler();
}}
>
{#if pinned}
<BookmarkSlash strokeWidth="2" />
<div class="flex items-center">{$i18n.t('Unpin')}</div>
{:else}
<Bookmark strokeWidth="2" />
<div class="flex items-center">{$i18n.t('Pin')}</div>
{/if}
</DropdownMenu.Item>
2024-04-20 19:40:06 +00:00
<DropdownMenu.Item
2024-05-31 17:30:42 +00:00
class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
2024-04-20 19:40:06 +00:00
on:click={() => {
2024-05-31 17:30:42 +00:00
renameHandler();
2024-04-20 19:40:06 +00:00
}}
>
2024-05-31 17:30:42 +00:00
<Pencil strokeWidth="2" />
<div class="flex items-center">{$i18n.t('Rename')}</div>
2024-04-20 19:40:06 +00:00
</DropdownMenu.Item>
2024-03-16 08:57:26 +00:00
<DropdownMenu.Item
2024-05-16 02:42:55 +00:00
class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
2024-03-16 08:57:26 +00:00
on:click={() => {
2024-05-31 17:30:42 +00:00
cloneChatHandler();
2024-03-16 08:57:26 +00:00
}}
>
2024-05-31 17:30:42 +00:00
<DocumentDuplicate strokeWidth="2" />
<div class="flex items-center">{$i18n.t('Clone')}</div>
2024-03-16 08:57:26 +00:00
</DropdownMenu.Item>
2024-05-15 08:22:15 +00:00
<DropdownMenu.Item
2024-05-16 02:42:55 +00:00
class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
2024-05-15 08:22:15 +00:00
on:click={() => {
archiveChatHandler();
}}
>
<ArchiveBox strokeWidth="2" />
<div class="flex items-center">{$i18n.t('Archive')}</div>
</DropdownMenu.Item>
2024-05-31 17:30:42 +00:00
<DropdownMenu.Item
class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
on:click={() => {
shareHandler();
}}
>
<Share />
<div class="flex items-center">{$i18n.t('Share')}</div>
</DropdownMenu.Item>
2024-03-16 08:57:26 +00:00
<DropdownMenu.Item
2024-05-16 02:42:55 +00:00
class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
2024-03-16 08:57:26 +00:00
on:click={() => {
deleteHandler();
}}
>
<GarbageBin strokeWidth="2" />
<div class="flex items-center">{$i18n.t('Delete')}</div>
2024-03-16 08:57:26 +00:00
</DropdownMenu.Item>
2024-04-16 21:31:06 +00:00
<hr class="border-gray-100 dark:border-gray-800 mt-2.5 mb-1.5" />
<div class="flex p-1">
2024-05-04 00:27:48 +00:00
<Tags
{chatId}
on:close={() => {
show = false;
onClose();
}}
/>
2024-04-16 21:31:06 +00:00
</div>
2024-03-16 08:57:26 +00:00
</DropdownMenu.Content>
</div>
</Dropdown>