1
1
import PropTypes from 'prop-types' ;
2
- import React from 'react' ;
2
+ import React , { useState , useEffect } from 'react' ;
3
3
import { connect } from 'react-redux' ;
4
4
import MediaQuery from 'react-responsive' ;
5
5
import { withTranslation } from 'react-i18next' ;
@@ -24,36 +24,27 @@ import DashboardTabSwitcherPublic, {
24
24
TabKey
25
25
} from '../components/DashboardTabSwitcher' ;
26
26
27
- class DashboardView extends React . Component {
28
- static defaultProps = {
29
- user : null
27
+ function DashboardView ( props ) {
28
+ const [ collectionCreateVisible , setCollectionCreateVisible ] = useState ( false ) ;
29
+
30
+ useEffect ( ( ) => {
31
+ // You can add any componentDidMount logic here if needed.
32
+ } , [ ] ) ;
33
+
34
+ const closeAccountPage = ( ) => {
35
+ browserHistory . push ( props . previousPath ) ;
36
+ } ;
37
+
38
+ const createNewSketch = ( ) => {
39
+ props . newProject ( ) ;
30
40
} ;
31
41
32
- constructor ( props ) {
33
- super ( props ) ;
34
- this . closeAccountPage = this . closeAccountPage . bind ( this ) ;
35
- this . createNewSketch = this . createNewSketch . bind ( this ) ;
36
- this . gotoHomePage = this . gotoHomePage . bind ( this ) ;
37
- this . toggleCollectionCreate = this . toggleCollectionCreate . bind ( this ) ;
38
- this . state = {
39
- collectionCreateVisible : false
40
- } ;
41
- }
42
-
43
- closeAccountPage ( ) {
44
- browserHistory . push ( this . props . previousPath ) ;
45
- }
46
-
47
- createNewSketch ( ) {
48
- this . props . newProject ( ) ;
49
- }
50
-
51
- gotoHomePage ( ) {
42
+ const gotoHomePage = ( ) => {
52
43
browserHistory . push ( '/' ) ;
53
- }
44
+ } ;
54
45
55
- selectedTabKey ( ) {
56
- const path = this . props . location . pathname ;
46
+ const selectedTabKey = ( ) => {
47
+ const path = props . location . pathname ;
57
48
58
49
if ( / a s s e t s / . test ( path ) ) {
59
50
return TabKey . assets ;
@@ -62,57 +53,55 @@ class DashboardView extends React.Component {
62
53
}
63
54
64
55
return TabKey . sketches ;
65
- }
56
+ } ;
66
57
67
- ownerName ( ) {
68
- if ( this . props . params . username ) {
69
- return this . props . params . username ;
58
+ const ownerName = ( ) => {
59
+ if ( props . params . username ) {
60
+ return props . params . username ;
70
61
}
71
62
72
- return this . props . user . username ;
73
- }
63
+ return props . user . username ;
64
+ } ;
74
65
75
- isOwner ( ) {
76
- return this . props . user . username === this . props . params . username ;
77
- }
66
+ const isOwner = ( ) => {
67
+ return props . user . username === props . params . username ;
68
+ } ;
78
69
79
- toggleCollectionCreate ( ) {
80
- this . setState ( ( prevState ) => ( {
81
- collectionCreateVisible : ! prevState . collectionCreateVisible
82
- } ) ) ;
83
- }
70
+ const toggleCollectionCreate = ( ) => {
71
+ setCollectionCreateVisible ( ( prevState ) => ! prevState ) ;
72
+ } ;
84
73
85
- renderActionButton ( tabKey , username , t ) {
74
+ const renderActionButton = ( tabKey , username , t ) => {
86
75
switch ( tabKey ) {
87
76
case TabKey . assets :
88
- return this . isOwner ( ) && < AssetSize /> ;
77
+ return isOwner ( ) && < AssetSize /> ;
89
78
case TabKey . collections :
90
79
return (
91
- this . isOwner ( ) && (
92
- < React . Fragment >
93
- < Button onClick = { this . toggleCollectionCreate } >
80
+ isOwner ( ) && (
81
+ < >
82
+ < Button onClick = { toggleCollectionCreate } >
94
83
{ t ( 'DashboardView.CreateCollection' ) }
95
84
</ Button >
96
85
< CollectionSearchbar />
97
- </ React . Fragment >
86
+ </ >
98
87
)
99
88
) ;
100
89
case TabKey . sketches :
101
90
default :
102
91
return (
103
- < React . Fragment >
104
- { this . isOwner ( ) && (
105
- < Button onClick = { this . createNewSketch } >
92
+ < >
93
+ { isOwner ( ) && (
94
+ < Button onClick = { createNewSketch } >
106
95
{ t ( 'DashboardView.NewSketch' ) }
107
96
</ Button >
108
97
) }
109
98
< SketchSearchbar />
110
- </ React . Fragment >
99
+ </ >
111
100
) ;
112
101
}
113
- }
102
+ } ;
114
103
115
- renderContent ( tabKey , username , mobile ) {
104
+ const renderContent = ( tabKey , username , mobile ) => {
116
105
switch ( tabKey ) {
117
106
case TabKey . assets :
118
107
return < AssetList key = { username } mobile = { mobile } username = { username } /> ;
@@ -122,56 +111,50 @@ class DashboardView extends React.Component {
122
111
) ;
123
112
case TabKey . sketches :
124
113
default :
125
- return (
126
- < SketchList key = { username } mobile = { mobile } username = { username } />
127
- ) ;
114
+ return < SketchList key = { username } mobile = { mobile } username = { username } /> ;
128
115
}
129
- }
130
-
131
- render ( ) {
132
- const currentTab = this . selectedTabKey ( ) ;
133
- const isOwner = this . isOwner ( ) ;
134
- const { username } = this . props . params ;
135
- const actions = this . renderActionButton ( currentTab , username , this . props . t ) ;
136
-
137
- return (
138
- < RootPage fixedHeight = "100%" >
139
- < Nav layout = "dashboard" />
140
-
141
- < main className = "dashboard-header" >
142
- < div className = "dashboard-header__header" >
143
- < h2 className = "dashboard-header__header__title" >
144
- { this . ownerName ( ) }
145
- </ h2 >
146
- < div className = "dashboard-header__nav" >
147
- < DashboardTabSwitcherPublic
148
- currentTab = { currentTab }
149
- isOwner = { isOwner }
150
- username = { username }
151
- />
152
- { actions && (
153
- < div className = "dashboard-header__actions" > { actions } </ div >
154
- ) }
155
- </ div >
156
- </ div >
116
+ } ;
157
117
158
- < div className = "dashboard-content" >
159
- < MediaQuery maxWidth = { 770 } >
160
- { ( mobile ) => this . renderContent ( currentTab , username , mobile ) }
161
- </ MediaQuery >
118
+ const currentTab = selectedTabKey ( ) ;
119
+ const isOwnerFlag = isOwner ( ) ;
120
+ const { username } = props . params ;
121
+ const actions = renderActionButton ( currentTab , username , props . t ) ;
122
+
123
+ return (
124
+ < RootPage fixedHeight = "100%" >
125
+ < Nav layout = "dashboard" />
126
+
127
+ < main className = "dashboard-header" >
128
+ < div className = "dashboard-header__header" >
129
+ < h2 className = "dashboard-header__header__title" > { ownerName ( ) } </ h2 >
130
+ < div className = "dashboard-header__nav" >
131
+ < DashboardTabSwitcherPublic
132
+ currentTab = { currentTab }
133
+ isOwner = { isOwnerFlag }
134
+ username = { username }
135
+ />
136
+ { actions && (
137
+ < div className = "dashboard-header__actions" > { actions } </ div >
138
+ ) }
162
139
</ div >
163
- </ main >
164
- { this . state . collectionCreateVisible && (
165
- < Overlay
166
- title = { this . props . t ( 'DashboardView.CreateCollectionOverlay' ) }
167
- closeOverlay = { this . toggleCollectionCreate }
168
- >
169
- < CollectionCreate />
170
- </ Overlay >
171
- ) }
172
- </ RootPage >
173
- ) ;
174
- }
140
+ </ div >
141
+
142
+ < div className = "dashboard-content" >
143
+ < MediaQuery maxWidth = { 770 } >
144
+ { ( mobile ) => renderContent ( currentTab , username , mobile ) }
145
+ </ MediaQuery >
146
+ </ div >
147
+ </ main >
148
+ { collectionCreateVisible && (
149
+ < Overlay
150
+ title = { props . t ( 'DashboardView.CreateCollectionOverlay' ) }
151
+ closeOverlay = { toggleCollectionCreate }
152
+ >
153
+ < CollectionCreate />
154
+ </ Overlay >
155
+ ) }
156
+ </ RootPage >
157
+ ) ;
175
158
}
176
159
177
160
function mapStateToProps ( state ) {
0 commit comments