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";
|
} from "../pages/MainPage/services";
|
||||||
import { FoldersStoreType } from "../types/zustand/folders";
|
import { FoldersStoreType } from "../types/zustand/folders";
|
||||||
import useFlowsManagerStore from "./flowsManagerStore";
|
import useFlowsManagerStore from "./flowsManagerStore";
|
||||||
|
import { uploadFlowsToDatabase } from "../controllers/API";
|
||||||
|
|
||||||
export const useFolderStore = create<FoldersStoreType>((set, get) => ({
|
export const useFolderStore = create<FoldersStoreType>((set, get) => ({
|
||||||
folders: [],
|
folders: [],
|
||||||
|
|
@ -17,18 +18,18 @@ export const useFolderStore = create<FoldersStoreType>((set, get) => ({
|
||||||
getFolders().then(
|
getFolders().then(
|
||||||
(res) => {
|
(res) => {
|
||||||
const foldersWithoutStarterProjects = res.filter(
|
const foldersWithoutStarterProjects = res.filter(
|
||||||
(folder) => folder.name !== STARTER_FOLDER_NAME
|
(folder) => folder.name !== STARTER_FOLDER_NAME,
|
||||||
);
|
);
|
||||||
|
|
||||||
const starterProjects = res.find(
|
const starterProjects = res.find(
|
||||||
(folder) => folder.name === STARTER_FOLDER_NAME
|
(folder) => folder.name === STARTER_FOLDER_NAME,
|
||||||
);
|
);
|
||||||
|
|
||||||
set({ starterProjectId: starterProjects!.id ?? "" });
|
set({ starterProjectId: starterProjects!.id ?? "" });
|
||||||
set({ folders: foldersWithoutStarterProjects });
|
set({ folders: foldersWithoutStarterProjects });
|
||||||
|
|
||||||
const myCollectionId = res?.find(
|
const myCollectionId = res?.find(
|
||||||
(f) => f.name === DEFAULT_FOLDER
|
(f) => f.name === DEFAULT_FOLDER,
|
||||||
)?.id;
|
)?.id;
|
||||||
|
|
||||||
set({ myCollectionId });
|
set({ myCollectionId });
|
||||||
|
|
@ -45,7 +46,7 @@ export const useFolderStore = create<FoldersStoreType>((set, get) => ({
|
||||||
set({ folders: [] });
|
set({ folders: [] });
|
||||||
get().setLoading(false);
|
get().setLoading(false);
|
||||||
reject();
|
reject();
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -65,7 +66,7 @@ export const useFolderStore = create<FoldersStoreType>((set, get) => ({
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
get().setLoadingById(false);
|
get().setLoadingById(false);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -100,7 +101,7 @@ export const useFolderStore = create<FoldersStoreType>((set, get) => ({
|
||||||
folderIdDragging: "",
|
folderIdDragging: "",
|
||||||
setFolderIdDragging: (id) => set(() => ({ folderIdDragging: id })),
|
setFolderIdDragging: (id) => set(() => ({ folderIdDragging: id })),
|
||||||
uploadFolder: () => {
|
uploadFolder: () => {
|
||||||
return new Promise<void>(() => {
|
return new Promise<void>((resolve) => {
|
||||||
const input = document.createElement("input");
|
const input = document.createElement("input");
|
||||||
input.type = "file";
|
input.type = "file";
|
||||||
input.onchange = (event: Event) => {
|
input.onchange = (event: Event) => {
|
||||||
|
|
@ -111,9 +112,31 @@ export const useFolderStore = create<FoldersStoreType>((set, get) => ({
|
||||||
const file = (event.target as HTMLInputElement).files![0];
|
const file = (event.target as HTMLInputElement).files![0];
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("file", file);
|
formData.append("file", file);
|
||||||
uploadFlowsFromFolders(formData).then(() => {
|
const fileReader = new FileReader();
|
||||||
get().getFoldersApi(true);
|
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();
|
input.click();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue