-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuseProjectActions.ts
More file actions
45 lines (38 loc) · 1.23 KB
/
useProjectActions.ts
File metadata and controls
45 lines (38 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { api, type WorkshopProject } from "@/lib/tauri";
import { useWorkshopDialogsStore } from "@/stores";
import { useTestProjects } from "./useTestProject";
export function useProjectActions(project: WorkshopProject | undefined) {
const testProjects = useTestProjects();
const openPackDialog = useWorkshopDialogsStore((s) => s.openPackDialog);
const openDeleteDialog = useWorkshopDialogsStore((s) => s.openDeleteDialog);
function handleTestProject() {
if (!project) return;
testProjects.mutate(
{ projects: [{ path: project.path, displayName: project.displayName }] },
{ onError: (err) => console.error("Failed to test project:", err.message) },
);
}
function handleOpenPackDialog() {
if (!project) return;
openPackDialog(project);
}
function handleOpenDeleteDialog() {
if (!project) return;
openDeleteDialog(project);
}
async function handleOpenLocation() {
if (!project) return;
try {
await api.revealInExplorer(project.path);
} catch (error) {
console.error("Failed to open location:", error);
}
}
return {
isTesting: testProjects.isPending,
handleTestProject,
handleOpenPackDialog,
handleOpenDeleteDialog,
handleOpenLocation,
};
}