1- import React from 'react' ;
2- import { inject , observer } from 'app/componentConnectors ' ;
1+ import React , { useMemo } from 'react' ;
2+ import { useOvermind } from 'app/overmind ' ;
33
44import AppearanceIcon from 'react-icons/lib/md/color-lens' ;
55import CodeIcon from 'react-icons/lib/fa/code' ;
@@ -25,12 +25,20 @@ import { KeyMapping } from './KeyMapping';
2525
2626import { Container , ContentContainer } from './elements' ;
2727
28- class PreferencesModal extends React . Component {
29- getItems = ( ) => {
30- const hasSubscription = this . props . store . isPatron ;
31- const signedIn = this . props . store . isLoggedIn ;
28+ const PreferencesModal : React . FC = ( ) => {
29+ const {
30+ state : {
31+ isPatron,
32+ isLoggedIn,
33+ preferences : { itemId } ,
34+ } ,
35+ actions : {
36+ preferences : { itemIdChanged } ,
37+ } ,
38+ } = useOvermind ( ) ;
3239
33- return [
40+ const items = useMemo (
41+ ( ) => [
3442 {
3543 id : 'appearance' ,
3644 title : 'Appearance' ,
@@ -61,19 +69,19 @@ class PreferencesModal extends React.Component {
6169 icon : < KeyboardIcon /> ,
6270 content : < KeyMapping /> ,
6371 } ,
64- signedIn && {
72+ isLoggedIn && {
6573 id : 'integrations' ,
6674 title : 'Integrations' ,
6775 icon : < IntegrationIcon /> ,
6876 content : < Integrations /> ,
6977 } ,
70- hasSubscription && {
78+ isPatron && {
7179 id : 'paymentInfo' ,
7280 title : 'Payment Info' ,
7381 icon : < CreditCardIcon /> ,
7482 content : < PaymentInfo /> ,
7583 } ,
76- hasSubscription && {
84+ isPatron && {
7785 id : 'badges' ,
7886 title : 'Badges' ,
7987 icon : < StarIcon /> ,
@@ -85,26 +93,22 @@ class PreferencesModal extends React.Component {
8593 icon : < FlaskIcon /> ,
8694 content : < Experiments /> ,
8795 } ,
88- ] . filter ( x => x ) ;
89- } ;
96+ ] ,
97+ [ isLoggedIn , isPatron ]
98+ ) ;
9099
91- render ( ) {
92- const items = this . getItems ( ) ;
93- const item = items . find (
94- currentItem => currentItem . id === this . props . store . preferences . itemId
95- ) ;
100+ const item = items . find ( currentItem => currentItem . id === itemId ) ;
96101
97- return (
98- < Container >
99- < SideNavigation
100- itemId = { this . props . store . preferences . itemId }
101- menuItems = { items }
102- setItem = { this . props . signals . preferences . itemIdChanged }
103- />
104- < ContentContainer > { item . content } </ ContentContainer >
105- </ Container >
106- ) ;
107- }
108- }
102+ return (
103+ < Container >
104+ < SideNavigation
105+ itemId = { itemId }
106+ menuItems = { items }
107+ setItem = { itemIdChanged }
108+ />
109+ < ContentContainer > { item . content } </ ContentContainer >
110+ </ Container >
111+ ) ;
112+ } ;
109113
110- export default inject ( 'store' , 'signals' ) ( observer ( PreferencesModal ) ) ;
114+ export default PreferencesModal ;
0 commit comments