Skip to content

Commit

Permalink
fix: make PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh committed Mar 25, 2024
1 parent 3138b51 commit ea7d1e5
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions src/components/APIChecker.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { useState } from 'react';

import { Replay } from '@mui/icons-material';
import { LoadingButton } from '@mui/lab';
import { Alert, AlertTitle, Box, Stack, Typography } from '@mui/material';
Expand All @@ -9,42 +7,22 @@ import { useAuthTranslation } from '../config/i18n';
import { axios, useQuery } from '../config/queryClient';
import { AUTH } from '../langs/constants';

const APIChecker = (): JSX.Element | null => {
const APIChecker = (): JSX.Element | false => {
const { t } = useAuthTranslation();
const [noConnection, setNoConnection] = useState(false);
const { isSuccess, isLoading, refetch } = useQuery({
const { isSuccess, isLoading, refetch, isError } = useQuery({
queryKey: ['apiStatus'],
queryFn: () =>
axios
.get(`${API_HOST}/status`, { withCredentials: false })
.then(({ data }) => data)
.catch(() => setNoConnection(true)),
retry: 1,
.then(({ data }) => data),
retry: 0,
});

if (isSuccess) {
return (
<Stack direction="row" alignItems="center" color="success.light">
<svg viewBox="0 0 10 10" width="20px" height="20px">
<circle
fill="currentColor"
style={{ filter: 'drop-shadow(0px 0px 2px currentColor)' }}
r="1.3px"
cx="5px"
cy="4.8px"
/>
</svg>
<Typography
sx={{ textShadow: 'currentColor 1px 0px 10px' }}
variant="caption"
>
Connected to Graasp backend
</Typography>
</Stack>
);
return false;
}

if (noConnection) {
if (isError) {
return (
<Box maxWidth="48ch">
<Alert severity="error">
Expand All @@ -66,6 +44,6 @@ const APIChecker = (): JSX.Element | null => {
);
}

return null;
return false;
};
export default APIChecker;

0 comments on commit ea7d1e5

Please sign in to comment.