Fix: Bring back loading to avoid white page error (#1434)

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-02-15 18:33:54 -03:00 • committed by GitHub
commit 8e1ff4b3cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 10 additions and 11 deletions

View file

@ -34,6 +34,7 @@ export default function App() {
const setSuccessOpen = useAlertStore((state) => state.setSuccessOpen); const setSuccessOpen = useAlertStore((state) => state.setSuccessOpen);
const loading = useAlertStore((state) => state.loading); const loading = useAlertStore((state) => state.loading);
const [fetchError, setFetchError] = useState(false); const [fetchError, setFetchError] = useState(false);
const isLoading = useFlowsManagerStore((state) => state.isLoading);
// Initialize state variable for the list of alerts // Initialize state variable for the list of alerts
const [alertsList, setAlertsList] = useState< const [alertsList, setAlertsList] = useState<
@ -170,7 +171,7 @@ export default function App() {
description={FETCH_ERROR_DESCRIPION} description={FETCH_ERROR_DESCRIPION}
message={FETCH_ERROR_MESSAGE} message={FETCH_ERROR_MESSAGE}
></FetchErrorComponent> ></FetchErrorComponent>
) : loading ? ( ) : isLoading ? (
<div className="loading-page-panel"> <div className="loading-page-panel">
<LoadingComponent remSize={50} /> <LoadingComponent remSize={50} />
</div> </div>

View file

@ -94,12 +94,6 @@ export default function ComponentsComponent({
setPageSize(10); setPageSize(10);
} }
useEffect(() => {
setTimeout(() => {
setLoadingScreen(false);
}, 600);
}, []);
return ( return (
<CardsWrapComponent <CardsWrapComponent
onFileDrop={onFileDrop} onFileDrop={onFileDrop}
@ -107,7 +101,7 @@ export default function ComponentsComponent({
> >
<div className="flex h-full w-full flex-col justify-between"> <div className="flex h-full w-full flex-col justify-between">
<div className="flex w-full flex-col gap-4"> <div className="flex w-full flex-col gap-4">
{!loadingScreen && data.length === 0 ? ( {!isLoading && data.length === 0 ? (
<div className="mt-6 flex w-full items-center justify-center text-center"> <div className="mt-6 flex w-full items-center justify-center text-center">
<div className="flex-max-width h-full flex-col"> <div className="flex-max-width h-full flex-col">
<div className="flex w-full flex-col gap-4"> <div className="flex w-full flex-col gap-4">
@ -136,7 +130,7 @@ export default function ComponentsComponent({
</div> </div>
) : ( ) : (
<div className="grid w-full gap-4 md:grid-cols-2 lg:grid-cols-2"> <div className="grid w-full gap-4 md:grid-cols-2 lg:grid-cols-2">
{loadingScreen === false && data?.length > 0 ? ( {isLoading === false && data?.length > 0 ? (
data?.map((item, idx) => ( data?.map((item, idx) => (
<CollectionCardComponent <CollectionCardComponent
onDelete={() => { onDelete={() => {
@ -185,7 +179,7 @@ export default function ComponentsComponent({
</div> </div>
)} )}
</div> </div>
{!loadingScreen && data.length > 0 && ( {!isLoading && data.length > 0 && (
<div className="relative py-6"> <div className="relative py-6">
<PaginatorComponent <PaginatorComponent
storeComponent={true} storeComponent={true}

View file

@ -62,10 +62,10 @@ const useFlowsManagerStore = create<FlowsManagerStoreType>((set, get) => ({
if (dbData) { if (dbData) {
const { data, flows } = processFlows(dbData, false); const { data, flows } = processFlows(dbData, false);
get().setFlows(flows); get().setFlows(flows);
set({ isLoading: false });
useTypesStore.setState((state) => ({ useTypesStore.setState((state) => ({
data: { ...state.data, ["saved_components"]: data }, data: { ...state.data, ["saved_components"]: data },
})); }));
set({ isLoading: false });
resolve(); resolve();
} }
}) })

View file

@ -4,6 +4,7 @@ import { APIDataType } from "../types/api";
import { TypesStoreType } from "../types/zustand/types"; import { TypesStoreType } from "../types/zustand/types";
import { templatesGenerator, typesGenerator } from "../utils/reactflowUtils"; import { templatesGenerator, typesGenerator } from "../utils/reactflowUtils";
import useAlertStore from "./alertStore"; import useAlertStore from "./alertStore";
import useFlowsManagerStore from "./flowsManagerStore";
export const useTypesStore = create<TypesStoreType>((set, get) => ({ export const useTypesStore = create<TypesStoreType>((set, get) => ({
types: {}, types: {},
@ -11,6 +12,8 @@ export const useTypesStore = create<TypesStoreType>((set, get) => ({
data: {}, data: {},
getTypes: () => { getTypes: () => {
return new Promise<void>(async (resolve, reject) => { return new Promise<void>(async (resolve, reject) => {
const setLoading = useFlowsManagerStore.getState().setIsLoading;
setLoading(true);
getAll() getAll()
.then((response) => { .then((response) => {
const data = response.data; const data = response.data;
@ -20,6 +23,7 @@ export const useTypesStore = create<TypesStoreType>((set, get) => ({
data: { ...old.data, ...data }, data: { ...old.data, ...data },
templates: templatesGenerator(data), templates: templatesGenerator(data),
})); }));
setLoading(false)
resolve(); resolve();
}) })
.catch((error) => { .catch((error) => {