Skip to content

Commit

Permalink
replace store methods with useSelector and useDispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
sunilshetye committed Oct 14, 2024
1 parent 56610b3 commit 0594f4e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 3 additions & 4 deletions blocks/eda-frontend/src/components/SchematicEditor/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { deepPurple } from '@material-ui/core/colors'

import logo from '../../static/favicon.ico'
import { setTitle, logout, setSchTitle, setSchShared } from '../../redux/actions/index'
import store from '../../redux/store'
import { getDateTime as getDate } from '../../utils/GalleryUtils'

const useStyles = makeStyles((theme) => ({
Expand Down Expand Up @@ -102,8 +101,8 @@ SimpleSnackbar.propTypes = {
function Header () {
const history = useHistory()
const classes = useStyles()
const isAuthenticated = store.getState().authReducer.isAuthenticated
const user = store.getState().authReducer.user
const isAuthenticated = useSelector(state => state.authReducer.isAuthenticated)
const user = useSelector(state => state.authReducer.user)
const details = useSelector(state => state.saveSchematicReducer.details)
const isSaved = useSelector(state => state.saveSchematicReducer.isSaved)
const isShared = useSelector(state => state.saveSchematicReducer.isShared)
Expand Down Expand Up @@ -333,7 +332,7 @@ function Header () {
{typography2}
</MenuItem>
<MenuItem onClick={() => {
store.dispatch(logout(history))
dispatch(logout(history))
}}
>
Logout
Expand Down
10 changes: 6 additions & 4 deletions blocks/eda-frontend/src/components/Shared/Navbar.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { useState } from 'react'
import { useSelector, useDispatch } from 'react-redux'

import { AppBar, Avatar, Button, Fade, IconButton, Link, ListItemText, Menu, MenuItem, Toolbar, Typography } from '@material-ui/core'
import { makeStyles } from '@material-ui/core/styles'
import { deepPurple } from '@material-ui/core/colors'
import { Link as RouterLink, useHistory } from 'react-router-dom'
import logo from '../../static/favicon.ico'
import store from '../../redux/store'
import { logout } from '../../redux/actions/index'

const useStyles = makeStyles((theme) => ({
Expand Down Expand Up @@ -42,8 +42,10 @@ export function Header () {
const history = useHistory()
const classes = useStyles()
const [anchorEl, setAnchorEl] = useState(null)
const isAuthenticated = store.getState().authReducer.isAuthenticated
const user = store.getState().authReducer.user
const isAuthenticated = useSelector(state => state.authReducer.isAuthenticated)
const user = useSelector(state => state.authReducer.user)

const dispatch = useDispatch()

const handleClick = (event) => {
setAnchorEl(event.currentTarget)
Expand Down Expand Up @@ -193,7 +195,7 @@ export function Header () {
{typography}
</MenuItem>
<MenuItem onClick={() => {
store.dispatch(logout(history))
dispatch(logout(history))
}}
>
Logout
Expand Down

0 comments on commit 0594f4e

Please sign in to comment.