enh: pinned chats support
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { DropdownMenu } from 'bits-ui';
|
||||
import { flyAndScale } from '$lib/utils/transitions';
|
||||
import { getContext } from 'svelte';
|
||||
import { getContext, createEventDispatcher } from 'svelte';
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
import Dropdown from '$lib/components/common/Dropdown.svelte';
|
||||
import GarbageBin from '$lib/components/icons/GarbageBin.svelte';
|
||||
@@ -11,6 +13,9 @@
|
||||
import Share from '$lib/components/icons/Share.svelte';
|
||||
import ArchiveBox from '$lib/components/icons/ArchiveBox.svelte';
|
||||
import DocumentDuplicate from '$lib/components/icons/DocumentDuplicate.svelte';
|
||||
import Bookmark from '$lib/components/icons/Bookmark.svelte';
|
||||
import BookmarkSlash from '$lib/components/icons/BookmarkSlash.svelte';
|
||||
import { addTagById, deleteTagById, getTagsById } from '$lib/apis/chats';
|
||||
|
||||
const i18n = getContext('i18n');
|
||||
|
||||
@@ -24,6 +29,28 @@
|
||||
export let chatId = '';
|
||||
|
||||
let show = false;
|
||||
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();
|
||||
}
|
||||
</script>
|
||||
|
||||
<Dropdown
|
||||
@@ -46,6 +73,21 @@
|
||||
align="start"
|
||||
transition={flyAndScale}
|
||||
>
|
||||
<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>
|
||||
|
||||
<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={() => {
|
||||
|
||||
Reference in New Issue
Block a user