Timothy J. Baek 6 月之前
父節點
當前提交
9658c2559a

+ 4 - 12
src/lib/components/chat/Tags.svelte

@@ -36,6 +36,7 @@
 		await updateChatById(localStorage.token, chatId, {
 		await updateChatById(localStorage.token, chatId, {
 			tags: tags
 			tags: tags
 		});
 		});
+
 		_tags.set(await getAllChatTags(localStorage.token));
 		_tags.set(await getAllChatTags(localStorage.token));
 	};
 	};
 
 
@@ -47,18 +48,9 @@
 		});
 		});
 
 
 		await _tags.set(await getAllChatTags(localStorage.token));
 		await _tags.set(await getAllChatTags(localStorage.token));
-		if ($_tags.map((t) => t.name).includes(tagName)) {
-			await chats.set(await getChatListByTagName(localStorage.token, tagName));
-
-			if ($chats.find((chat) => chat.id === chatId)) {
-				dispatch('close');
-			}
-		} else {
-			// if the tag we deleted is no longer a valid tag, return to main chat list view
-			currentChatPage.set(1);
-			await chats.set(await getChatList(localStorage.token, $currentChatPage));
-			await scrollPaginationEnabled.set(true);
-		}
+		dispatch('delete', {
+			name: tagName
+		});
 	};
 	};
 
 
 	onMount(async () => {
 	onMount(async () => {

+ 23 - 0
src/lib/components/layout/Sidebar.svelte

@@ -47,6 +47,7 @@
 	import Loader from '../common/Loader.svelte';
 	import Loader from '../common/Loader.svelte';
 	import FilesOverlay from '../chat/MessageInput/FilesOverlay.svelte';
 	import FilesOverlay from '../chat/MessageInput/FilesOverlay.svelte';
 	import AddFilesPlaceholder from '../AddFilesPlaceholder.svelte';
 	import AddFilesPlaceholder from '../AddFilesPlaceholder.svelte';
+	import { select } from 'd3-selection';
 
 
 	const BREAKPOINT = 768;
 	const BREAKPOINT = 768;
 
 
@@ -167,6 +168,20 @@
 		}
 		}
 	};
 	};
 
 
+	const tagEventHandler = async (type, tagName, chatId) => {
+		console.log(type, tagName, chatId);
+		if (type === 'delete') {
+			if (selectedTagName === tagName) {
+				if ($tags.map((t) => t.name).includes(tagName)) {
+					await chats.set(await getChatListByTagName(localStorage.token, tagName));
+				} else {
+					selectedTagName = null;
+					await initChatList();
+				}
+			}
+		}
+	};
+
 	let dragged = false;
 	let dragged = false;
 
 
 	const onDragOver = (e) => {
 	const onDragOver = (e) => {
@@ -561,6 +576,10 @@
 										showDeleteConfirm = true;
 										showDeleteConfirm = true;
 									}
 									}
 								}}
 								}}
+								on:tag={(e) => {
+									const { type, name } = e.detail;
+									tagEventHandler(type, name, chat.id);
+								}}
 							/>
 							/>
 						{/each}
 						{/each}
 					</div>
 					</div>
@@ -616,6 +635,10 @@
 									showDeleteConfirm = true;
 									showDeleteConfirm = true;
 								}
 								}
 							}}
 							}}
+							on:tag={(e) => {
+								const { type, name } = e.detail;
+								tagEventHandler(type, name, chat.id);
+							}}
 						/>
 						/>
 					{/each}
 					{/each}
 
 

+ 3 - 0
src/lib/components/layout/Sidebar/ChatItem.svelte

@@ -259,6 +259,9 @@
 					on:change={async () => {
 					on:change={async () => {
 						await pinnedChats.set(await getPinnedChatList(localStorage.token));
 						await pinnedChats.set(await getPinnedChatList(localStorage.token));
 					}}
 					}}
+					on:tag={(e) => {
+						dispatch('tag', e.detail);
+					}}
 				>
 				>
 					<button
 					<button
 						aria-label="Chat Menu"
 						aria-label="Chat Menu"

+ 7 - 0
src/lib/components/layout/Sidebar/ChatMenu.svelte

@@ -141,6 +141,13 @@
 			<div class="flex p-1">
 			<div class="flex p-1">
 				<Tags
 				<Tags
 					{chatId}
 					{chatId}
+					on:delete={(e) => {
+						dispatch('tag', {
+							type: 'delete',
+							name: e.detail.name
+						});
+						show = false;
+					}}
 					on:close={() => {
 					on:close={() => {
 						show = false;
 						show = false;
 						onClose();
 						onClose();