feat: persist project selection
This commit is contained in:
32
src/App.tsx
32
src/App.tsx
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { open } from "@tauri-apps/plugin-dialog";
|
||||
import { Chat } from "./components/Chat";
|
||||
@@ -8,6 +8,23 @@ function App() {
|
||||
const [projectPath, setProjectPath] = useState<string | null>(null);
|
||||
const [errorMsg, setErrorMsg] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
invoke<string | null>("get_current_project")
|
||||
.then((path) => {
|
||||
if (path) setProjectPath(path);
|
||||
})
|
||||
.catch((e) => console.error(e));
|
||||
}, []);
|
||||
|
||||
async function closeProject() {
|
||||
try {
|
||||
await invoke("close_project");
|
||||
setProjectPath(null);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
async function selectProject() {
|
||||
try {
|
||||
setErrorMsg(null);
|
||||
@@ -57,9 +74,20 @@ function App() {
|
||||
background: "#f0f0f0",
|
||||
borderRadius: "4px",
|
||||
color: "#333",
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<strong>Active Project:</strong> {projectPath}
|
||||
<span>
|
||||
<strong>Active Project:</strong> {projectPath}
|
||||
</span>
|
||||
<button
|
||||
onClick={closeProject}
|
||||
style={{ padding: "5px 10px", fontSize: "0.9em" }}
|
||||
>
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
<hr style={{ margin: "20px 0" }} />
|
||||
<Chat />
|
||||
|
||||
Reference in New Issue
Block a user