1
- import React , { useState } from 'react' ;
2
- import PropTypes , { string } from 'prop-types' ;
1
+ import React from 'react' ;
2
+ import PropTypes from 'prop-types' ;
3
3
import styled from 'styled-components' ;
4
+ import { useSelector } from 'react-redux' ;
4
5
import { withRouter , Link } from 'react-router' ;
5
6
6
7
import Screen from '../../components/mobile/MobileScreen' ;
@@ -14,6 +15,7 @@ import CollectionList from '../IDE/components/CollectionList';
14
15
import AssetList from '../IDE/components/AssetList' ;
15
16
import Content from './MobileViewContent' ;
16
17
import { SketchSearchbar , CollectionSearchbar } from '../IDE/components/Searchbar' ;
18
+ import Button from '../../common/Button' ;
17
19
18
20
const EXAMPLE_USERNAME = 'p5' ;
19
21
@@ -26,16 +28,21 @@ const FooterTab = styled(Link)`
26
28
` ;
27
29
28
30
const Subheader = styled . div `
31
+ display: flex;
32
+ flex-direction: row;
33
+ * { border-radius: 0px; }
29
34
30
35
.searchbar {
31
36
display: flex;
32
- * {
33
- border-radius: 0px;
34
- }
37
+ width: 100%;
35
38
}
36
39
.searchbar__input { width: 100%; }
37
40
` ;
38
41
42
+ const SubheaderButton = styled ( Button ) `
43
+ border-radius: 0px !important;
44
+ ` ;
45
+
39
46
40
47
const FooterTabSwitcher = styled . div `
41
48
display: flex;
@@ -49,23 +56,31 @@ const Panels = {
49
56
assets : AssetList
50
57
} ;
51
58
52
- const renderPanel = ( name , props ) => ( Component => ( Component && < Component { ...props } /> ) ) ( Panels [ name ] ) ;
59
+ const CreatePathname = {
60
+ sketches : '/mobile' ,
61
+ collections : '/mobile/:username/collections/create' ,
62
+ } ;
63
+
53
64
54
65
const getPanel = ( pathname ) => {
55
66
const pathparts = pathname ? pathname . split ( '/' ) : [ ] ;
56
67
const matches = Object . keys ( Panels ) . map ( part => part . toLowerCase ( ) ) . filter ( part => pathparts . includes ( part ) ) ;
57
68
return matches && matches . length > 0 && matches [ 0 ] ;
58
69
} ;
59
70
71
+ const getCreatePathname = ( panel , username ) => ( CreatePathname [ panel ] || '#' ) . replace ( ':username' , username ) ;
60
72
61
- const MobileDashboard = ( { params, location } ) => {
62
- const Tabs = Object . keys ( Panels ) ;
73
+ const isOwner = ( user , params ) => user && params && user . username === params . username ;
74
+
75
+ const renderPanel = ( name , props ) => ( Component => ( Component && < Component { ...props } /> ) ) ( Panels [ name ] ) ;
63
76
77
+ const MobileDashboard = ( { params, location } ) => {
78
+ const user = useSelector ( state => state . user ) ;
64
79
const { username } = params ;
65
80
const { pathname } = location ;
66
81
82
+ const Tabs = Object . keys ( Panels ) ;
67
83
const isExamples = username === EXAMPLE_USERNAME ;
68
-
69
84
const panel = getPanel ( pathname ) ;
70
85
71
86
return (
@@ -77,6 +92,7 @@ const MobileDashboard = ({ params, location }) => {
77
92
78
93
< Content slimheader >
79
94
< Subheader >
95
+ { isOwner ( user , params ) && < SubheaderButton to = { getCreatePathname ( panel , username ) } > new</ SubheaderButton > }
80
96
{ panel === Tabs [ 0 ] && < SketchSearchbar /> }
81
97
{ panel === Tabs [ 1 ] && < CollectionSearchbar /> }
82
98
</ Subheader >
@@ -100,6 +116,7 @@ const MobileDashboard = ({ params, location }) => {
100
116
</ Screen > ) ;
101
117
} ;
102
118
119
+
103
120
MobileDashboard . propTypes = {
104
121
location : PropTypes . shape ( {
105
122
pathname : PropTypes . string . isRequired
0 commit comments