Skip to content

Commit 40db915

Browse files
committed
🐛 fix panels not changing
1 parent e287e55 commit 40db915

File tree

5 files changed

+40
-37
lines changed

5 files changed

+40
-37
lines changed

client/modules/App/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class App extends React.Component {
3535
return (
3636
<div className="app">
3737
{/* FIXME: remove false */}
38-
{false && this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && <DevTools />}
38+
{this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && <DevTools />}
3939
{this.props.children}
4040
</div>
4141
);

client/modules/IDE/actions/collections.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export function getCollections(username) {
1717
} else {
1818
url = '/collections';
1919
}
20+
console.log(url);
2021
apiClient.get(url)
2122
.then((response) => {
2223
dispatch({

client/modules/Mobile/MobileDashboardView.jsx

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState } from 'react';
2-
import PropTypes from 'prop-types';
2+
import PropTypes, { string } from 'prop-types';
33
import styled from 'styled-components';
4-
import { withRouter } from 'react-router';
4+
import { withRouter, Link } from 'react-router';
55

66
import Screen from '../../components/mobile/MobileScreen';
77
import Header from '../../components/mobile/Header';
@@ -17,7 +17,7 @@ import { SketchSearchbar } from '../IDE/components/Searchbar';
1717

1818
const EXAMPLE_USERNAME = 'p5';
1919

20-
const FooterTab = styled.div`
20+
const FooterTab = styled(Link)`
2121
background: ${props => prop(props.selected ? 'backgroundColor' : 'MobilePanel.default.foreground')};
2222
color: ${props => prop(`MobilePanel.default.${props.selected ? 'foreground' : 'background'}`)};
2323
padding: ${remSize(16)};
@@ -44,24 +44,32 @@ const FooterTabSwitcher = styled.div`
4444
`;
4545

4646
const Panels = {
47-
Sketches: SketchList,
48-
Collections: CollectionList,
49-
Assets: AssetList
47+
sketches: SketchList,
48+
collections: CollectionList,
49+
assets: AssetList
5050
};
5151

5252
const renderPanel = (name, props) => (Component => (Component && <Component {...props} />))(Panels[name]);
5353

54+
const getPanel = (pathname) => {
55+
const pathparts = pathname ? pathname.split('/') : [];
56+
const matches = Object.keys(Panels).map(part => part.toLowerCase()).filter(part => pathparts.includes(part));
57+
return matches && matches.length > 0 && matches[0];
58+
};
59+
5460

55-
const MobileDashboard = ({ params }) => {
61+
const MobileDashboard = ({ params, location }) => {
5662
const Tabs = Object.keys(Panels);
57-
const [selected, selectTab] = useState(Tabs[0]);
5863

59-
// const username = 'p5';
6064
const { username } = params;
65+
const { pathname } = location;
66+
6167
const isExamples = username === EXAMPLE_USERNAME;
6268

69+
const panel = getPanel(pathname);
70+
6371
return (
64-
<Screen fullscreen>
72+
<Screen fullscreen key={pathname}>
6573
<Header slim inverted title={isExamples ? 'Examples' : 'My Stuff'}>
6674
<IconButton to="/mobile" icon={ExitIcon} aria-label="Return to ide view" />
6775
</Header>
@@ -71,19 +79,18 @@ const MobileDashboard = ({ params }) => {
7179
<Subheader>
7280
<SketchSearchbar />
7381
</Subheader>
74-
{renderPanel(selected, { username })}
82+
{renderPanel(panel, { username, key: pathname })}
7583
</Content>
76-
7784
<Footer>
7885
{!isExamples &&
7986
<FooterTabSwitcher>
8087
{Tabs.map(tab => (
8188
<FooterTab
8289
key={`tab-${tab}`}
83-
selected={tab === selected}
84-
onClick={() => selectTab(tab)}
90+
selected={tab === panel}
91+
to={pathname.replace(panel, tab)}
8592
>
86-
<h3>{(tab === 'Sketches' && username === 'p5') ? 'Examples' : tab}</h3>
93+
<h3>{(isExamples && tab === 'Sketches') ? 'Examples' : tab}</h3>
8794
</FooterTab>))
8895
}
8996
</FooterTabSwitcher>
@@ -93,6 +100,9 @@ const MobileDashboard = ({ params }) => {
93100
};
94101

95102
MobileDashboard.propTypes = {
103+
location: PropTypes.shape({
104+
pathname: PropTypes.string.isRequired
105+
}).isRequired,
96106
params: PropTypes.shape({
97107
username: PropTypes.string.isRequired
98108
})

client/routes.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,11 @@ const routes = store => (
6363
<Route path="/mobile/preferences" component={MobilePreferences} />
6464
<Route path="/mobile" component={MobileIDEView} />
6565

66-
<Route path="/mobile/:username/sketches" component={MobileDashboardView} />
6766
<Route path="/mobile/:username/sketches/:project_id" component={MobileIDEView} />
6867
<Route path="/mobile/:username/assets" component={userIsAuthenticated(userIsAuthorized(MobileDashboardView))} />
68+
<Route path="/mobile/:username/sketches" component={MobileDashboardView} />
6969
<Route path="/mobile/:username/collections" component={MobileDashboardView} />
7070
<Route path="/mobile/:username/collections/create" component={MobileDashboardView} />
71-
<Route path="/mobile/:username/collections/:collection_id" component={CollectionView} />
7271

7372
</Route>
7473
);

server/routes/server.routes.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { collectionForUserExists } from '../controllers/collection.controller';
77

88
const router = new Router();
99

10+
const fallback404 = res => (exists => (exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))));
11+
1012
// this is intended to be a temporary file
1113
// until i figure out isomorphic rendering
1214

@@ -152,15 +154,11 @@ if (process.env.MOBILE_ENABLED) {
152154
router.get('/mobile/preferences', (req, res) => res.send(renderIndex()));
153155

154156
router.get('/mobile/:username/sketches', (req, res) => {
155-
userExists(req.params.username, exists => (
156-
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
157-
));
157+
userExists(req.params.username, fallback404(res));
158158
});
159159

160160
router.get('/mobile/:username/sketches/:project_id', (req, res) => {
161-
projectForUserExists(req.params.username, req.params.project_id, exists => (
162-
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
163-
));
161+
projectForUserExists(req.params.username, req.params.project_id, fallback404(res));
164162
});
165163

166164
router.get('/mobile/:username/assets', (req, res) => {
@@ -173,7 +171,7 @@ if (process.env.MOBILE_ENABLED) {
173171
});
174172
});
175173

176-
router.get('/:username/collections/create', (req, res) => {
174+
router.get('/mobile/:username/collections/create', (req, res) => {
177175
userExists(req.params.username, (exists) => {
178176
const isLoggedInUser = req.user && req.user.username === req.params.username;
179177
const canAccess = exists && isLoggedInUser;
@@ -183,22 +181,17 @@ if (process.env.MOBILE_ENABLED) {
183181
});
184182
});
185183

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-
));
184+
185+
router.get('/mobile/:username/collections', (req, res) => {
186+
userExists(req.params.username, fallback404(res));
190187
});
191188

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-
));
189+
router.get('/mobile/:username/collections/create', (req, res) => {
190+
userExists(req.params.username, fallback404(res));
196191
});
197192

198-
router.get('/:username/collections', (req, res) => {
199-
userExists(req.params.username, exists => (
200-
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
201-
));
193+
router.get('/mobile/:username/collections/:id', (req, res) => {
194+
collectionForUserExists(req.params.username, req.params.id, fallback404(res));
202195
});
203196
}
204197

0 commit comments

Comments
 (0)