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 { listen } from "@tauri-apps/api/event";
import { ask } from "@tauri-apps/plugin-dialog";
import { useEffect, useRef, useState } from "react";
import Markdown from "react-markdown";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
@@ -163,25 +164,21 @@ export function Chat({ projectPath, onCloseProject }: ChatProps) {
}
};
const clearSession = () => {
// Store current state in case we need to debug
console.log("clearSession called, messages count:", messages.length);
const confirmed = window.confirm(
const clearSession = async () => {
const confirmed = await ask(
"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 === true) {
console.log("Clearing session...");
if (confirmed) {
setMessages([]);
setStreamingContent("");
setLoading(false);
// TODO: Add backend call to clear context when implemented
// invoke("clear_session").catch(console.error);
} else {
console.log("User cancelled, keeping messages");
}
};