@@ -10,14 +10,20 @@ import ListItemText from "@material-ui/core/ListItemText";
1010import  Switch  from  "@material-ui/core/Switch" ; 
1111import  PaletteIcon  from  "@material-ui/icons/Palette" ; 
1212import  CompareArrowsIcon  from  "@material-ui/icons/CompareArrows" ; 
13- import  {  bindActionCreators  }  from  "redux" ; 
14- import  {  connect  }  from  "react-redux" ; 
13+ import  {  useSelector ,  useDispatch  }  from  'react-redux' ; 
1514
16- import  {  toggleThemeMode ,  swapThemeColors   }  from  "../store/reducers/settings " ; 
15+ import  {  toggleThemeMode ,  swapThemeColors ,   isDarkMode ,   isColorSwaped   }  from  "./settingsReducer " ; 
1716
18- const  Settings  =  props  =>  ( 
17+ export  default  function  Setting ( )  { 
18+ 
19+  const  darkMode  =  useSelector ( isDarkMode ) ; 
20+  const  colorSwaped  =  useSelector ( isColorSwaped ) ; 
21+ 
22+  const  dispatch  =  useDispatch ( ) ; 
23+ 
24+  return  ( 
1925 < div > 
20-  < Typography  variant = "headline " > Settings</ Typography > 
26+  < Typography  variant = "h5 " > Settings</ Typography > 
2127 < Card > 
2228 < CardContent > 
2329 < List > 
@@ -28,8 +34,8 @@ const Settings = props => (
2834 < ListItemText  primary = "Dark Mode"  /> 
2935 < ListItemSecondaryAction > 
3036 < Switch 
31-  onChange = { ( e ,  checked )  =>  props . toggleThemeMode ( checked ) } 
32-  checked = { props . settings . darkMode } 
37+  onChange = { ( e ,  checked )  =>    dispatch ( toggleThemeMode ( checked ) ) } 
38+  checked = { darkMode } 
3339 /> 
3440 </ ListItemSecondaryAction > 
3541 </ ListItem > 
@@ -40,34 +46,13 @@ const Settings = props => (
4046 < ListItemText  primary = "Swap Colors"  /> 
4147 < ListItemSecondaryAction > 
4248 < Switch 
43-  onChange = { ( e ,  checked )  =>  props . swapThemeColors ( checked ) } 
44-  checked = { props . settings . colorsSwaped } 
49+  onChange = { ( e ,  checked )  =>  dispatch ( swapThemeColors ( checked ) ) } 
50+  checked = { colorSwaped } 
4551 /> 
4652 </ ListItemSecondaryAction > 
4753 </ ListItem > 
4854 </ List > 
4955 </ CardContent > 
5056 </ Card > 
51-  </ div > 
52- ) ; 
53- 
54- const  mapStateToProps  =  state  =>  { 
55-  return  { 
56-  settings : state . settings 
57-  } ; 
57+  </ div > ) ; 
5858} ; 
59- 
60- const  mapDispatchToProps  =  dispatch  =>  { 
61-  return  bindActionCreators ( 
62-  { 
63-  toggleThemeMode : checked  =>  toggleThemeMode ( checked ) , 
64-  swapThemeColors : checked  =>  swapThemeColors ( checked ) 
65-  } , 
66-  dispatch 
67-  ) ; 
68- } ; 
69- 
70- export  default  connect ( 
71-  mapStateToProps , 
72-  mapDispatchToProps 
73- ) ( Settings ) ; 
0 commit comments