"...stable_diffusion/test_stable_diffusion_gligen.py" did not exist on "3a9d7d97588a1bbc906d8a17be77cf382492a7b6"
ChatMenu.svelte 4.43 KB
Newer Older
Timothy J. Baek's avatar
Timothy J. Baek committed
1
2
<script lang="ts">
	import { DropdownMenu } from 'bits-ui';
Timothy J. Baek's avatar
Timothy J. Baek committed
3
	import { flyAndScale } from '$lib/utils/transitions';
Timothy J. Baek's avatar
Timothy J. Baek committed
4
5
6
	import { getContext, createEventDispatcher } from 'svelte';

	const dispatch = createEventDispatcher();
Timothy J. Baek's avatar
Timothy J. Baek committed
7
8
9
10

	import Dropdown from '$lib/components/common/Dropdown.svelte';
	import GarbageBin from '$lib/components/icons/GarbageBin.svelte';
	import Pencil from '$lib/components/icons/Pencil.svelte';
11
	import Tooltip from '$lib/components/common/Tooltip.svelte';
Timothy J. Baek's avatar
Timothy J. Baek committed
12
	import Tags from '$lib/components/chat/Tags.svelte';
Timothy J. Baek's avatar
Timothy J. Baek committed
13
	import Share from '$lib/components/icons/Share.svelte';
Timothy J. Baek's avatar
Timothy J. Baek committed
14
	import ArchiveBox from '$lib/components/icons/ArchiveBox.svelte';
Timothy J. Baek's avatar
Timothy J. Baek committed
15
	import DocumentDuplicate from '$lib/components/icons/DocumentDuplicate.svelte';
Timothy J. Baek's avatar
Timothy J. Baek committed
16
17
18
	import Bookmark from '$lib/components/icons/Bookmark.svelte';
	import BookmarkSlash from '$lib/components/icons/BookmarkSlash.svelte';
	import { addTagById, deleteTagById, getTagsById } from '$lib/apis/chats';
Timothy J. Baek's avatar
Timothy J. Baek committed
19

20
21
	const i18n = getContext('i18n');

Timothy J. Baek's avatar
Timothy J. Baek committed
22
	export let shareHandler: Function;
Timothy J. Baek's avatar
Timothy J. Baek committed
23
	export let cloneChatHandler: Function;
Timothy J. Baek's avatar
Timothy J. Baek committed
24
	export let archiveChatHandler: Function;
Timothy J. Baek's avatar
Timothy J. Baek committed
25
26
	export let renameHandler: Function;
	export let deleteHandler: Function;
Timothy J. Baek's avatar
Timothy J. Baek committed
27
	export let onClose: Function;
Timothy J. Baek's avatar
Timothy J. Baek committed
28
29
30
31

	export let chatId = '';

	let show = false;
Timothy J. Baek's avatar
Timothy J. Baek committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
	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();
	}
Timothy J. Baek's avatar
Timothy J. Baek committed
54
55
</script>

Timothy J. Baek's avatar
Timothy J. Baek committed
56
<Dropdown
Timothy J. Baek's avatar
Timothy J. Baek committed
57
	bind:show
Timothy J. Baek's avatar
Timothy J. Baek committed
58
59
60
61
62
63
	on:change={(e) => {
		if (e.detail === false) {
			onClose();
		}
	}}
>
64
	<Tooltip content={$i18n.t('More')}>
65
66
		<slot />
	</Tooltip>
Timothy J. Baek's avatar
Timothy J. Baek committed
67
68
69

	<div slot="content">
		<DropdownMenu.Content
Timothy J. Baek's avatar
Timothy J. Baek committed
70
			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"
Timothy J. Baek's avatar
Timothy J. Baek committed
71
			sideOffset={-2}
Timothy J. Baek's avatar
Timothy J. Baek committed
72
73
			side="bottom"
			align="start"
Timothy J. Baek's avatar
Timothy J. Baek committed
74
			transition={flyAndScale}
Timothy J. Baek's avatar
Timothy J. Baek committed
75
		>
Timothy J. Baek's avatar
Timothy J. Baek committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
			<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>

Timothy J. Baek's avatar
Timothy J. Baek committed
91
			<DropdownMenu.Item
Timothy J. Baek's avatar
Timothy J. Baek committed
92
				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"
Timothy J. Baek's avatar
Timothy J. Baek committed
93
				on:click={() => {
Timothy J. Baek's avatar
Timothy J. Baek committed
94
					renameHandler();
Timothy J. Baek's avatar
Timothy J. Baek committed
95
96
				}}
			>
Timothy J. Baek's avatar
Timothy J. Baek committed
97
98
				<Pencil strokeWidth="2" />
				<div class="flex items-center">{$i18n.t('Rename')}</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
99
100
			</DropdownMenu.Item>

Timothy J. Baek's avatar
Timothy J. Baek committed
101
			<DropdownMenu.Item
Timothy J. Baek's avatar
Timothy J. Baek committed
102
				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"
Timothy J. Baek's avatar
Timothy J. Baek committed
103
				on:click={() => {
Timothy J. Baek's avatar
Timothy J. Baek committed
104
					cloneChatHandler();
Timothy J. Baek's avatar
Timothy J. Baek committed
105
106
				}}
			>
Timothy J. Baek's avatar
Timothy J. Baek committed
107
108
				<DocumentDuplicate strokeWidth="2" />
				<div class="flex items-center">{$i18n.t('Clone')}</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
109
110
			</DropdownMenu.Item>

Timothy J. Baek's avatar
Timothy J. Baek committed
111
			<DropdownMenu.Item
Timothy J. Baek's avatar
Timothy J. Baek committed
112
				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"
Timothy J. Baek's avatar
Timothy J. Baek committed
113
114
115
116
117
118
119
120
				on:click={() => {
					archiveChatHandler();
				}}
			>
				<ArchiveBox strokeWidth="2" />
				<div class="flex items-center">{$i18n.t('Archive')}</div>
			</DropdownMenu.Item>

Timothy J. Baek's avatar
Timothy J. Baek committed
121
122
123
124
125
126
127
128
129
130
			<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>

Timothy J. Baek's avatar
Timothy J. Baek committed
131
			<DropdownMenu.Item
Timothy J. Baek's avatar
Timothy J. Baek committed
132
				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"
Timothy J. Baek's avatar
Timothy J. Baek committed
133
134
135
136
137
				on:click={() => {
					deleteHandler();
				}}
			>
				<GarbageBin strokeWidth="2" />
138
				<div class="flex items-center">{$i18n.t('Delete')}</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
139
			</DropdownMenu.Item>
Timothy J. Baek's avatar
Timothy J. Baek committed
140
141
142
143

			<hr class="border-gray-100 dark:border-gray-800 mt-2.5 mb-1.5" />

			<div class="flex p-1">
Timothy J. Baek's avatar
Timothy J. Baek committed
144
145
146
147
148
149
150
				<Tags
					{chatId}
					on:close={() => {
						show = false;
						onClose();
					}}
				/>
Timothy J. Baek's avatar
Timothy J. Baek committed
151
			</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
152
153
154
		</DropdownMenu.Content>
	</div>
</Dropdown>