Skip to content

Commit

Permalink
feat: refactor layout component and add useOnlineStatus hook
Browse files Browse the repository at this point in the history
  • Loading branch information
mohandast52 committed Feb 5, 2025
1 parent 8aa4be7 commit b6c5aa2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
16 changes: 8 additions & 8 deletions frontend/components/Layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { WifiOutlined } from '@ant-design/icons';
import { message } from 'antd';
import { PropsWithChildren, useContext, useEffect } from 'react';
import { PropsWithChildren, useEffect } from 'react';
import styled, { css } from 'styled-components';

import { COLOR } from '@/constants/colors';
import { OnlineStatusContext } from '@/context/OnlineStatusProvider';
import { APP_HEIGHT } from '@/constants/width';
import { useNotifyOnNewEpoch } from '@/hooks/useNotifyOnNewEpoch';
import { useOnlineStatusContext } from '@/hooks/useOnlineStatus';

import { TopBar } from './TopBar';

const Container = styled.div<{ blur: 'true' | 'false' }>`
const Container = styled.div<{ $blur: boolean }>`
background-color: ${COLOR.WHITE};
border-radius: 8px;
${(props) =>
props.blur === 'true' &&
props.$blur &&
css`
filter: blur(2px);
position: relative;
Expand All @@ -34,8 +35,7 @@ const Container = styled.div<{ blur: 'true' | 'false' }>`
`;

const Body = styled.div`
// check main.js for the height of the app ie, 700px
max-height: calc(700px - 45px);
max-height: calc(${APP_HEIGHT}px - 45px);
padding-top: 45px;
overflow-y: auto;
`;
Expand All @@ -47,7 +47,7 @@ const useSystemLevelNotifications = () => {
export const Layout = ({
children,
}: PropsWithChildren & { vertical?: boolean }) => {
const { isOnline } = useContext(OnlineStatusContext);
const { isOnline } = useOnlineStatusContext();

// all the app level notifications
useSystemLevelNotifications();
Expand All @@ -66,7 +66,7 @@ export const Layout = ({
}, [isOnline]);

return (
<Container blur={isOnline ? 'false' : 'true'}>
<Container $blur={!isOnline}>
<TopBar />
<Body>{children}</Body>
</Container>
Expand Down
1 change: 1 addition & 0 deletions frontend/constants/width.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const APP_WIDTH = 480;
export const APP_HEIGHT = 700;

export const MODAL_WIDTH = 412;

Expand Down
5 changes: 5 additions & 0 deletions frontend/hooks/useOnlineStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { useContext } from 'react';

import { OnlineStatusContext } from '@/context/OnlineStatusProvider';

export const useOnlineStatusContext = () => useContext(OnlineStatusContext);
File renamed without changes.

0 comments on commit b6c5aa2

Please sign in to comment.