Wait for user loading before loading Library or Schema
Some checks are pending
Frontend CI / build (18.x) (push) Waiting to run

This commit is contained in:
IRBorisov 2024-06-26 21:50:43 +03:00
parent c2417eb760
commit e12cb3821b
3 changed files with 19 additions and 9 deletions

View File

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

View File

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