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

View file

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