Added logic to upload flows and folders at the same place
This commit is contained in:
parent
c3db738a13
commit
49f977911e
1 changed files with 32 additions and 9 deletions
|
|
@ -7,6 +7,7 @@ import {
|
|||
} from "../pages/MainPage/services";
|
||||
import { FoldersStoreType } from "../types/zustand/folders";
|
||||
import useFlowsManagerStore from "./flowsManagerStore";
|
||||
import { uploadFlowsToDatabase } from "../controllers/API";
|
||||
|
||||
export const useFolderStore = create<FoldersStoreType>((set, get) => ({
|
||||
folders: [],
|
||||
|
|
@ -17,18 +18,18 @@ export const useFolderStore = create<FoldersStoreType>((set, get) => ({
|
|||
getFolders().then(
|
||||
(res) => {
|
||||
const foldersWithoutStarterProjects = res.filter(
|
||||
(folder) => folder.name !== STARTER_FOLDER_NAME
|
||||
(folder) => folder.name !== STARTER_FOLDER_NAME,
|
||||
);
|
||||
|
||||
const starterProjects = res.find(
|
||||
(folder) => folder.name === STARTER_FOLDER_NAME
|
||||
(folder) => folder.name === STARTER_FOLDER_NAME,
|
||||
);
|
||||
|
||||
set({ starterProjectId: starterProjects!.id ?? "" });
|
||||
set({ folders: foldersWithoutStarterProjects });
|
||||
|
||||
const myCollectionId = res?.find(
|
||||
(f) => f.name === DEFAULT_FOLDER
|
||||
(f) => f.name === DEFAULT_FOLDER,
|
||||
)?.id;
|
||||
|
||||
set({ myCollectionId });
|
||||
|
|
@ -45,7 +46,7 @@ export const useFolderStore = create<FoldersStoreType>((set, get) => ({
|
|||
set({ folders: [] });
|
||||
get().setLoading(false);
|
||||
reject();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
@ -65,7 +66,7 @@ export const useFolderStore = create<FoldersStoreType>((set, get) => ({
|
|||
},
|
||||
() => {
|
||||
get().setLoadingById(false);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
|
|
@ -100,7 +101,7 @@ export const useFolderStore = create<FoldersStoreType>((set, get) => ({
|
|||
folderIdDragging: "",
|
||||
setFolderIdDragging: (id) => set(() => ({ folderIdDragging: id })),
|
||||
uploadFolder: () => {
|
||||
return new Promise<void>(() => {
|
||||
return new Promise<void>((resolve) => {
|
||||
const input = document.createElement("input");
|
||||
input.type = "file";
|
||||
input.onchange = (event: Event) => {
|
||||
|
|
@ -111,9 +112,31 @@ export const useFolderStore = create<FoldersStoreType>((set, get) => ({
|
|||
const file = (event.target as HTMLInputElement).files![0];
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
uploadFlowsFromFolders(formData).then(() => {
|
||||
get().getFoldersApi(true);
|
||||
});
|
||||
const fileReader = new FileReader();
|
||||
fileReader.readAsText(file, "UTF-8");
|
||||
fileReader.onload = (e) => {
|
||||
if (e && e.target) {
|
||||
const data = JSON.parse(e.target.result as string);
|
||||
if (data.data?.nodes) {
|
||||
uploadFlowsToDatabase(formData).then(() => {
|
||||
useFlowsManagerStore
|
||||
.getState()
|
||||
.refreshFlows()
|
||||
.then(() => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
uploadFlowsFromFolders(formData).then(() => {
|
||||
get()
|
||||
.getFoldersApi(true)
|
||||
.then(() => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
input.click();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue