Files
parcer/src/components/molecules/NavBar.tsx

126 lines
4.0 KiB
TypeScript
Raw Normal View History

2024-09-25 20:27:56 +05:30
import React, { useState, useContext } from 'react';
import axios from 'axios';
2024-06-24 22:34:54 +05:30
import styled from "styled-components";
import { stopRecording } from "../../api/recording";
import { useGlobalInfoStore } from "../../context/globalInfo";
2024-10-21 01:12:06 +05:30
import { IconButton } from "@mui/material";
2024-06-24 22:34:54 +05:30
import { RecordingIcon } from "../atoms/RecorderIcon";
import { SaveRecording } from "./SaveRecording";
2024-10-21 01:12:06 +05:30
import { Logout, Clear } from "@mui/icons-material";
import { useNavigate } from 'react-router-dom';
2024-09-25 20:27:56 +05:30
import { AuthContext } from '../../context/auth';
2024-06-24 22:34:54 +05:30
interface NavBarProps {
recordingName: string;
isRecording: boolean;
}
2024-10-21 01:13:06 +05:30
export const NavBar: React.FC<NavBarProps> = ({ recordingName, isRecording }) => {
2024-06-24 22:34:54 +05:30
2024-10-21 01:12:27 +05:30
const { notify, browserId, setBrowserId, recordingUrl } = useGlobalInfoStore();
2024-09-25 20:27:56 +05:30
const { state, dispatch } = useContext(AuthContext);
const { user } = state;
2024-10-11 04:57:48 +05:30
console.log(`Recording URL: ${recordingUrl}`)
2024-10-11 04:48:25 +05:30
2024-09-10 02:52:07 +05:30
const navigate = useNavigate();
2024-06-24 22:34:54 +05:30
2024-09-25 20:27:56 +05:30
const logout = async () => {
dispatch({ type: 'LOGOUT' });
window.localStorage.removeItem('user');
const { data } = await axios.get('http://localhost:8080/auth/logout');
notify('success', data.message);
navigate('/login');
};
2024-06-24 22:34:54 +05:30
// If recording is in progress, the resources and change page view by setting browserId to null
// else it won't affect the page
2024-09-10 02:49:30 +05:30
const goToMainMenu = async () => {
2024-06-24 22:34:54 +05:30
if (browserId) {
await stopRecording(browserId);
notify('warning', 'Current Recording was terminated');
setBrowserId(null);
}
2024-09-10 02:52:07 +05:30
navigate('/');
2024-06-24 22:34:54 +05:30
};
return (
<NavBarWrapper>
2024-09-30 16:05:50 +05:30
<div style={{
display: 'flex',
justifyContent: 'flex-start',
}}>
<RecordingIcon />
<div style={{ padding: '11px' }}><ProjectName>Maxun</ProjectName></div>
</div>
2024-09-30 16:05:26 +05:30
{
user !== null ? (
<>
2024-09-30 16:00:26 +05:30
<div style={{
display: 'flex',
justifyContent: 'flex-end',
}}>
2024-10-10 21:45:09 +05:30
{
!isRecording ? (
<>
<IconButton sx={{
2024-10-10 21:45:09 +05:30
width: '140px',
borderRadius: '5px',
padding: '8px',
background: '#ff00c3',
color: 'white',
marginRight: '10px',
fontFamily: '"Roboto","Helvetica","Arial",sans-serif',
2024-10-11 18:29:30 +05:30
fontWeight: '500',
2024-10-10 21:45:09 +05:30
fontSize: '0.875rem',
lineHeight: '1.75',
letterSpacing: '0.02857em',
'&:hover': { color: 'white', backgroundColor: '#ff00c3' }
}} onClick={logout}>
<Logout sx={{ marginRight: '5px' }} />
Logout</IconButton>
</>
2024-10-21 01:14:32 +05:30
) :
<>
<IconButton sx={{
width: '140px',
borderRadius: '5px',
padding: '8px',
background: 'red',
color: 'white',
marginRight: '10px',
fontFamily: '"Roboto","Helvetica","Arial",sans-serif',
fontWeight: '500',
fontSize: '0.875rem',
lineHeight: '1.75',
letterSpacing: '0.02857em',
'&:hover': { color: 'white', backgroundColor: 'red' }
}} onClick={goToMainMenu}>
<Clear sx={{ marginRight: '5px' }} />
Discard</IconButton>
<SaveRecording fileName={recordingName} />
</>
2024-09-25 20:27:56 +05:30
}
2024-09-30 16:00:26 +05:30
</div>
</>
) : ""
}
2024-06-24 22:34:54 +05:30
</NavBarWrapper>
);
};
const NavBarWrapper = styled.div`
grid-area: navbar;
2024-10-10 21:14:51 +05:30
background-color: white;
2024-06-24 22:34:54 +05:30
padding:5px;
display: flex;
justify-content: space-between;
2024-10-23 07:12:33 +05:30
border-bottom: 1px solid #e0e0e0;
2024-06-24 22:34:54 +05:30
`;
const ProjectName = styled.b`
2024-10-10 21:14:51 +05:30
color: #3f4853;
2024-06-24 22:34:54 +05:30
font-size: 1.3em;
`;