Explorar o código

refac: show chat menu in temp chat

Timothy J. Baek hai 6 meses
pai
achega
854024cdf8

+ 11 - 1
src/lib/components/chat/Chat.svelte

@@ -1935,7 +1935,17 @@
 		{/if}
 
 		<Navbar
-			{chat}
+			chat={{
+				id: $chatId,
+				chat: {
+					title: $chatTitle,
+					models: selectedModels,
+					system: $settings.system ?? undefined,
+					params: params,
+					history: history,
+					timestamp: Date.now()
+				}
+			}}
 			title={$chatTitle}
 			bind:selectedModels
 			shareEnabled={!!history.currentId}

+ 3 - 2
src/lib/components/layout/Navbar.svelte

@@ -10,6 +10,7 @@
 		showArchivedChats,
 		showControls,
 		showSidebar,
+		temporaryChatEnabled,
 		user
 	} from '$lib/stores';
 
@@ -23,6 +24,7 @@
 	import MenuLines from '../icons/MenuLines.svelte';
 	import AdjustmentsHorizontal from '../icons/AdjustmentsHorizontal.svelte';
 	import Map from '../icons/Map.svelte';
+	import { stringify } from 'postcss';
 
 	const i18n = getContext('i18n');
 
@@ -74,8 +76,7 @@
 
 			<div class="self-start flex flex-none items-center text-gray-600 dark:text-gray-400">
 				<!-- <div class="md:hidden flex self-center w-[1px] h-5 mx-2 bg-gray-300 dark:bg-stone-700" /> -->
-
-				{#if shareEnabled && chat && chat.id}
+				{#if shareEnabled && chat && (chat.id || $temporaryChatEnabled)}
 					<Menu
 						{chat}
 						{shareEnabled}

+ 41 - 35
src/lib/components/layout/Navbar/Menu.svelte

@@ -9,7 +9,13 @@
 	import { downloadChatAsPDF } from '$lib/apis/utils';
 	import { copyToClipboard, createMessagesList } from '$lib/utils';
 
-	import { showOverview, showControls, showArtifacts, mobile } from '$lib/stores';
+	import {
+		showOverview,
+		showControls,
+		showArtifacts,
+		mobile,
+		temporaryChatEnabled
+	} from '$lib/stores';
 	import { flyAndScale } from '$lib/utils/transitions';
 
 	import Dropdown from '$lib/components/common/Dropdown.svelte';
@@ -31,9 +37,8 @@
 	export let onClose: Function = () => {};
 
 	const getChatAsText = async () => {
-		const _chat = chat.chat;
-
-		const messages = createMessagesList(_chat.history, _chat.history.currentId);
+		const history = chat.chat.history;
+		const messages = createMessagesList(history, history.currentId);
 		const chatText = messages.reduce((a, message, i, arr) => {
 			return `${a}### ${message.role.toUpperCase()}\n${message.content}\n\n`;
 		}, '');
@@ -52,12 +57,9 @@
 	};
 
 	const downloadPdf = async () => {
-		const _chat = chat.chat;
-		const messages = createMessagesList(_chat.history, _chat.history.currentId);
-
-		console.log('download', chat);
-
-		const blob = await downloadChatAsPDF(_chat.title, messages);
+		const history = chat.chat.history;
+		const messages = createMessagesList(history, history.currentId);
+		const blob = await downloadChatAsPDF(chat.chat.title, messages);
 
 		// Create a URL for the blob
 		const url = window.URL.createObjectURL(blob);
@@ -65,7 +67,7 @@
 		// Create a link element to trigger the download
 		const a = document.createElement('a');
 		a.href = url;
-		a.download = `chat-${_chat.title}.pdf`;
+		a.download = `chat-${chat.chat.title}.pdf`;
 
 		// Append the link to the body and click it programmatically
 		document.body.appendChild(a);
@@ -189,27 +191,29 @@
 				<div class="flex items-center">{$i18n.t('Copy')}</div>
 			</DropdownMenu.Item>
 
-			<DropdownMenu.Item
-				class="flex gap-2 items-center px-3 py-2 text-sm  cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
-				id="chat-share-button"
-				on:click={() => {
-					shareHandler();
-				}}
-			>
-				<svg
-					xmlns="http://www.w3.org/2000/svg"
-					viewBox="0 0 24 24"
-					fill="currentColor"
-					class="size-4"
+			{#if !$temporaryChatEnabled}
+				<DropdownMenu.Item
+					class="flex gap-2 items-center px-3 py-2 text-sm  cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
+					id="chat-share-button"
+					on:click={() => {
+						shareHandler();
+					}}
 				>
-					<path
-						fill-rule="evenodd"
-						d="M15.75 4.5a3 3 0 1 1 .825 2.066l-8.421 4.679a3.002 3.002 0 0 1 0 1.51l8.421 4.679a3 3 0 1 1-.729 1.31l-8.421-4.678a3 3 0 1 1 0-4.132l8.421-4.679a3 3 0 0 1-.096-.755Z"
-						clip-rule="evenodd"
-					/>
-				</svg>
-				<div class="flex items-center">{$i18n.t('Share')}</div>
-			</DropdownMenu.Item>
+					<svg
+						xmlns="http://www.w3.org/2000/svg"
+						viewBox="0 0 24 24"
+						fill="currentColor"
+						class="size-4"
+					>
+						<path
+							fill-rule="evenodd"
+							d="M15.75 4.5a3 3 0 1 1 .825 2.066l-8.421 4.679a3.002 3.002 0 0 1 0 1.51l8.421 4.679a3 3 0 1 1-.729 1.31l-8.421-4.678a3 3 0 1 1 0-4.132l8.421-4.679a3 3 0 0 1-.096-.755Z"
+							clip-rule="evenodd"
+						/>
+					</svg>
+					<div class="flex items-center">{$i18n.t('Share')}</div>
+				</DropdownMenu.Item>
+			{/if}
 
 			<DropdownMenu.Sub>
 				<DropdownMenu.SubTrigger
@@ -265,11 +269,13 @@
 				</DropdownMenu.SubContent>
 			</DropdownMenu.Sub>
 
-			<hr class="border-gray-100 dark:border-gray-800 mt-2.5 mb-1.5" />
+			{#if !$temporaryChatEnabled}
+				<hr class="border-gray-100 dark:border-gray-800 mt-2.5 mb-1.5" />
 
-			<div class="flex p-1">
-				<Tags chatId={chat.id} />
-			</div>
+				<div class="flex p-1">
+					<Tags chatId={chat.id} />
+				</div>
+			{/if}
 		</DropdownMenu.Content>
 	</div>
 </Dropdown>