From 26952ff6c8628f0ecdb99b7e47312c7ebe55d1b3 Mon Sep 17 00:00:00 2001
From: TamHC <79314879+TamHC@users.noreply.github.com>
Date: Tue, 24 Jun 2025 17:35:41 +0800
Subject: [PATCH] Add files via upload
---
src/components/ChatWindow.tsx | 4 ++
src/components/EmptyChat.tsx | 10 ++--
src/components/IncognitoToggle.tsx | 84 ++++++++++++++++++++++++++++++
src/components/Navbar.tsx | 2 +
4 files changed, 97 insertions(+), 3 deletions(-)
create mode 100644 src/components/IncognitoToggle.tsx
diff --git a/src/components/ChatWindow.tsx b/src/components/ChatWindow.tsx
index 93c8a0c..ea29b1e 100644
--- a/src/components/ChatWindow.tsx
+++ b/src/components/ChatWindow.tsx
@@ -334,6 +334,9 @@ const ChatWindow = ({ id }: { id?: string }) => {
return;
}
+ // 檢查無痕模式
+ const isIncognito = localStorage.getItem('incognitoMode') === 'true';
+
setLoading(true);
setMessageAppeared(false);
@@ -481,6 +484,7 @@ const ChatWindow = ({ id }: { id?: string }) => {
provider: embeddingModelProvider.provider,
},
systemInstructions: localStorage.getItem('systemInstructions'),
+ isIncognito: isIncognito,
}),
});
diff --git a/src/components/EmptyChat.tsx b/src/components/EmptyChat.tsx
index 42e5a09..28b7b91 100644
--- a/src/components/EmptyChat.tsx
+++ b/src/components/EmptyChat.tsx
@@ -4,6 +4,7 @@ import { File } from './ChatWindow';
import Link from 'next/link';
import WeatherWidget from './WeatherWidget';
import NewsArticleWidget from './NewsArticleWidget';
+import IncognitoToggle from './IncognitoToggle';
const EmptyChat = ({
sendMessage,
@@ -35,9 +36,12 @@ const EmptyChat = ({
-
- Research begins here.
-
+
+
+ Research begins here.
+
+
+
{
+ const [isIncognito, setIsIncognito] = useState(false);
+ const searchParams = useSearchParams();
+ const router = useRouter();
+ const pathname = usePathname();
+
+ // 初始化無痕模式狀態
+ useEffect(() => {
+ // 檢查URL參數
+ const incognitoParam = searchParams.get('incognito');
+ if (incognitoParam !== null) {
+ const incognitoValue = incognitoParam === 'true';
+ setIsIncognito(incognitoValue);
+ localStorage.setItem('incognitoMode', incognitoValue.toString());
+ return;
+ }
+
+ // 檢查localStorage
+ const savedIncognito = localStorage.getItem('incognitoMode');
+ if (savedIncognito !== null) {
+ setIsIncognito(savedIncognito === 'true');
+ }
+ }, [searchParams]);
+
+ const toggleIncognito = () => {
+ const newIncognitoState = !isIncognito;
+ setIsIncognito(newIncognitoState);
+
+ // 保存到localStorage
+ localStorage.setItem('incognitoMode', newIncognitoState.toString());
+
+ // 更新URL參數
+ const params = new URLSearchParams(searchParams.toString());
+ if (newIncognitoState) {
+ params.set('incognito', 'true');
+ } else {
+ params.delete('incognito');
+ }
+
+ const newUrl = params.toString() ? `${pathname}?${params.toString()}` : pathname;
+ router.replace(newUrl, { scroll: false });
+
+ // 觸發自定義事件,通知其他組件無痕模式狀態變化
+ window.dispatchEvent(new CustomEvent('incognitoModeChanged', {
+ detail: { isIncognito: newIncognitoState }
+ }));
+ };
+
+ return (
+
+ );
+};
+
+export default IncognitoToggle;
diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx
index e406ade..d24b3fc 100644
--- a/src/components/Navbar.tsx
+++ b/src/components/Navbar.tsx
@@ -10,6 +10,7 @@ import {
Transition,
} from '@headlessui/react';
import jsPDF from 'jspdf';
+import IncognitoToggle from './IncognitoToggle';
const downloadFile = (filename: string, content: string, type: string) => {
const blob = new Blob([content], { type });
@@ -173,6 +174,7 @@ const Navbar = ({
{title}