feat: add loading indicator in AddNewAppConnection
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { useQuery } from '@apollo/client';
|
import { useLazyQuery } from '@apollo/client';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
|
import debounce from 'lodash/debounce';
|
||||||
import { useTheme } from '@mui/material/styles';
|
import { useTheme } from '@mui/material/styles';
|
||||||
import useMediaQuery from '@mui/material/useMediaQuery';
|
import useMediaQuery from '@mui/material/useMediaQuery';
|
||||||
import DialogTitle from '@mui/material/DialogTitle';
|
import DialogTitle from '@mui/material/DialogTitle';
|
||||||
@@ -8,6 +9,7 @@ import DialogContent from '@mui/material/DialogContent';
|
|||||||
import Dialog from '@mui/material/Dialog';
|
import Dialog from '@mui/material/Dialog';
|
||||||
import SearchIcon from '@mui/icons-material/Search';
|
import SearchIcon from '@mui/icons-material/Search';
|
||||||
import InputAdornment from '@mui/material/InputAdornment';
|
import InputAdornment from '@mui/material/InputAdornment';
|
||||||
|
import CircularProgress from '@mui/material/CircularProgress';
|
||||||
import List from '@mui/material/List';
|
import List from '@mui/material/List';
|
||||||
import ListItem from '@mui/material/ListItem';
|
import ListItem from '@mui/material/ListItem';
|
||||||
import ListItemButton from '@mui/material/ListItemButton';
|
import ListItemButton from '@mui/material/ListItemButton';
|
||||||
@@ -33,7 +35,27 @@ export default function AddNewAppConnection(props: AddNewAppConnectionProps): Re
|
|||||||
const matchSmallScreens = useMediaQuery(theme.breakpoints.down('sm'));
|
const matchSmallScreens = useMediaQuery(theme.breakpoints.down('sm'));
|
||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
const [appName, setAppName] = React.useState<string | null>(null);
|
const [appName, setAppName] = React.useState<string | null>(null);
|
||||||
const { data } = useQuery(GET_APPS, { variables: { name: appName } });
|
const [loading, setLoading] = React.useState(false);
|
||||||
|
const [getApps, { data }] = useLazyQuery(GET_APPS, {
|
||||||
|
onCompleted: () => { setLoading(false); },
|
||||||
|
});
|
||||||
|
|
||||||
|
const fetchData = React.useMemo(
|
||||||
|
() => debounce((name) => getApps({ variables: { name }}), 300),
|
||||||
|
[getApps]
|
||||||
|
);
|
||||||
|
|
||||||
|
React.useEffect(function fetchAppsOnAppNameChange() {
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
fetchData(appName);
|
||||||
|
}, [fetchData, appName]);
|
||||||
|
|
||||||
|
React.useEffect(function cancelDebounceOnUnmount() {
|
||||||
|
return () => {
|
||||||
|
fetchData.cancel();
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={true} onClose={onClose} maxWidth="sm" fullWidth>
|
<Dialog open={true} onClose={onClose} maxWidth="sm" fullWidth>
|
||||||
@@ -57,6 +79,7 @@ export default function AddNewAppConnection(props: AddNewAppConnectionProps): Re
|
|||||||
id="search-app"
|
id="search-app"
|
||||||
type="text"
|
type="text"
|
||||||
fullWidth
|
fullWidth
|
||||||
|
autoFocus
|
||||||
onChange={(event) => setAppName(event.target.value)}
|
onChange={(event) => setAppName(event.target.value)}
|
||||||
endAdornment={
|
endAdornment={
|
||||||
<InputAdornment position="end">
|
<InputAdornment position="end">
|
||||||
@@ -67,8 +90,10 @@ export default function AddNewAppConnection(props: AddNewAppConnectionProps): Re
|
|||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
||||||
<List sx={{ pt: 2 }}>
|
<List sx={{ pt: 2, width: '100%' }}>
|
||||||
{data?.getApps?.map((app: IApp) => (
|
{loading && <CircularProgress sx={{ display: 'block', margin: '20px auto' }} />}
|
||||||
|
|
||||||
|
{!loading && data?.getApps?.map((app: IApp) => (
|
||||||
<ListItem disablePadding key={app.name}>
|
<ListItem disablePadding key={app.name}>
|
||||||
<ListItemButton component={Link} to={URLS.APP_ADD_CONNECTION(app.name.toLowerCase())}>
|
<ListItemButton component={Link} to={URLS.APP_ADD_CONNECTION(app.name.toLowerCase())}>
|
||||||
<ListItemIcon sx={{ minWidth: 74 }}>
|
<ListItemIcon sx={{ minWidth: 74 }}>
|
||||||
|
Reference in New Issue
Block a user