From 122bf4fcc15306c0803611255512fd5cafcc0d8e Mon Sep 17 00:00:00 2001 From: IRBorisov <8611739+IRBorisov@users.noreply.github.com> Date: Sun, 23 Jun 2024 19:43:22 +0300 Subject: [PATCH] Fix context loading semantics Loading is a flag for data loading on context create Processing is a flag for waiting for response after function call --- rsconcept/frontend/src/context/LibraryContext.tsx | 2 +- rsconcept/frontend/src/context/UserProfileContext.tsx | 2 +- .../src/dialogs/DlgEditWordForms/DlgEditWordForms.tsx | 10 +++++----- rsconcept/frontend/src/hooks/useCheckExpression.ts | 6 +++--- rsconcept/frontend/src/hooks/useConceptText.ts | 10 +++++----- rsconcept/frontend/src/hooks/useOssDetails.ts | 2 +- rsconcept/frontend/src/hooks/useRSFormDetails.ts | 2 +- rsconcept/frontend/src/hooks/useResolveText.ts | 6 +++--- .../EditorRSExpression/EditorRSExpression.tsx | 2 +- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/rsconcept/frontend/src/context/LibraryContext.tsx b/rsconcept/frontend/src/context/LibraryContext.tsx index 16e2c11d..ebb84e78 100644 --- a/rsconcept/frontend/src/context/LibraryContext.tsx +++ b/rsconcept/frontend/src/context/LibraryContext.tsx @@ -70,7 +70,7 @@ export const LibraryState = ({ children }: LibraryStateProps) => { const [items, setItems] = useState([]); const [templates, setTemplates] = useState([]); - const [loading, setLoading] = useState(false); + const [loading, setLoading] = useState(true); const [processing, setProcessing] = useState(false); const [loadingError, setLoadingError] = useState(undefined); const [processingError, setProcessingError] = useState(undefined); diff --git a/rsconcept/frontend/src/context/UserProfileContext.tsx b/rsconcept/frontend/src/context/UserProfileContext.tsx index 7185a553..7c39352e 100644 --- a/rsconcept/frontend/src/context/UserProfileContext.tsx +++ b/rsconcept/frontend/src/context/UserProfileContext.tsx @@ -36,7 +36,7 @@ interface UserProfileStateProps { export const UserProfileState = ({ children }: UserProfileStateProps) => { const { users } = useUsers(); const [user, setUser] = useState(undefined); - const [loading, setLoading] = useState(false); + const [loading, setLoading] = useState(true); const [processing, setProcessing] = useState(false); const [error, setError] = useState(undefined); const [errorProcessing, setErrorProcessing] = useState(undefined); diff --git a/rsconcept/frontend/src/dialogs/DlgEditWordForms/DlgEditWordForms.tsx b/rsconcept/frontend/src/dialogs/DlgEditWordForms/DlgEditWordForms.tsx index e1557d99..e0b182b4 100644 --- a/rsconcept/frontend/src/dialogs/DlgEditWordForms/DlgEditWordForms.tsx +++ b/rsconcept/frontend/src/dialogs/DlgEditWordForms/DlgEditWordForms.tsx @@ -165,14 +165,14 @@ function DlgEditWordForms({ hideWindow, target, onSave }: DlgEditWordFormsProps) noHover title='Определить граммемы' icon={} - disabled={textProcessor.loading || !inputText} + disabled={textProcessor.processing || !inputText} onClick={handleParse} /> } - disabled={textProcessor.loading || inputGrams.length == 0} + disabled={textProcessor.processing || inputGrams.length == 0} onClick={handleInflect} /> @@ -190,14 +190,14 @@ function DlgEditWordForms({ hideWindow, target, onSave }: DlgEditWordFormsProps) noHover title='Внести словоформу' icon={} - disabled={textProcessor.loading || !inputText || inputGrams.length == 0} + disabled={textProcessor.processing || !inputText || inputGrams.length == 0} onClick={handleAddForm} /> } - disabled={textProcessor.loading || !inputText} + disabled={textProcessor.processing || !inputText} onClick={handleGenerateLexeme} /> @@ -210,7 +210,7 @@ function DlgEditWordForms({ hideWindow, target, onSave }: DlgEditWordFormsProps) title='Сбросить все словоформы' className='py-0' icon={} - disabled={textProcessor.loading || forms.length === 0} + disabled={textProcessor.processing || forms.length === 0} onClick={handleResetAll} /> diff --git a/rsconcept/frontend/src/hooks/useCheckExpression.ts b/rsconcept/frontend/src/hooks/useCheckExpression.ts index 89ebfc5e..7d711b20 100644 --- a/rsconcept/frontend/src/hooks/useCheckExpression.ts +++ b/rsconcept/frontend/src/hooks/useCheckExpression.ts @@ -11,7 +11,7 @@ import { RSErrorType } from '@/models/rslang'; import { PARAMETER } from '@/utils/constants'; function useCheckExpression({ schema }: { schema?: IRSForm }) { - const [loading, setLoading] = useState(false); + const [processing, setProcessing] = useState(false); const [error, setError] = useState(undefined); const [parseData, setParseData] = useState(undefined); @@ -22,7 +22,7 @@ function useCheckExpression({ schema }: { schema?: IRSForm }) { postCheckExpression(String(schema!.id), { data: { expression: expression }, showError: true, - setLoading, + setLoading: setProcessing, onError: setError, onSuccess: parse => { if (activeCst) { @@ -34,7 +34,7 @@ function useCheckExpression({ schema }: { schema?: IRSForm }) { }); } - return { parseData, checkExpression, resetParse, error, setError, loading }; + return { parseData, checkExpression, resetParse, error, setError, processing }; } export default useCheckExpression; diff --git a/rsconcept/frontend/src/hooks/useConceptText.ts b/rsconcept/frontend/src/hooks/useConceptText.ts index 5ea48753..661d6ee7 100644 --- a/rsconcept/frontend/src/hooks/useConceptText.ts +++ b/rsconcept/frontend/src/hooks/useConceptText.ts @@ -7,7 +7,7 @@ import { ErrorData } from '@/components/info/InfoError'; import { ILexemeData, ITextRequest, ITextResult, IWordFormPlain } from '@/models/language'; function useConceptText() { - const [loading, setLoading] = useState(false); + const [processing, setProcessing] = useState(false); const [error, setError] = useState(undefined); const inflect = useCallback((data: IWordFormPlain, onSuccess: DataCallback) => { @@ -15,7 +15,7 @@ function useConceptText() { postInflectText({ data: data, showError: true, - setLoading, + setLoading: setProcessing, onError: setError, onSuccess: data => { if (onSuccess) onSuccess(data); @@ -28,7 +28,7 @@ function useConceptText() { postParseText({ data: data, showError: true, - setLoading, + setLoading: setProcessing, onError: setError, onSuccess: data => { if (onSuccess) onSuccess(data); @@ -41,7 +41,7 @@ function useConceptText() { postGenerateLexeme({ data: data, showError: true, - setLoading, + setLoading: setProcessing, onError: setError, onSuccess: data => { if (onSuccess) onSuccess(data); @@ -49,7 +49,7 @@ function useConceptText() { }); }, []); - return { inflect, parse, generateLexeme, error, setError, loading }; + return { inflect, parse, generateLexeme, error, setError, processing }; } export default useConceptText; diff --git a/rsconcept/frontend/src/hooks/useOssDetails.ts b/rsconcept/frontend/src/hooks/useOssDetails.ts index ae2184f8..ef202f99 100644 --- a/rsconcept/frontend/src/hooks/useOssDetails.ts +++ b/rsconcept/frontend/src/hooks/useOssDetails.ts @@ -9,7 +9,7 @@ import { OssLoader } from '@/models/OssLoader'; function useOssDetails({ target }: { target?: string }) { const [schema, setInner] = useState(undefined); - const [loading, setLoading] = useState(false); + const [loading, setLoading] = useState(true); const [error, setError] = useState(undefined); function setSchema(data?: IOperationSchemaData) { diff --git a/rsconcept/frontend/src/hooks/useRSFormDetails.ts b/rsconcept/frontend/src/hooks/useRSFormDetails.ts index dd2c532b..0d2d5144 100644 --- a/rsconcept/frontend/src/hooks/useRSFormDetails.ts +++ b/rsconcept/frontend/src/hooks/useRSFormDetails.ts @@ -9,7 +9,7 @@ import { RSFormLoader } from '@/models/RSFormLoader'; function useRSFormDetails({ target, version }: { target?: string; version?: string }) { const [schema, setInnerSchema] = useState(undefined); - const [loading, setLoading] = useState(false); + const [loading, setLoading] = useState(true); const [error, setError] = useState(undefined); function setSchema(data?: IRSFormData) { diff --git a/rsconcept/frontend/src/hooks/useResolveText.ts b/rsconcept/frontend/src/hooks/useResolveText.ts index 2926d330..7d578398 100644 --- a/rsconcept/frontend/src/hooks/useResolveText.ts +++ b/rsconcept/frontend/src/hooks/useResolveText.ts @@ -8,7 +8,7 @@ import { IResolutionData } from '@/models/language'; import { IRSForm } from '@/models/rsform'; function useResolveText({ schema }: { schema?: IRSForm }) { - const [loading, setLoading] = useState(false); + const [processing, setProcessing] = useState(false); const [error, setError] = useState(undefined); const [refsData, setRefsData] = useState(undefined); @@ -19,7 +19,7 @@ function useResolveText({ schema }: { schema?: IRSForm }) { postResolveText(String(schema!.id), { data: { text: text }, showError: true, - setLoading, + setLoading: setProcessing, onError: setError, onSuccess: data => { setRefsData(data); @@ -28,7 +28,7 @@ function useResolveText({ schema }: { schema?: IRSForm }) { }); } - return { refsData, resolveText, resetData, error, setError, loading }; + return { refsData, resolveText, resetData, error, setError, processing }; } export default useResolveText; diff --git a/rsconcept/frontend/src/pages/RSFormPage/EditorRSExpression/EditorRSExpression.tsx b/rsconcept/frontend/src/pages/RSFormPage/EditorRSExpression/EditorRSExpression.tsx index c61ac3f8..86cfbdc2 100644 --- a/rsconcept/frontend/src/pages/RSFormPage/EditorRSExpression/EditorRSExpression.tsx +++ b/rsconcept/frontend/src/pages/RSFormPage/EditorRSExpression/EditorRSExpression.tsx @@ -170,7 +170,7 @@ function EditorRSExpression({