This commit is contained in:
@@ -1,19 +1,23 @@
|
||||
import { create } from "zustand";
|
||||
import { scriptsApi } from "../api/scripts.api";
|
||||
|
||||
interface FilePickerState {
|
||||
selectedPaths: Set<string>;
|
||||
expandedFolders: Set<string>;
|
||||
runningScripts: Map<string, { id: number; status: string }>;
|
||||
|
||||
toggleSelection: (path: string) => void;
|
||||
selectAll: (paths: string[]) => void;
|
||||
clearSelection: () => void;
|
||||
toggleFolder: (path: string) => void;
|
||||
getSelectedPaths: () => string[];
|
||||
runScript: (path: string) => Promise<void>;
|
||||
}
|
||||
|
||||
export const useFilePickerStore = create<FilePickerState>((set, get) => ({
|
||||
selectedPaths: new Set(),
|
||||
expandedFolders: new Set(),
|
||||
runningScripts: new Map(),
|
||||
|
||||
toggleSelection: (path: string) => {
|
||||
set((state) => {
|
||||
@@ -54,4 +58,17 @@ export const useFilePickerStore = create<FilePickerState>((set, get) => ({
|
||||
getSelectedPaths: () => {
|
||||
return Array.from(get().selectedPaths);
|
||||
},
|
||||
|
||||
runScript: async (path: string) => {
|
||||
try {
|
||||
const result = await scriptsApi.run(path);
|
||||
set((state) => {
|
||||
const newMap = new Map(state.runningScripts);
|
||||
newMap.set(path, result);
|
||||
return { runningScripts: newMap };
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("Failed to run script:", e);
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user