Skip to content

Commit aaef43d

Browse files
committed
fix(): Adding server status in the nav bar
1 parent b994e96 commit aaef43d

6 files changed

Lines changed: 83 additions & 17 deletions

File tree

src/screens/common/NavigationBar.tsx

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box, HStack, Img } from '@chakra-ui/react';
1+
import { Box, HStack, Img, Spinner, Text } from '@chakra-ui/react';
22
import { LinkButton, useCursor } from '@components';
33
import AmitRaikwarLogo from '@assets/images/AmitRaikwarLogo.png';
44
import { SearchIcon } from '@assets';
@@ -7,6 +7,8 @@ import { useTranslation } from 'react-i18next';
77
import { useLocation, useNavigate } from 'react-router-dom';
88
import { useMoveToTop } from '@hooks';
99
import { BASE_URL_ROUTE } from '@router';
10+
import { usePingTest } from '@services';
11+
import { isUndefined } from 'lodash';
1012

1113
const NavigationLink = [
1214
{
@@ -34,6 +36,7 @@ const ArticleLink = {
3436

3537
const NavigationBar = () => {
3638
const moveToTop = useMoveToTop();
39+
const { data } = usePingTest();
3740
const location = useLocation();
3841
const pathName = location.pathname;
3942
const navigate = useNavigate();
@@ -102,7 +105,9 @@ const NavigationBar = () => {
102105
bg={'rgba(255, 255, 255, 0.1)'}
103106
backdropFilter={'blur(20px)'}
104107
transition={'background-color 0.3s'}
105-
display={pathName !== BASE_URL_ROUTE ? 'none' : 'flex'}
108+
display={
109+
pathName !== BASE_URL_ROUTE + '/privateRoute' ? 'none' : 'flex'
110+
}
106111
>
107112
{NavigationLink.map(({ name, href }) => (
108113
<LinkButton
@@ -131,23 +136,56 @@ const NavigationBar = () => {
131136
</Box>
132137
</HStack>
133138
<HStack
134-
border={'1px solid gray'}
135-
padding="2.5"
136-
color={'white'}
137-
borderRadius="100px"
138-
bg={'rgba(255, 255, 255, 0.1)'}
139-
backdropFilter={'blur(20px)'}
140-
transition={'all 0.3s'}
141-
_hover={{
142-
transform: 'scale(1.1)',
143-
cursor: 'pointer',
144-
}}
145-
onMouseEnter={onMouseEnter}
146-
onMouseLeave={onMouseLeave}
147-
ref={ref}
148139
onClick={() => {}} // eslint-disable-line
149140
>
150-
<SearchIcon />
141+
<Box
142+
display={pathName === BASE_URL_ROUTE ? 'none' : 'flex'}
143+
border={'1px solid gray'}
144+
>
145+
<Text color={'white'} fontSize={'lg'} p={2}>
146+
Server :{' '}
147+
{isUndefined(data) ? (
148+
<>
149+
<Box
150+
as="span"
151+
w={3}
152+
h={3}
153+
borderRadius="50%"
154+
bg={'red.500'}
155+
display="inline-block"
156+
/>
157+
<Spinner size="xs" color="white" />
158+
</>
159+
) : (
160+
<Box
161+
as="span"
162+
w={3}
163+
h={3}
164+
borderRadius="50%"
165+
bg={'green.500'}
166+
display="inline-block"
167+
/>
168+
)}
169+
</Text>
170+
</Box>
171+
<Box
172+
onMouseEnter={onMouseEnter}
173+
onMouseLeave={onMouseLeave}
174+
ref={ref}
175+
border={'1px solid gray'}
176+
padding="2.5"
177+
color={'white'}
178+
borderRadius="100px"
179+
bg={'rgba(255, 255, 255, 0.1)'}
180+
backdropFilter={'blur(20px)'}
181+
transition={'all 0.3s'}
182+
_hover={{
183+
transform: 'scale(1.1)',
184+
cursor: 'pointer',
185+
}}
186+
>
187+
<SearchIcon />
188+
</Box>
151189
</HStack>
152190
</HStack>
153191
);

src/services/backend/articles/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ export const ADD_COMMENT_URL = `/add_comment`;
1515

1616
// Editor
1717
export const EDITOR_ARTICLES_URL = `/get_editor_article`;
18+
19+
// Ping
20+
export const PING_URL = `/ping`;

src/services/backend/articles/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ export { default as addComment } from './addComment';
77
export { default as getComments } from './getComments';
88

99
export { default as getEditorArticleData } from './getEditorArticleData';
10+
11+
export { default as pingTest } from './pingTest';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { GetRequest } from '../client/client';
2+
import { PING_URL } from './constants';
3+
4+
const pingTest = async () => GetRequest(PING_URL);
5+
6+
export default pingTest;

src/services/hooks/articles/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ export { default as useLikeArticleData } from './useLikeArticleData';
55
export { default as useAddArticle } from './useAddArticle';
66
export { default as useAddComment } from './useAddComment';
77
export { default as useGetComments } from './useGetComments';
8+
9+
export { default as usePingTest } from './usePingTest';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { pingTest } from '../../backend';
2+
import { useCallQuery } from '../common';
3+
4+
const usePingTest = () => {
5+
return useCallQuery({
6+
method: () => pingTest(),
7+
queryOptions: {
8+
queryKey: ['ping'],
9+
staleTime: 0,
10+
gcTime: 0,
11+
},
12+
});
13+
};
14+
15+
export default usePingTest;

0 commit comments

Comments
 (0)