Commit 37f6fb5d authored by Thisara Kavinda's avatar Thisara Kavinda

refactor: created MeetingLoading component

parent b188752b
import { Box, Button, CircularProgress, Typography } from '@mui/material'
import { useTheme, type Theme } from '@mui/material/styles'
interface Props {
variant: 'joining' | 'loading' | 'error'
}
const MeetingLoading = ({ variant }: Props) => {
const theme: Theme = useTheme()
const renderComponent = (): JSX.Element => {
switch (variant) {
case 'joining':
return (
<Box
sx={{
height: '100%',
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Typography
variant='h3'
textAlign={'center'}
sx={{ fontSize: '18px', color: theme.palette.common.white, fontWeight: '600' }}
>
Joining the meeting...
</Typography>
</Box>
)
case 'loading':
return (
<Box
sx={{
height: '100%',
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Box
sx={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
}}
>
<CircularProgress
size={'md'}
sx={{
color: theme.palette.common.white,
height: '20px',
width: '20px',
marginRight: '20px',
}}
/>
<Typography
variant='h3'
textAlign={'center'}
sx={{ fontSize: '18px', color: theme.palette.common.white, fontWeight: '600' }}
>
Loading devices
</Typography>
</Box>
</Box>
)
case 'error':
return (
<Box
sx={{
height: '100%',
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Box
sx={{
backgroundColor: '#262625',
borderRadius: '20px',
padding: '20px 40px',
width: '30%',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Typography
variant='h3'
textAlign={'center'}
sx={{
fontSize: '18px',
color: theme.palette.common.white,
fontWeight: '600',
marginTop: '10px',
}}
>
Unexpected error occurred. Please try reloading the page. 😞
</Typography>
<Button
variant='text'
sx={{
color: theme.palette.primary.main,
borderRadius: '10px',
padding: '10px 20px',
marginTop: '10px',
fontWeight: '600',
}}
onClick={() => window.location.reload()}
>
Reload
</Button>
</Box>
</Box>
)
default:
return <></>
}
}
return renderComponent()
}
export default MeetingLoading
...@@ -12,8 +12,9 @@ import { ...@@ -12,8 +12,9 @@ import {
import React, { createContext, useContext, useEffect } from 'react' import React, { createContext, useContext, useEffect } from 'react'
import type { IMicrophoneAudioTrack, ICameraVideoTrack } from 'agora-rtc-sdk-ng' import type { IMicrophoneAudioTrack, ICameraVideoTrack } from 'agora-rtc-sdk-ng'
import { Box, Button, CircularProgress, Typography } from '@mui/material' import { Box } from '@mui/material'
import { useTheme, type Theme } from '@mui/material/styles' import { useTheme, type Theme } from '@mui/material/styles'
import MeetingLoading from '../../Components/MeetingLoading/MeetingLoading'
interface AgoraContextType { interface AgoraContextType {
localCameraTrack: ICameraVideoTrack | null localCameraTrack: ICameraVideoTrack | null
...@@ -82,59 +83,9 @@ export const AgoraManager = ({ children }: { children: React.ReactNode }) => { ...@@ -82,59 +83,9 @@ export const AgoraManager = ({ children }: { children: React.ReactNode }) => {
return ( return (
<Box sx={{ width: '100%', height: '100%', backgroundColor: theme.palette.background.default }}> <Box sx={{ width: '100%', height: '100%', backgroundColor: theme.palette.background.default }}>
{isJoining ? ( {isJoining ? (
<Box <MeetingLoading variant='joining' />
sx={{
height: '100%',
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Typography
variant='h3'
textAlign={'center'}
sx={{ fontSize: '18px', color: theme.palette.common.white, fontWeight: '600' }}
>
Joining the meeting...
</Typography>
</Box>
) : isLoadingCam || isLoadingMic ? ( ) : isLoadingCam || isLoadingMic ? (
<Box <MeetingLoading variant='loading' />
sx={{
height: '100%',
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Box
sx={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
}}
>
<CircularProgress
size={'md'}
sx={{
color: theme.palette.common.white,
height: '20px',
width: '20px',
marginRight: '20px',
}}
/>
<Typography
variant='h3'
textAlign={'center'}
sx={{ fontSize: '18px', color: theme.palette.common.white, fontWeight: '600' }}
>
Loading devices
</Typography>
</Box>
</Box>
) : isJoined ? ( ) : isJoined ? (
<AgoraProvider <AgoraProvider
localCameraTrack={localCameraTrack} localCameraTrack={localCameraTrack}
...@@ -155,58 +106,10 @@ export const AgoraManager = ({ children }: { children: React.ReactNode }) => { ...@@ -155,58 +106,10 @@ export const AgoraManager = ({ children }: { children: React.ReactNode }) => {
</div> </div>
</AgoraProvider> </AgoraProvider>
) : joinError ? ( ) : joinError ? (
<Box <MeetingLoading variant='error' />
sx={{
height: '100%',
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Box
sx={{
backgroundColor: '#262625',
borderRadius: '20px',
padding: '20px 40px',
width: '30%',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Typography
variant='h3'
textAlign={'center'}
sx={{
fontSize: '18px',
color: theme.palette.common.white,
fontWeight: '600',
marginTop: '10px',
}}
>
Unexpected error occurred. Please try reloading the page. 😞
</Typography>
<Button
variant='text'
sx={{
color: theme.palette.primary.main,
borderRadius: '10px',
padding: '10px 20px',
marginTop: '10px',
fontWeight: '600',
}}
onClick={() => window.location.reload()}
>
Reload
</Button>
</Box>
</Box>
) : null} ) : null}
</Box> </Box>
) )
} }
// Export the AgoraManager component as the default export
export default AgoraManager export default AgoraManager
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment