@@ -2,7 +2,6 @@ import React, { useContext, useMemo, useState } from 'react';
22import styled from 'styled-components' ;
33import { useDispatch , useSelector } from 'react-redux' ;
44import { useTranslation } from 'react-i18next' ;
5- import { useLocation } from 'react-router' ;
65import { Link } from 'react-router-dom' ;
76import { sortBy } from 'lodash' ;
87import classNames from 'classnames' ;
@@ -15,6 +14,7 @@ import AsteriskIcon from '../../../../images/p5-asterisk.svg';
1514import IconButton from '../../../../components/mobile/IconButton' ;
1615import {
1716 AccountIcon ,
17+ AddIcon ,
1818 EditorIcon ,
1919 MoreIcon ,
2020 CrossIcon
@@ -26,14 +26,15 @@ import {
2626 showKeyboardShortcutModal
2727} from '../../actions/ide' ;
2828import { logoutUser } from '../../../User/actions' ;
29- import { useSketchActions } from '../../hooks' ;
29+ import { useSketchActions , useWhatPage } from '../../hooks' ;
3030import { CmControllerContext } from '../../pages/IDEView' ;
3131import { selectSketchPath } from '../../selectors/project' ;
3232import { availableLanguages , languageKeyToLabel } from '../../../../i18n' ;
3333import { showToast } from '../../actions/toast' ;
3434import { setLanguage } from '../../actions/preferences' ;
3535import Overlay from '../../../App/components/Overlay' ;
3636import ProjectName from './ProjectName' ;
37+ import CollectionCreate from '../../../User/components/CollectionCreate' ;
3738
3839const Nav = styled ( NavBar ) `
3940 background: ${ prop ( 'MobilePanel.default.background' ) } ;
@@ -80,7 +81,7 @@ const Title = styled.div`
8081 }
8182` ;
8283
83- const Options = styled . div `
84+ export const Options = styled . div `
8485 margin-left: auto;
8586 display: flex;
8687 /* transform: translateX(${ remSize ( 12 ) } ); */
@@ -202,33 +203,28 @@ const MobileNav = () => {
202203
203204 const { t } = useTranslation ( ) ;
204205
205- const { pathname } = useLocation ( ) ;
206206 const editorLink = useSelector ( selectSketchPath ) ;
207+ const pageName = useWhatPage ( ) ;
207208
208209 // TODO: remove the switch and use a props like mobileTitle <Nav layout=“dashboard” mobileTitle={t(‘Login’)} />
209210 function resolveTitle ( ) {
210- switch ( pathname ) {
211- case '/' :
212- return project . name ;
213- case '/login' :
211+ switch ( pageName ) {
212+ case 'login' :
214213 return t ( 'LoginView.Login' ) ;
215- case '/ signup' :
214+ case 'signup' :
216215 return t ( 'LoginView.SignUp' ) ;
217- case '/ account' :
216+ case 'account' :
218217 return t ( 'AccountView.Settings' ) ;
219- case '/p5/sketches' :
220- case '/p5/collections' :
218+ case 'examples' :
221219 return t ( 'Nav.File.Examples' ) ;
222- case `/${ user . username } /assets` :
223- case `/${ user . username } /collections` :
224- case `/${ user . username } /sketches` :
220+ case 'myStuff' :
225221 return 'My Stuff' ;
226222 default :
227223 return project . name ;
228224 }
229225 }
230226
231- const title = useMemo ( resolveTitle , [ project , pathname ] ) ;
227+ const title = useMemo ( resolveTitle , [ pageName ] ) ;
232228
233229 const Logo = AsteriskIcon ;
234230 return (
@@ -242,10 +238,9 @@ const MobileNav = () => {
242238 < h5 > by { project ?. owner ?. username } </ h5 >
243239 ) }
244240 </ Title >
245-
246241 { /* check if the user is in login page */ }
247- { pathname === '/ login' || pathname === '/ signup' ? (
248- // showing the login page
242+ { pageName === 'login' || pageName === 'signup' ? (
243+ // showing the CrossIcon
249244 < Options >
250245 < div >
251246 < Link to = { editorLink } >
@@ -254,8 +249,9 @@ const MobileNav = () => {
254249 </ div >
255250 </ Options >
256251 ) : (
252+ // Menus for other pages
257253 < Options >
258- { /* checking if user is logged in or not */ }
254+ { pageName === 'myStuff' && < StuffMenu /> }
259255 { user . authenticated ? (
260256 < AccountMenu />
261257 ) : (
@@ -280,6 +276,39 @@ const MobileNav = () => {
280276 ) ;
281277} ;
282278
279+ const StuffMenu = ( ) => {
280+ const { isOpen, handlers } = useMenuProps ( 'stuff' ) ;
281+ const { newSketch } = useSketchActions ( ) ;
282+
283+ const [ createCollectionVisible , setCreateCollectionVisible ] = useState ( false ) ;
284+
285+ const { t } = useTranslation ( ) ;
286+
287+ return (
288+ < div >
289+ < IconButton icon = { AddIcon } { ...handlers } />
290+ < ul className = { isOpen ? 'opened' : '' } >
291+ < ParentMenuContext . Provider value = "stuff" >
292+ < NavMenuItem onClick = { ( ) => newSketch ( ) } >
293+ { t ( 'DashboardView.NewSketch' ) }
294+ </ NavMenuItem >
295+ < NavMenuItem onClick = { ( ) => setCreateCollectionVisible ( true ) } >
296+ { t ( 'DashboardView.CreateCollection' ) }
297+ </ NavMenuItem >
298+ </ ParentMenuContext . Provider >
299+ </ ul >
300+ { createCollectionVisible && (
301+ < Overlay
302+ title = { t ( 'DashboardView.CreateCollectionOverlay' ) }
303+ closeOverlay = { ( ) => setCreateCollectionVisible ( false ) }
304+ >
305+ < CollectionCreate />
306+ </ Overlay >
307+ ) }
308+ </ div >
309+ ) ;
310+ } ;
311+
283312const AccountMenu = ( ) => {
284313 const user = useSelector ( ( state ) => state . user ) ;
285314 const dispatch = useDispatch ( ) ;
0 commit comments