♻️ (foldersStore.tsx): remove redundant loadingById state and setLoadingById function

🐛 (foldersStore.tsx): fix fallback to getFoldersApi on getFolderById failure
This commit is contained in:
cristhianzl 2024-06-13 16:08:58 -03:00
commit 7313e5807b
2 changed files with 6 additions and 11 deletions

View file

@ -17,18 +17,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 +45,7 @@ export const useFolderStore = create<FoldersStoreType>((set, get) => ({
set({ folders: [] });
get().setLoading(false);
reject(error);
}
},
);
}
});
@ -54,24 +54,21 @@ export const useFolderStore = create<FoldersStoreType>((set, get) => ({
loading: false,
setLoading: (loading) => set(() => ({ loading: loading })),
getFolderById: (id) => {
get().setLoadingById(true);
if (id) {
getFolderById(id).then(
(res) => {
const setAllFlows = useFlowsManagerStore.getState().setAllFlows;
setAllFlows(res.flows);
set({ selectedFolder: res });
get().setLoadingById(false);
},
() => {
get().setLoadingById(false);
}
get().getFoldersApi(true);
},
);
}
},
selectedFolder: null,
loadingById: false,
setLoadingById: (loading) => set(() => ({ loadingById: loading })),
getMyCollectionFolder: () => {
const folders = get().folders;
const myCollectionId = folders?.find((f) => f.name === DEFAULT_FOLDER)?.id;

View file

@ -8,8 +8,6 @@ export type FoldersStoreType = {
setLoading: (loading: boolean) => void;
selectedFolder: FolderType | null;
getFolderById: (id: string) => void;
loadingById: boolean;
setLoadingById: (loading: boolean) => void;
getMyCollectionFolder: () => void;
myCollectionFlows: FolderType | null;
myCollectionId: string | null;