diff options
author | Sunil Shetye | 2024-10-11 21:10:58 +0530 |
---|---|---|
committer | Sunil Shetye | 2024-10-11 21:10:58 +0530 |
commit | b640527243c187489705faca2bf5bad192f18089 (patch) | |
tree | 9fcd9b2ed12fea3826d437e8b62305e02711f320 | |
parent | f1b47827716c6e17bfaed3970b3f9be8b8b89a8e (diff) | |
download | Common-Interface-Project-b640527243c187489705faca2bf5bad192f18089.tar.gz Common-Interface-Project-b640527243c187489705faca2bf5bad192f18089.tar.bz2 Common-Interface-Project-b640527243c187489705faca2bf5bad192f18089.zip |
replace reducers with the appropriate properties
14 files changed, 93 insertions, 81 deletions
diff --git a/blocks/eda-frontend/src/App.js b/blocks/eda-frontend/src/App.js index ba6668e4..4273cacc 100644 --- a/blocks/eda-frontend/src/App.js +++ b/blocks/eda-frontend/src/App.js @@ -19,7 +19,8 @@ import { loadUser } from './redux/actions/index' // Controls Private routes, this are accessible for authenticated users. [ e.g : dashboard ] // and restricted routes disabled for authenticated users. [ e.g : login , signup ] function PrivateRoute ({ component: Component, ...rest }) { - const auth = useSelector(state => state.authReducer) + const isAuthenticated = useSelector(state => state.authReducer.isAuthenticated) + const isLoading = useSelector(state => state.authReducer.isLoading) const dispatch = useDispatch() useEffect(() => dispatch(loadUser()), [dispatch]) @@ -27,9 +28,9 @@ function PrivateRoute ({ component: Component, ...rest }) { return ( <Route {...rest} render={props => { - if (auth.isLoading) { + if (isLoading) { return <CircularProgress style={{ margin: '50vh 50vw' }} /> - } else if (!auth.isAuthenticated) { + } else if (!isAuthenticated) { return <Redirect to='/login' /> } else { return <Component {...props} /> @@ -45,7 +46,8 @@ PrivateRoute.propTypes = { // Public routes accessible to all users. [ e.g. editor, gallery ] function PublicRoute ({ component: Component, restricted, nav, ...rest }) { - const auth = useSelector(state => state.authReducer) + const isAuthenticated = useSelector(state => state.authReducer.isAuthenticated) + const isLoading = useSelector(state => state.authReducer.isLoading) const dispatch = useDispatch() useEffect(() => dispatch(loadUser()), [dispatch]) @@ -53,9 +55,9 @@ function PublicRoute ({ component: Component, restricted, nav, ...rest }) { return ( <Route {...rest} render={props => { - if (auth.isLoading) { + if (isLoading) { return <CircularProgress style={{ margin: '50vh 50vw' }} /> - } else if (auth.isAuthenticated && restricted) { + } else if (isAuthenticated && restricted) { return <Redirect to='/dashboard' /> } else if (nav) { return (<><Navbar /><Component {...props} /></>) diff --git a/blocks/eda-frontend/src/components/Dashboard/DashboardHome.js b/blocks/eda-frontend/src/components/Dashboard/DashboardHome.js index 32931a90..e3858ea0 100644 --- a/blocks/eda-frontend/src/components/Dashboard/DashboardHome.js +++ b/blocks/eda-frontend/src/components/Dashboard/DashboardHome.js @@ -21,7 +21,7 @@ const useStyles = makeStyles((theme) => ({ // Card displaying user dashboard home page header. function MainCard () { const classes = useStyles() - const auth = useSelector(state => state.authReducer) + const user = useSelector(state => state.authReducer.user) const dashboard = process.env.REACT_APP_NAME const button = 'My ' + process.env.REACT_APP_DIAGRAMS_NAME @@ -32,7 +32,7 @@ function MainCard () { Welcome to your {dashboard} Dashboard </Typography> <Typography variant='h5' component='h2'> - Welcome {auth.user.username}... + Welcome {user.username}... </Typography> </CardContent> <CardActions> @@ -51,7 +51,7 @@ function MainCard () { export default function DashboardHome () { const classes = useStyles() - const auth = useSelector(state => state.authReducer) + const user = useSelector(state => state.authReducer.user) const typography = 'Track your ' + process.env.REACT_APP_SMALL_DIAGRAMS_NAME + ' status here...' return ( @@ -72,7 +72,7 @@ export default function DashboardHome () { <Grid item xs={12}> <Card style={{ padding: '7px 15px' }} className={classes.mainHead}> <Typography variant='subtitle1' gutterBottom> - Hey {auth.user.username} , {typography} + Hey {user.username} , {typography} </Typography> </Card> </Grid> diff --git a/blocks/eda-frontend/src/components/Dashboard/DashboardSidebar.js b/blocks/eda-frontend/src/components/Dashboard/DashboardSidebar.js index 83addf20..6f3486fd 100644 --- a/blocks/eda-frontend/src/components/Dashboard/DashboardSidebar.js +++ b/blocks/eda-frontend/src/components/Dashboard/DashboardSidebar.js @@ -38,7 +38,7 @@ const useStyles = makeStyles((theme) => ({ // Vertical Navbar for user dashboard export default function DashSidebar (props) { const classes = useStyles() - const auth = useSelector(state => state.authReducer) + const user = useSelector(state => state.authReducer.user) const schematics = useSelector(state => state.dashboardReducer.schematics) const dispatch = useDispatch() @@ -67,11 +67,11 @@ export default function DashSidebar (props) { > <ListItemAvatar> <Avatar className={classes.purple}> - {auth.user.username.charAt(0).toUpperCase()} + {user.username.charAt(0).toUpperCase()} </Avatar> </ListItemAvatar> <ListItemText - primary={auth.user.username} + primary={user.username} secondary={ <> <Typography diff --git a/blocks/eda-frontend/src/components/Dashboard/SchematicsList.js b/blocks/eda-frontend/src/components/Dashboard/SchematicsList.js index 9b9bef6b..85cfea3f 100644 --- a/blocks/eda-frontend/src/components/Dashboard/SchematicsList.js +++ b/blocks/eda-frontend/src/components/Dashboard/SchematicsList.js @@ -55,7 +55,7 @@ function MainCard () { export default function SchematicsList () { const classes = useStyles() - const auth = useSelector(state => state.authReducer) + const user = useSelector(state => state.authReducer.user) const schematics = useSelector(state => state.dashboardReducer.schematics) const dispatch = useDispatch() @@ -97,7 +97,7 @@ export default function SchematicsList () { : <Grid item xs={12}> <Card style={{ padding: '7px 15px' }} className={classes.mainHead}> <Typography variant='subtitle1' gutterBottom> - Hey {auth.user.username} , {typography1} + Hey {user.username} , {typography1} </Typography> </Card> </Grid>} diff --git a/blocks/eda-frontend/src/components/SchematicEditor/Header.js b/blocks/eda-frontend/src/components/SchematicEditor/Header.js index 437e8b0a..6b927d6e 100644 --- a/blocks/eda-frontend/src/components/SchematicEditor/Header.js +++ b/blocks/eda-frontend/src/components/SchematicEditor/Header.js @@ -102,8 +102,12 @@ SimpleSnackbar.propTypes = { function Header () { const history = useHistory() const classes = useStyles() - const auth = store.getState().authReducer - const schSave = useSelector(state => state.saveSchematicReducer) + const isAuthenticated = store.getState().authReducer.isAuthenticated + const user = store.getState().authReducer.user + const details = useSelector(state => state.saveSchematicReducer.details) + const isSaved = useSelector(state => state.saveSchematicReducer.isSaved) + const isShared = useSelector(state => state.saveSchematicReducer.isShared) + const title = useSelector(state => state.saveSchematicReducer.title) const [anchorEl, setAnchorEl] = useState(null) const dispatch = useDispatch() @@ -148,11 +152,11 @@ function Header () { } // change saved schematic share status - const [shared, setShared] = useState(schSave.isShared) + const [shared, setShared] = useState(isShared) useEffect(() => { - setShared(schSave.isShared) - }, [schSave.isShared]) + setShared(isShared) + }, [isShared]) const handleShareChange = (event) => { setShared(event.target.checked) @@ -160,10 +164,10 @@ function Header () { } const handleShare = () => { - if (auth.isAuthenticated !== true) { + if (isAuthenticated !== true) { setMessage('You are not Logged In') handleSnacClick() - } else if (schSave.isSaved !== true) { + } else if (isSaved !== true) { setMessage('You have not saved the circuit') handleSnacClick() } else { @@ -210,28 +214,28 @@ function Header () { <Input className={classes.input} color='secondary' - value={schSave.title === 'Untitled' ? 'Untitled' : schSave.title} + value={title === 'Untitled' ? 'Untitled' : title} onChange={titleHandler} inputProps={{ 'aria-label': 'SchematicTitle' }} /> </Hidden> {/* Display last saved and shared option for saved schematics */} - {auth.isAuthenticated === true + {isAuthenticated === true ? <> - {(schSave.isSaved === true && schSave.details.save_time !== undefined) + {(isSaved === true && details.save_time !== undefined) ? <Typography variant='body2' style={{ margin: '0px 15px 0px auto', paddingTop: '5px', color: '#8c8c8c' }} > - Last Saved : {getDate(schSave.details.save_time)} {/* Display last saved status for saved schematics */} + Last Saved : {getDate(details.save_time)} {/* Display last saved status for saved schematics */} </Typography> : <></>} <Button size='small' variant={shared !== true ? 'outlined' : 'contained'} color='primary' - className={schSave.isSaved === true && schSave.details.save_time !== undefined ? classes.button : classes.rightBlock} + className={isSaved === true && details.save_time !== undefined ? classes.button : classes.rightBlock} startIcon={<ShareIcon />} onClick={handleShare} > @@ -259,7 +263,7 @@ function Header () { {shared === true ? <input ref={textAreaRef} - value={`${window.location.protocol}\\\\${window.location.host}/eda/#/editor?id=${schSave.details.save_id}`} + value={`${window.location.protocol}\\\\${window.location.host}/eda/#/editor?id=${details.save_id}`} readOnly /> : <> Turn On sharing </>} @@ -280,7 +284,7 @@ function Header () { {/* Display login option or user menu as per authenticated status */} { - (!auth.isAuthenticated + (!isAuthenticated ? <Button size='small' component={RouterLink} @@ -300,7 +304,7 @@ function Header () { onClick={handleClick} > <Avatar className={classes.purple}> - {auth.user.username.charAt(0).toUpperCase()} + {user.username.charAt(0).toUpperCase()} </Avatar> </IconButton> <Menu @@ -318,7 +322,7 @@ function Header () { to='/dashboard' onClick={handleClose} > - <ListItemText primary={auth.user.username} secondary={auth.user.email} /> + <ListItemText primary={user.username} secondary={user.email} /> </MenuItem> <MenuItem target='_blank' diff --git a/blocks/eda-frontend/src/components/SchematicEditor/PropertiesSidebar.js b/blocks/eda-frontend/src/components/SchematicEditor/PropertiesSidebar.js index 646de25e..baf6ed51 100644 --- a/blocks/eda-frontend/src/components/SchematicEditor/PropertiesSidebar.js +++ b/blocks/eda-frontend/src/components/SchematicEditor/PropertiesSidebar.js @@ -119,9 +119,9 @@ export default function PropertiesSidebar ({ gridRef, outlineRef }) { const classes = useStyles() const isOpen = useSelector(state => state.componentPropertiesReducer.isPropertiesWindowOpen) - const schSave = useSelector(state => state.saveSchematicReducer) + const description1 = useSelector(state => state.saveSchematicReducer.description) - const [description, setDescription] = useState(schSave.description) + const [description, setDescription] = useState(description1) const dispatch = useDispatch() @@ -159,7 +159,7 @@ export default function PropertiesSidebar ({ gridRef, outlineRef }) { <ListItemText primary={typography1} /> </ListItem> <ListItem style={{ padding: '0px 7px 7px 7px' }} divider> - <TextareaAutosize id='Description' label='Description' value={schSave.description === '' ? description || '' : schSave.description} onChange={getInputValues} minRows={6} aria-label='Description' placeholder={typography2} style={{ width: '100%', minWidth: '234px', maxHeight: '250px' }} /> + <TextareaAutosize id='Description' label='Description' value={description1 === '' ? description || '' : description1} onChange={getInputValues} minRows={6} aria-label='Description' placeholder={typography2} style={{ width: '100%', minWidth: '234px', maxHeight: '250px' }} /> </ListItem> </div> </List> diff --git a/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js b/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js index 6924766d..8196e3f2 100644 --- a/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js +++ b/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js @@ -92,9 +92,12 @@ SimpleSnackbar.propTypes = { export default function SchematicToolbar ({ mobileClose, gridRef }) { const classes = useStyles() - const netfile = useSelector(state => state.netlistReducer) - const auth = useSelector(state => state.authReducer) - const schSave = useSelector(state => state.saveSchematicReducer) + const controlBlock = useSelector(state => state.netlistReducer.controlBlock) + const controlLine = useSelector(state => state.netlistReducer.controlLine) + const title1 = useSelector(state => state.netlistReducer.title) + const isAuthenticated = useSelector(state => state.authReducer.isAuthenticated) + const description = useSelector(state => state.saveSchematicReducer.description) + const title2 = useSelector(state => state.saveSchematicReducer.title) const dispatch = useDispatch() @@ -104,11 +107,11 @@ export default function SchematicToolbar ({ mobileClose, gridRef }) { const handleClickOpen = () => { const compNetlist = generateNetList() - const netlist = netfile.title + '\n\n' + + const netlist = title1 + '\n\n' + compNetlist.models + '\n' + compNetlist.main + '\n' + - netfile.controlLine + '\n' + - netfile.controlBlock + '\n' + controlLine + '\n' + + controlBlock + '\n' genNetlist(netlist) setOpen(true) } @@ -240,7 +243,7 @@ export default function SchematicToolbar ({ mobileClose, gridRef }) { }) const a = document.createElement('a') const ext = (type === 'PNG') ? '.png' : '.jpg' - a.setAttribute('download', schSave.title + '_' + process.env.REACT_APP_NAME + '_on_Cloud' + ext) + a.setAttribute('download', title2 + '_' + process.env.REACT_APP_NAME + '_on_Cloud' + ext) a.setAttribute('href', data) a.setAttribute('target', '_blank') a.dispatchEvent(evt) @@ -255,7 +258,7 @@ export default function SchematicToolbar ({ mobileClose, gridRef }) { cancelable: true }) const a = document.createElement('a') - a.setAttribute('download', schSave.title + '_' + process.env.REACT_APP_NAME + '_on_Cloud.svg') + a.setAttribute('download', title2 + '_' + process.env.REACT_APP_NAME + '_on_Cloud.svg') a.href = URL.createObjectURL(blob) a.target = '_blank' a.setAttribute('target', '_blank') @@ -292,17 +295,15 @@ export default function SchematicToolbar ({ mobileClose, gridRef }) { // Handle Save Schematic onCloud const handleSchSave = () => { - if (auth.isAuthenticated !== true) { + if (isAuthenticated !== true) { setMessage('You are not Logged In') handleSnacClick() } else { - const description = schSave.description const xml = saveXml(description) dispatch(setSchXmlData(xml)) - const title = schSave.title exportImage('PNG') .then(res => { - dispatch(saveSchematic(title, description, xml, res)) + dispatch(saveSchematic(title2, description, xml, res)) }) .catch(err => { // Debugging: Log if there is an error in exportImage @@ -316,14 +317,14 @@ export default function SchematicToolbar ({ mobileClose, gridRef }) { // Save Schematics Locally const handleLocalSchSave = () => { - const blob = new Blob([beautify(saveXml(schSave.description))], { type: 'application/xml' }) + const blob = new Blob([beautify(saveXml(description))], { type: 'application/xml' }) const evt = new MouseEvent('click', { view: window, bubbles: false, cancelable: true }) const a = document.createElement('a') - a.setAttribute('download', schSave.title + '_' + process.env.REACT_APP_NAME + '_on_Cloud.xml') + a.setAttribute('download', title2 + '_' + process.env.REACT_APP_NAME + '_on_Cloud.xml') a.href = URL.createObjectURL(blob) a.target = '_blank' a.setAttribute('target', '_blank') @@ -332,10 +333,10 @@ export default function SchematicToolbar ({ mobileClose, gridRef }) { const handleLocalSchSaveXcos = async () => { try { - const xmlContent = beautify(saveXml(schSave.description)) + const xmlContent = beautify(saveXml(description)) const xmlBlob = new Blob([xmlContent], { type: 'application/xml' }) - const xmlFileName = schSave.title + '.xml' + const xmlFileName = title2 + '.xml' const formData = new FormData() formData.append('file', xmlBlob, xmlFileName) @@ -352,7 +353,7 @@ export default function SchematicToolbar ({ mobileClose, gridRef }) { const xcosBlob = new Blob([response.data], { type: 'application/xcos' }) const a = document.createElement('a') - a.setAttribute('download', schSave.title + '_' + process.env.REACT_APP_NAME + '_on_Cloud.xcos') + a.setAttribute('download', title2 + '_' + process.env.REACT_APP_NAME + '_on_Cloud.xcos') a.href = URL.createObjectURL(xcosBlob) a.target = '_blank' a.setAttribute('target', '_blank') diff --git a/blocks/eda-frontend/src/components/SchematicEditor/SimulationProperties.js b/blocks/eda-frontend/src/components/SchematicEditor/SimulationProperties.js index 0d93ee3f..9a555ba3 100644 --- a/blocks/eda-frontend/src/components/SchematicEditor/SimulationProperties.js +++ b/blocks/eda-frontend/src/components/SchematicEditor/SimulationProperties.js @@ -42,7 +42,7 @@ const useStyles = makeStyles((theme) => ({ })) export default function SimulationProperties () { - const netfile = useSelector(state => state.netlistReducer) + const title = useSelector(state => state.netlistReducer.title) const isSimRes = useSelector(state => state.simulationReducer.isSimRes) const dispatch = useDispatch() const classes = useStyles() @@ -79,7 +79,7 @@ export default function SimulationProperties () { // Prepare Netlist to file const prepareNetlist = (netlist) => { - const titleA = netfile.title.split(' ')[1] + const titleA = title.split(' ')[1] const myblob = new Blob([netlist], { type: 'text/plain' }) diff --git a/blocks/eda-frontend/src/components/SchematicEditor/SimulationScreen.js b/blocks/eda-frontend/src/components/SchematicEditor/SimulationScreen.js index 948e5ce1..0fb36ce0 100644 --- a/blocks/eda-frontend/src/components/SchematicEditor/SimulationScreen.js +++ b/blocks/eda-frontend/src/components/SchematicEditor/SimulationScreen.js @@ -112,7 +112,8 @@ export function setGraphStatusClosed () { export default function SimulationScreen ({ open, close }) { const classes = useStyles() const dispatch = useDispatch() - const result = useSelector(state => state.simulationReducer) + const isGraph = useSelector(state => state.simulationReducer.isGraph) + const rtitle = useSelector(state => state.simulationReducer.title) const stitle = useSelector(state => state.netlistReducer.title) const taskId = useSelector(state => state.simulationReducer.taskId) const [isResult, setIsResult] = useState(false) @@ -733,7 +734,7 @@ export default function SimulationScreen ({ open, close }) { <Grid item xs={12} sm={12}> <Paper className={classes.paper}> <Typography variant='h2' align='center' gutterBottom> - {result.title} + {rtitle} </Typography> <Typography variant='h5' align='center' component='p' gutterBottom> Simulation Result for {stitle} * @@ -745,7 +746,7 @@ export default function SimulationScreen ({ open, close }) { {isResult === true ? <> { - (result.isGraph === 'true') + (isGraph === 'true') ? <> <Grid item xs={12} sm={12}> <Paper className={classes.paper}> @@ -770,7 +771,7 @@ export default function SimulationScreen ({ open, close }) { : <div /> } </> - : (result.isGraph === 'false') ? <span>{typography1}</span> : <span /> + : (isGraph === 'false') ? <span>{typography1}</span> : <span /> } {/* Diplay of Simulation parameter Not present */} { @@ -786,7 +787,7 @@ export default function SimulationScreen ({ open, close }) { } {/* Display text result */} { - (result.isGraph === 'false') + (isGraph === 'false') ? <Grid item xs={12} sm={12}> <Paper className={classes.paper}> <Typography variant='h4' align='center' gutterBottom> diff --git a/blocks/eda-frontend/src/components/SchematicEditor/ToolbarExtension.js b/blocks/eda-frontend/src/components/SchematicEditor/ToolbarExtension.js index 601e276e..6c08e03c 100644 --- a/blocks/eda-frontend/src/components/SchematicEditor/ToolbarExtension.js +++ b/blocks/eda-frontend/src/components/SchematicEditor/ToolbarExtension.js @@ -47,9 +47,9 @@ const FileSaver = require('file-saver') // Dialog box to display generated netlist export function NetlistModal ({ open, close, netlist }) { - const netfile = useSelector(state => state.netlistReducer) + const title = useSelector(state => state.netlistReducer.title) const createNetlistFile = () => { - const titleA = netfile.title.split(' ')[1] + const titleA = title.split(' ')[1] const name = process.env.REACT_APP_NAME const blob = new Blob([netlist], { type: 'text/plain;charset=utf-8' }) FileSaver.saveAs(blob, `${titleA}_${name}_on_Cloud.cir`) @@ -384,8 +384,9 @@ export function OpenSchDialog (props) { const { open, close, openLocal } = props const [isLocal, setisLocal] = useState(true) const [isGallery, setisGallery] = useState(false) - const schSave = useSelector(state => state.saveSchematicReducer) - const auth = useSelector(state => state.authReducer) + const details = useSelector(state => state.saveSchematicReducer.details) + const isAuthenticated = useSelector(state => state.authReducer.isAuthenticated) + const user = useSelector(state => state.authReducer.user) const schematics = useSelector(state => state.dashboardReducer.schematics) const dispatch = useDispatch() @@ -442,7 +443,7 @@ export function OpenSchDialog (props) { size='small' color='primary' onClick={() => { dispatch(loadGallery(sch.save_id.substr(7, sch.save_id.length))) }} - variant={schSave.details.save_id === undefined ? 'outlined' : schSave.details.save_id !== sch.save_id ? 'outlined' : 'contained'} + variant={details.save_id === undefined ? 'outlined' : details.save_id !== sch.save_id ? 'outlined' : 'contained'} > Launch </Button> @@ -460,7 +461,7 @@ export function OpenSchDialog (props) { {/* Listing Saved Schematics */} {schematics.length === 0 ? <Typography variant='subtitle1' gutterBottom> - Hey {auth.user.username} , {typography1} + Hey {user.username} , {typography1} </Typography> : <TableContainer component={Paper} style={{ maxHeight: '45vh' }}> <Table stickyHeader size='small' aria-label='simple table'> @@ -494,7 +495,7 @@ export function OpenSchDialog (props) { size='small' color='primary' onClick={() => { dispatch(fetchSchematic(sch.save_id)) }} - variant={schSave.details.save_id === undefined ? 'outlined' : schSave.details.save_id !== sch.save_id ? 'outlined' : 'contained'} + variant={details.save_id === undefined ? 'outlined' : details.save_id !== sch.save_id ? 'outlined' : 'contained'} > Launch </Button> @@ -517,7 +518,7 @@ export function OpenSchDialog (props) { <Button variant={isGallery ? 'outlined' : 'text'} onClick={() => { setisLocal(false); setisGallery(true) }} color='secondary'> Gallery </Button> - {auth.isAuthenticated !== true + {isAuthenticated !== true ? <></> : <Button variant={!isGallery & !isLocal ? 'outlined' : 'text'} onClick={() => { dispatch(fetchSchematics()); setisLocal(false); setisGallery(false) }} color='secondary'> on Cloud diff --git a/blocks/eda-frontend/src/components/Shared/Navbar.js b/blocks/eda-frontend/src/components/Shared/Navbar.js index 43bafb82..77ec687f 100644 --- a/blocks/eda-frontend/src/components/Shared/Navbar.js +++ b/blocks/eda-frontend/src/components/Shared/Navbar.js @@ -42,7 +42,8 @@ export function Header () { const history = useHistory() const classes = useStyles() const [anchorEl, setAnchorEl] = useState(null) - const auth = store.getState().authReducer + const isAuthenticated = store.getState().authReducer.isAuthenticated + const user = store.getState().authReducer.user const handleClick = (event) => { setAnchorEl(event.currentTarget) @@ -75,7 +76,7 @@ export function Header () { {/* Display relative link to other pages */} <nav> { - (auth.isAuthenticated + (isAuthenticated ? (<> <Link variant='button' @@ -145,7 +146,7 @@ export function Header () { {/* Display login option or user menu as per authenticated status */} { - (!auth.isAuthenticated + (!isAuthenticated ? <Button size='small' component={RouterLink} @@ -165,7 +166,7 @@ export function Header () { onClick={handleClick} > <Avatar className={classes.purple}> - {auth.user.username.charAt(0).toUpperCase()} + {user.username.charAt(0).toUpperCase()} </Avatar> </IconButton> <Menu @@ -182,7 +183,7 @@ export function Header () { to='/dashboard' onClick={handleClose} > - <ListItemText primary={auth.user.username} secondary={auth.user.email} /> + <ListItemText primary={user.username} secondary={user.email} /> </MenuItem> <MenuItem component={RouterLink} diff --git a/blocks/eda-frontend/src/pages/Login.js b/blocks/eda-frontend/src/pages/Login.js index e14b26fb..5d1da000 100644 --- a/blocks/eda-frontend/src/pages/Login.js +++ b/blocks/eda-frontend/src/pages/Login.js @@ -51,7 +51,7 @@ let url = '' export default function SignIn (props) { const classes = useStyles() - const auth = useSelector(state => state.authReducer) + const errors = useSelector(state => state.authReducer.errors) const dispatch = useDispatch() const homeURL = `${window.location.protocol}\\\\${window.location.host}/` @@ -105,7 +105,7 @@ export default function SignIn (props) { {/* Display's error messages while logging in */} <Typography variant='body1' align='center' style={{ marginTop: '10px' }} color='error'> - {auth.errors} + {errors} </Typography> <form className={classes.form} noValidate> diff --git a/blocks/eda-frontend/src/pages/signUp.js b/blocks/eda-frontend/src/pages/signUp.js index 38fd7ea0..4895b696 100644 --- a/blocks/eda-frontend/src/pages/signUp.js +++ b/blocks/eda-frontend/src/pages/signUp.js @@ -48,7 +48,8 @@ const useStyles = makeStyles((theme) => ({ export default function SignUp () { const classes = useStyles() - const auth = useSelector(state => state.authReducer) + const isRegistered = useSelector(state => state.authReducer.isRegistered) + const regErrors = useSelector(state => state.authReducer.regErrors) const dispatch = useDispatch() const homeURL = `${window.location.protocol}\\\\${window.location.host}/` @@ -96,8 +97,8 @@ export default function SignUp () { </Typography> {/* Display's error messages while signing in */} - <Typography variant='body1' align='center' style={{ marginTop: '10px' }} color={auth.isRegistered ? 'secondary' : 'error'}> - {auth.regErrors} + <Typography variant='body1' align='center' style={{ marginTop: '10px' }} color={isRegistered ? 'secondary' : 'error'}> + {regErrors} </Typography> <form className={classes.form} noValidate> diff --git a/blocks/eda-frontend/src/redux/actions/saveSchematicActions.js b/blocks/eda-frontend/src/redux/actions/saveSchematicActions.js index cc4b30c6..08d83b4f 100644 --- a/blocks/eda-frontend/src/redux/actions/saveSchematicActions.js +++ b/blocks/eda-frontend/src/redux/actions/saveSchematicActions.js @@ -53,7 +53,8 @@ export const saveSchematic = (title, description, xml, base64) => (dispatch, get // Get token from localstorage const token = getState().authReducer.token - const schSave = getState().saveSchematicReducer + const details = getState().saveSchematicReducer.details + const isSaved = getState().saveSchematicReducer.isSaved // add headers const config = { @@ -67,9 +68,9 @@ export const saveSchematic = (title, description, xml, base64) => (dispatch, get config.headers.Authorization = `Token ${token}` } - if (schSave.isSaved) { + if (isSaved) { // Updating saved schemaic - api.post('save/diagram/' + schSave.details.save_id, queryString.stringify(body), config) + api.post('save/diagram/' + details.save_id, queryString.stringify(body), config) .then( (res) => { dispatch({ @@ -130,7 +131,7 @@ export const fetchSchematic = (saveId) => (dispatch, getState) => { export const setSchShared = (share) => (dispatch, getState) => { // Get token from localstorage const token = getState().authReducer.token - const schSave = getState().saveSchematicReducer + const details = getState().saveSchematicReducer.details // add headers const config = { @@ -151,7 +152,7 @@ export const setSchShared = (share) => (dispatch, getState) => { isShared = 'off' } - api.post('save/' + schSave.details.save_id + '/sharing/' + isShared, {}, config) + api.post('save/' + details.save_id + '/sharing/' + isShared, {}, config) .then( (res) => { dispatch({ |