1- import React , { useState } from 'react' ;
1+ import React , { useContext , useState } from 'react' ;
22import { makeStyles } from '@material-ui/core/styles' ;
33import AppBar from '@material-ui/core/AppBar' ;
44import Toolbar from '@material-ui/core/Toolbar' ;
@@ -11,6 +11,10 @@ import NavigationDrawer from '../NavigationDrawer';
1111import GitHubIcon from '../GithubIcon' ;
1212import TwitterIcon from '../TwitterIcon' ;
1313import FacebookIcon from '../FacebookIcon' ;
14+ import Brightness5Icon from '@material-ui/icons/Brightness5' ;
15+ import Brightness7Icon from '@material-ui/icons/Brightness7' ;
16+ import { MainContext } from '../../contexts/MainContextProvider' ;
17+ import { setThemeIndex } from '../../reducers/MainReducer/Actions' ;
1418
1519const useStyles = makeStyles ( ( theme ) => ( {
1620 root : {
@@ -27,17 +31,18 @@ const useStyles = makeStyles((theme) => ({
2731const DefaultAppBar = ( {
2832 title, githubUrl, twitterUrl, facebookUrl,
2933} ) => {
34+ const [ state , dispatch ] = useContext ( MainContext ) ;
35+
36+ const { themeIndex } = state ;
37+
3038 const classes = useStyles ( ) ;
3139 const [ drawerOpen , setDrawerOpen ] = useState ( false ) ;
3240
3341 /**
34- * Open a website
35- * @param site The website that should be opened
42+ * Change the theme
3643 */
37- const openSite = ( site ) => {
38- if ( site ) {
39- window . open ( site , '_blank' ) ;
40- }
44+ const changeTheme = ( ) => {
45+ dispatch ( setThemeIndex ( themeIndex === 1 ? 0 : 1 ) ) ;
4146 } ;
4247
4348 return (
@@ -67,20 +72,8 @@ const DefaultAppBar = ({
6772
6873 < div className = { classes . title } />
6974
70- < IconButton color = "inherit" onClick = { ( ) => openSite ( facebookUrl ) } >
71- < SvgIcon >
72- < FacebookIcon />
73- </ SvgIcon >
74- </ IconButton >
75- < IconButton color = "inherit" onClick = { ( ) => openSite ( twitterUrl ) } >
76- < SvgIcon >
77- < TwitterIcon />
78- </ SvgIcon >
79- </ IconButton >
80- < IconButton color = "inherit" onClick = { ( ) => openSite ( githubUrl ) } >
81- < SvgIcon >
82- < GitHubIcon />
83- </ SvgIcon >
75+ < IconButton color = "inherit" onClick = { changeTheme } >
76+ { themeIndex === 1 ? < Brightness5Icon /> : < Brightness7Icon /> }
8477 </ IconButton >
8578 </ Toolbar >
8679 < NavigationDrawer onClose = { ( ) => setDrawerOpen ( false ) } open = { drawerOpen } />
0 commit comments