mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
fix(experience): improve the loading experience (#5038)
improve the loading experience
This commit is contained in:
parent
527cd22608
commit
ba691c5636
3 changed files with 16 additions and 9 deletions
|
@ -7,7 +7,7 @@ import LoadingLayer from '@/components/LoadingLayer';
|
|||
|
||||
const LoadingLayerProvider = () => {
|
||||
const { loading } = useContext(PageContext);
|
||||
const debouncedLoading = useDebouncedLoader(loading);
|
||||
const debouncedLoading = useDebouncedLoader(loading, 500);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
|
@ -3,16 +3,24 @@ import { useCallback, useContext } from 'react';
|
|||
|
||||
import PageContext from '@/Providers/PageContextProvider/PageContext';
|
||||
|
||||
const useApi = <Args extends unknown[], Response>(api: (...args: Args) => Promise<Response>) => {
|
||||
type Options = {
|
||||
silent?: boolean;
|
||||
};
|
||||
|
||||
const useApi = <Args extends unknown[], Response>(
|
||||
api: (...args: Args) => Promise<Response>,
|
||||
options?: Options
|
||||
) => {
|
||||
const { setLoading } = useContext(PageContext);
|
||||
|
||||
const request = useCallback(
|
||||
async (...args: Args): Promise<[Nullable<unknown>, Response?]> => {
|
||||
if (!options?.silent) {
|
||||
setLoading(true);
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await api(...args);
|
||||
|
||||
return [null, result];
|
||||
} catch (error: unknown) {
|
||||
return [error];
|
||||
|
@ -20,7 +28,7 @@ const useApi = <Args extends unknown[], Response>(api: (...args: Args) => Promis
|
|||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[api, setLoading]
|
||||
[api, options?.silent, setLoading]
|
||||
);
|
||||
|
||||
return request;
|
||||
|
|
|
@ -23,12 +23,11 @@ const useSingleSignOnWatch = (identifierInput?: IdentifierInputValue) => {
|
|||
|
||||
const { showSingleSignOnForm, setShowSingleSignOnForm } = useContext(SingleSignOnFormModeContext);
|
||||
|
||||
const request = useApi(getSingleSignOnConnectors);
|
||||
const request = useApi(getSingleSignOnConnectors, { silent: true });
|
||||
|
||||
const singleSignOn = useSingleSignOn();
|
||||
|
||||
/**
|
||||
* Silently check if the email is registered with any SSO connectors
|
||||
*/
|
||||
// Silently check if the email is registered with any SSO connectors
|
||||
const fetchSsoConnectors = useCallback(
|
||||
async (email: string) => {
|
||||
const [, result] = await request(email);
|
||||
|
|
Loading…
Reference in a new issue