Wait for user loading before loading Library or Schema

This commit is contained in:
IRBorisov 2024-06-26 21:49:35 +03:00
parent 05811fe0f8
commit 5af65ecb06
3 changed files with 19 additions and 9 deletions

View File

@ -65,7 +65,7 @@ interface LibraryStateProps {
}
export const LibraryState = ({ children }: LibraryStateProps) => {
const { user } = useAuth();
const { user, loading: userLoading } = useAuth();
const { adminMode } = useConceptOptions();
const [items, setItems] = useState<ILibraryItem[]>([]);
@ -175,16 +175,18 @@ export const LibraryState = ({ children }: LibraryStateProps) => {
const reloadTemplates = useCallback(() => {
setTemplates([]);
getTemplates({
setLoading: setLoading,
onError: setLoadingError,
setLoading: setProcessing,
onError: setProcessingError,
showError: true,
onSuccess: newData => setTemplates(newData)
});
}, []);
useEffect(() => {
if (!userLoading) {
reloadItems();
}, [reloadItems]);
}
}, [reloadItems, userLoading]);
useEffect(() => {
reloadTemplates();

View File

@ -4,10 +4,12 @@ import { useCallback, useEffect, useState } from 'react';
import { getOssDetails } from '@/app/backendAPI';
import { type ErrorData } from '@/components/info/InfoError';
import { useAuth } from '@/context/AuthContext';
import { IOperationSchema, IOperationSchemaData } from '@/models/oss';
import { OssLoader } from '@/models/OssLoader';
function useOssDetails({ target }: { target?: string }) {
const { loading: userLoading } = useAuth();
const [schema, setInner] = useState<IOperationSchema | undefined>(undefined);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<ErrorData>(undefined);
@ -44,8 +46,10 @@ function useOssDetails({ target }: { target?: string }) {
);
useEffect(() => {
if (!userLoading) {
reload();
}, [reload]);
}
}, [reload, userLoading]);
return { schema, setSchema, reload, error, setError, loading };
}

View File

@ -4,10 +4,12 @@ import { useCallback, useEffect, useState } from 'react';
import { getRSFormDetails } from '@/app/backendAPI';
import { type ErrorData } from '@/components/info/InfoError';
import { useAuth } from '@/context/AuthContext';
import { IRSForm, IRSFormData } from '@/models/rsform';
import { RSFormLoader } from '@/models/RSFormLoader';
function useRSFormDetails({ target, version }: { target?: string; version?: string }) {
const { loading: userLoading } = useAuth();
const [schema, setInnerSchema] = useState<IRSForm | undefined>(undefined);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<ErrorData>(undefined);
@ -44,8 +46,10 @@ function useRSFormDetails({ target, version }: { target?: string; version?: stri
);
useEffect(() => {
if (!userLoading) {
reload();
}, [reload]);
}
}, [reload, userLoading]);
return { schema, setSchema, reload, error, setError, loading };
}