Skip to content

Commit 42b0025

Browse files
committed
🚧 add link to MyStuff when user is logged in
1 parent bf67451 commit 42b0025

File tree

3 files changed

+61
-10
lines changed

3 files changed

+61
-10
lines changed

client/modules/IDE/pages/MobileIDEView.jsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ const NavItem = styled.li`
4646
position: relative;
4747
`;
4848

49-
const headerNavOptions = [
50-
{ icon: PreferencesIcon, title: 'Preferences', href: '/mobile/preferences', },
51-
{ icon: PreferencesIcon, title: 'Examples', href: '/mobile/p5/sketches' },
52-
{ icon: PreferencesIcon, title: 'Original Editor', href: '/', },
53-
];
54-
55-
5649
const MobileIDEView = (props) => {
5750
const {
5851
preferences,
@@ -75,12 +68,27 @@ const MobileIDEView = (props) => {
7568
showRuntimeErrorWarning,
7669
hideRuntimeErrorWarning,
7770
startSketch,
71+
user
7872
} = props;
7973

8074
const [tmController, setTmController] = useState(null); // eslint-disable-line
8175

76+
const { username } = user;
77+
const navOptionsLoggedIn = [
78+
{ icon: PreferencesIcon, title: 'Preferences', href: '/mobile/preferences', },
79+
{ icon: PreferencesIcon, title: 'My Stuff', href: `/mobile/${username}/sketches` },
80+
{ icon: PreferencesIcon, title: 'Examples', href: '/mobile/p5/sketches' },
81+
{ icon: PreferencesIcon, title: 'Original Editor', href: '/', },
82+
];
83+
84+
const navOptionsLoggedOut = [
85+
{ icon: PreferencesIcon, title: 'Preferences', href: '/mobile/preferences', },
86+
{ icon: PreferencesIcon, title: 'Examples', href: '/mobile/p5/sketches' },
87+
{ icon: PreferencesIcon, title: 'Original Editor', href: '/', },
88+
];
89+
8290

83-
const [triggerNavDropdown, NavDropDown] = useAsModal(<Dropdown right items={headerNavOptions} />);
91+
const [triggerNavDropdown, NavDropDown] = useAsModal(<Dropdown right items={username ? navOptionsLoggedIn : navOptionsLoggedOut} />);
8492

8593
return (
8694
<Screen fullscreen>

client/routes.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,18 @@ const routes = store => (
5858
<Route path="/:username/collections/:collection_id" component={CollectionView} />
5959
<Route path="/about" component={IDEView} />
6060

61-
<Route path="/mobile/:username/sketches/:project_id" component={MobileIDEView} />
6261

63-
<Route path="/mobile/:username/sketches" component={MobileDashboard} />
6462
<Route path="/mobile/preview" component={MobileSketchView} />
6563
<Route path="/mobile/preferences" component={MobilePreferences} />
6664
<Route path="/mobile" component={MobileIDEView} />
6765

66+
<Route path="/mobile/:username/sketches" component={MobileDashboard} />
67+
<Route path="/mobile/:username/sketches/:project_id" component={MobileIDEView} />
68+
<Route path="/mobile/:username/assets" component={userIsAuthenticated(userIsAuthorized(MobileDashboard))} />
69+
<Route path="/mobile/:username/collections" component={MobileDashboard} />
70+
<Route path="/mobile/:username/collections/create" component={MobileDashboard} />
71+
<Route path="/mobile/:username/collections/:collection_id" component={CollectionView} />
72+
6873
</Route>
6974
);
7075

server/routes/server.routes.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,44 @@ if (process.env.MOBILE_ENABLED) {
162162
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
163163
));
164164
});
165+
166+
router.get('/mobile/:username/assets', (req, res) => {
167+
userExists(req.params.username, (exists) => {
168+
const isLoggedInUser = req.user && req.user.username === req.params.username;
169+
const canAccess = exists && isLoggedInUser;
170+
return canAccess ?
171+
res.send(renderIndex()) :
172+
get404Sketch(html => res.send(html));
173+
});
174+
});
175+
176+
router.get('/:username/collections/create', (req, res) => {
177+
userExists(req.params.username, (exists) => {
178+
const isLoggedInUser = req.user && req.user.username === req.params.username;
179+
const canAccess = exists && isLoggedInUser;
180+
return canAccess ?
181+
res.send(renderIndex()) :
182+
get404Sketch(html => res.send(html));
183+
});
184+
});
185+
186+
router.get('/:username/collections/create', (req, res) => {
187+
userExists(req.params.username, exists => (
188+
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
189+
));
190+
});
191+
192+
router.get('/:username/collections/:id', (req, res) => {
193+
collectionForUserExists(req.params.username, req.params.id, exists => (
194+
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
195+
));
196+
});
197+
198+
router.get('/:username/collections', (req, res) => {
199+
userExists(req.params.username, exists => (
200+
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
201+
));
202+
});
165203
}
166204

167205
export default router;

0 commit comments

Comments
 (0)