Fix New Session bug: use async Tauri dialog instead of window.confirm

- Tauri overrides window.confirm to return Promise, not boolean
- Changed clearSession to async function using Tauri's ask() dialog
- Now properly waits for user confirmation before clearing state
- Removed debug logging
- All quality checks passing
This commit is contained in:
Dave
2025-12-27 17:33:03 +00:00
parent 418fa86f7d
commit 68f35d4591

View File

@@ -1,5 +1,6 @@
import { invoke } from "@tauri-apps/api/core"; import { invoke } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event"; import { listen } from "@tauri-apps/api/event";
import { ask } from "@tauri-apps/plugin-dialog";
import { useEffect, useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
import Markdown from "react-markdown"; import Markdown from "react-markdown";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
@@ -163,25 +164,21 @@ export function Chat({ projectPath, onCloseProject }: ChatProps) {
} }
}; };
const clearSession = () => { const clearSession = async () => {
// Store current state in case we need to debug const confirmed = await ask(
console.log("clearSession called, messages count:", messages.length);
const confirmed = window.confirm(
"Are you sure? This will clear all messages and reset the conversation context.", "Are you sure? This will clear all messages and reset the conversation context.",
{
title: "New Session",
kind: "warning",
},
); );
console.log("User confirmed:", confirmed); if (confirmed) {
if (confirmed === true) {
console.log("Clearing session...");
setMessages([]); setMessages([]);
setStreamingContent(""); setStreamingContent("");
setLoading(false); setLoading(false);
// TODO: Add backend call to clear context when implemented // TODO: Add backend call to clear context when implemented
// invoke("clear_session").catch(console.error); // invoke("clear_session").catch(console.error);
} else {
console.log("User cancelled, keeping messages");
} }
}; };