🐛 fix panels not changing
This commit is contained in:
parent
e287e551a3
commit
40db915282
5 changed files with 40 additions and 37 deletions
|
@ -35,7 +35,7 @@ class App extends React.Component {
|
||||||
return (
|
return (
|
||||||
<div className="app">
|
<div className="app">
|
||||||
{/* FIXME: remove false */}
|
{/* FIXME: remove false */}
|
||||||
{false && this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && <DevTools />}
|
{this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && <DevTools />}
|
||||||
{this.props.children}
|
{this.props.children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -17,6 +17,7 @@ export function getCollections(username) {
|
||||||
} else {
|
} else {
|
||||||
url = '/collections';
|
url = '/collections';
|
||||||
}
|
}
|
||||||
|
console.log(url);
|
||||||
apiClient.get(url)
|
apiClient.get(url)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes, { string } from 'prop-types';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { withRouter } from 'react-router';
|
import { withRouter, Link } from 'react-router';
|
||||||
|
|
||||||
import Screen from '../../components/mobile/MobileScreen';
|
import Screen from '../../components/mobile/MobileScreen';
|
||||||
import Header from '../../components/mobile/Header';
|
import Header from '../../components/mobile/Header';
|
||||||
|
@ -17,7 +17,7 @@ import { SketchSearchbar } from '../IDE/components/Searchbar';
|
||||||
|
|
||||||
const EXAMPLE_USERNAME = 'p5';
|
const EXAMPLE_USERNAME = 'p5';
|
||||||
|
|
||||||
const FooterTab = styled.div`
|
const FooterTab = styled(Link)`
|
||||||
background: ${props => prop(props.selected ? 'backgroundColor' : 'MobilePanel.default.foreground')};
|
background: ${props => prop(props.selected ? 'backgroundColor' : 'MobilePanel.default.foreground')};
|
||||||
color: ${props => prop(`MobilePanel.default.${props.selected ? 'foreground' : 'background'}`)};
|
color: ${props => prop(`MobilePanel.default.${props.selected ? 'foreground' : 'background'}`)};
|
||||||
padding: ${remSize(16)};
|
padding: ${remSize(16)};
|
||||||
|
@ -44,24 +44,32 @@ const FooterTabSwitcher = styled.div`
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const Panels = {
|
const Panels = {
|
||||||
Sketches: SketchList,
|
sketches: SketchList,
|
||||||
Collections: CollectionList,
|
collections: CollectionList,
|
||||||
Assets: AssetList
|
assets: AssetList
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderPanel = (name, props) => (Component => (Component && <Component {...props} />))(Panels[name]);
|
const renderPanel = (name, props) => (Component => (Component && <Component {...props} />))(Panels[name]);
|
||||||
|
|
||||||
|
const getPanel = (pathname) => {
|
||||||
|
const pathparts = pathname ? pathname.split('/') : [];
|
||||||
|
const matches = Object.keys(Panels).map(part => part.toLowerCase()).filter(part => pathparts.includes(part));
|
||||||
|
return matches && matches.length > 0 && matches[0];
|
||||||
|
};
|
||||||
|
|
||||||
const MobileDashboard = ({ params }) => {
|
|
||||||
|
const MobileDashboard = ({ params, location }) => {
|
||||||
const Tabs = Object.keys(Panels);
|
const Tabs = Object.keys(Panels);
|
||||||
const [selected, selectTab] = useState(Tabs[0]);
|
|
||||||
|
|
||||||
// const username = 'p5';
|
|
||||||
const { username } = params;
|
const { username } = params;
|
||||||
|
const { pathname } = location;
|
||||||
|
|
||||||
const isExamples = username === EXAMPLE_USERNAME;
|
const isExamples = username === EXAMPLE_USERNAME;
|
||||||
|
|
||||||
|
const panel = getPanel(pathname);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Screen fullscreen>
|
<Screen fullscreen key={pathname}>
|
||||||
<Header slim inverted title={isExamples ? 'Examples' : 'My Stuff'}>
|
<Header slim inverted title={isExamples ? 'Examples' : 'My Stuff'}>
|
||||||
<IconButton to="/mobile" icon={ExitIcon} aria-label="Return to ide view" />
|
<IconButton to="/mobile" icon={ExitIcon} aria-label="Return to ide view" />
|
||||||
</Header>
|
</Header>
|
||||||
|
@ -71,19 +79,18 @@ const MobileDashboard = ({ params }) => {
|
||||||
<Subheader>
|
<Subheader>
|
||||||
<SketchSearchbar />
|
<SketchSearchbar />
|
||||||
</Subheader>
|
</Subheader>
|
||||||
{renderPanel(selected, { username })}
|
{renderPanel(panel, { username, key: pathname })}
|
||||||
</Content>
|
</Content>
|
||||||
|
|
||||||
<Footer>
|
<Footer>
|
||||||
{!isExamples &&
|
{!isExamples &&
|
||||||
<FooterTabSwitcher>
|
<FooterTabSwitcher>
|
||||||
{Tabs.map(tab => (
|
{Tabs.map(tab => (
|
||||||
<FooterTab
|
<FooterTab
|
||||||
key={`tab-${tab}`}
|
key={`tab-${tab}`}
|
||||||
selected={tab === selected}
|
selected={tab === panel}
|
||||||
onClick={() => selectTab(tab)}
|
to={pathname.replace(panel, tab)}
|
||||||
>
|
>
|
||||||
<h3>{(tab === 'Sketches' && username === 'p5') ? 'Examples' : tab}</h3>
|
<h3>{(isExamples && tab === 'Sketches') ? 'Examples' : tab}</h3>
|
||||||
</FooterTab>))
|
</FooterTab>))
|
||||||
}
|
}
|
||||||
</FooterTabSwitcher>
|
</FooterTabSwitcher>
|
||||||
|
@ -93,6 +100,9 @@ const MobileDashboard = ({ params }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
MobileDashboard.propTypes = {
|
MobileDashboard.propTypes = {
|
||||||
|
location: PropTypes.shape({
|
||||||
|
pathname: PropTypes.string.isRequired
|
||||||
|
}).isRequired,
|
||||||
params: PropTypes.shape({
|
params: PropTypes.shape({
|
||||||
username: PropTypes.string.isRequired
|
username: PropTypes.string.isRequired
|
||||||
})
|
})
|
||||||
|
|
|
@ -63,12 +63,11 @@ const routes = store => (
|
||||||
<Route path="/mobile/preferences" component={MobilePreferences} />
|
<Route path="/mobile/preferences" component={MobilePreferences} />
|
||||||
<Route path="/mobile" component={MobileIDEView} />
|
<Route path="/mobile" component={MobileIDEView} />
|
||||||
|
|
||||||
<Route path="/mobile/:username/sketches" component={MobileDashboardView} />
|
|
||||||
<Route path="/mobile/:username/sketches/:project_id" component={MobileIDEView} />
|
<Route path="/mobile/:username/sketches/:project_id" component={MobileIDEView} />
|
||||||
<Route path="/mobile/:username/assets" component={userIsAuthenticated(userIsAuthorized(MobileDashboardView))} />
|
<Route path="/mobile/:username/assets" component={userIsAuthenticated(userIsAuthorized(MobileDashboardView))} />
|
||||||
|
<Route path="/mobile/:username/sketches" component={MobileDashboardView} />
|
||||||
<Route path="/mobile/:username/collections" component={MobileDashboardView} />
|
<Route path="/mobile/:username/collections" component={MobileDashboardView} />
|
||||||
<Route path="/mobile/:username/collections/create" component={MobileDashboardView} />
|
<Route path="/mobile/:username/collections/create" component={MobileDashboardView} />
|
||||||
<Route path="/mobile/:username/collections/:collection_id" component={CollectionView} />
|
|
||||||
|
|
||||||
</Route>
|
</Route>
|
||||||
);
|
);
|
||||||
|
|
|
@ -7,6 +7,8 @@ import { collectionForUserExists } from '../controllers/collection.controller';
|
||||||
|
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
|
const fallback404 = res => (exists => (exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))));
|
||||||
|
|
||||||
// this is intended to be a temporary file
|
// this is intended to be a temporary file
|
||||||
// until i figure out isomorphic rendering
|
// until i figure out isomorphic rendering
|
||||||
|
|
||||||
|
@ -152,15 +154,11 @@ if (process.env.MOBILE_ENABLED) {
|
||||||
router.get('/mobile/preferences', (req, res) => res.send(renderIndex()));
|
router.get('/mobile/preferences', (req, res) => res.send(renderIndex()));
|
||||||
|
|
||||||
router.get('/mobile/:username/sketches', (req, res) => {
|
router.get('/mobile/:username/sketches', (req, res) => {
|
||||||
userExists(req.params.username, exists => (
|
userExists(req.params.username, fallback404(res));
|
||||||
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
|
|
||||||
));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/mobile/:username/sketches/:project_id', (req, res) => {
|
router.get('/mobile/:username/sketches/:project_id', (req, res) => {
|
||||||
projectForUserExists(req.params.username, req.params.project_id, exists => (
|
projectForUserExists(req.params.username, req.params.project_id, fallback404(res));
|
||||||
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
|
|
||||||
));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/mobile/:username/assets', (req, res) => {
|
router.get('/mobile/:username/assets', (req, res) => {
|
||||||
|
@ -173,7 +171,7 @@ if (process.env.MOBILE_ENABLED) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/:username/collections/create', (req, res) => {
|
router.get('/mobile/:username/collections/create', (req, res) => {
|
||||||
userExists(req.params.username, (exists) => {
|
userExists(req.params.username, (exists) => {
|
||||||
const isLoggedInUser = req.user && req.user.username === req.params.username;
|
const isLoggedInUser = req.user && req.user.username === req.params.username;
|
||||||
const canAccess = exists && isLoggedInUser;
|
const canAccess = exists && isLoggedInUser;
|
||||||
|
@ -183,22 +181,17 @@ if (process.env.MOBILE_ENABLED) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/:username/collections/create', (req, res) => {
|
|
||||||
userExists(req.params.username, exists => (
|
router.get('/mobile/:username/collections', (req, res) => {
|
||||||
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
|
userExists(req.params.username, fallback404(res));
|
||||||
));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/:username/collections/:id', (req, res) => {
|
router.get('/mobile/:username/collections/create', (req, res) => {
|
||||||
collectionForUserExists(req.params.username, req.params.id, exists => (
|
userExists(req.params.username, fallback404(res));
|
||||||
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
|
|
||||||
));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/:username/collections', (req, res) => {
|
router.get('/mobile/:username/collections/:id', (req, res) => {
|
||||||
userExists(req.params.username, exists => (
|
collectionForUserExists(req.params.username, req.params.id, fallback404(res));
|
||||||
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
|
|
||||||
));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue