From bca59a6233a452a8f0d92f37f844c0ae24f0ca88 Mon Sep 17 00:00:00 2001 From: catarak Date: Wed, 17 Aug 2016 15:53:25 -0400 Subject: [PATCH] add /:username/sketches links to username sketches --- client/modules/IDE/actions/projects.js | 10 ++++++++-- client/modules/IDE/components/SketchList.js | 5 +++-- client/modules/IDE/pages/IDEView.js | 7 ++++--- client/routes.js | 1 + client/styles/components/_sketch-list.scss | 2 +- server/controllers/project.controller.js | 17 +++++++++++++++++ server/routes/project.routes.js | 2 ++ server/routes/server.routes.js | 4 ++++ 8 files changed, 40 insertions(+), 8 deletions(-) diff --git a/client/modules/IDE/actions/projects.js b/client/modules/IDE/actions/projects.js index d1898d77..c5f3c7a4 100644 --- a/client/modules/IDE/actions/projects.js +++ b/client/modules/IDE/actions/projects.js @@ -4,9 +4,15 @@ import axios from 'axios'; const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api'; -export function getProjects() { +export function getProjects(username) { return (dispatch) => { - axios.get(`${ROOT_URL}/projects`, { withCredentials: true }) + let url; + if (username) { + url = `${ROOT_URL}/${username}/projects`; + } else { + url = `${ROOT_URL}/projects`; + } + axios.get(url, { withCredentials: true }) .then(response => { dispatch({ type: ActionTypes.SET_PROJECTS, diff --git a/client/modules/IDE/components/SketchList.js b/client/modules/IDE/components/SketchList.js index 5d2a759e..6955090e 100644 --- a/client/modules/IDE/components/SketchList.js +++ b/client/modules/IDE/components/SketchList.js @@ -10,7 +10,7 @@ const exitUrl = require('../../../images/exit.svg'); class SketchList extends React.Component { componentDidMount() { - this.props.getProjects(); + this.props.getProjects(this.props.username); } render() { @@ -51,7 +51,8 @@ SketchList.propTypes = { user: PropTypes.object.isRequired, getProjects: PropTypes.func.isRequired, sketches: PropTypes.array.isRequired, - closeSketchList: PropTypes.func.isRequired + closeSketchList: PropTypes.func.isRequired, + username: PropTypes.string }; function mapStateToProps(state) { diff --git a/client/modules/IDE/pages/IDEView.js b/client/modules/IDE/pages/IDEView.js index 034c797b..258db9af 100644 --- a/client/modules/IDE/pages/IDEView.js +++ b/client/modules/IDE/pages/IDEView.js @@ -235,10 +235,10 @@ class IDEView extends React.Component { return ''; })()} {(() => { // eslint-disable-line - if (this.props.location.pathname === '/sketches') { + if (this.props.location.pathname.match(/sketches$/)) { return ( - + ); } @@ -251,7 +251,8 @@ class IDEView extends React.Component { IDEView.propTypes = { params: PropTypes.shape({ - project_id: PropTypes.string + project_id: PropTypes.string, + username: PropTypes.string }), location: PropTypes.shape({ pathname: PropTypes.string diff --git a/client/routes.js b/client/routes.js index 356a27da..051de716 100644 --- a/client/routes.js +++ b/client/routes.js @@ -19,6 +19,7 @@ const routes = (store) => + ); diff --git a/client/styles/components/_sketch-list.scss b/client/styles/components/_sketch-list.scss index 4780b12a..47bba3a8 100644 --- a/client/styles/components/_sketch-list.scss +++ b/client/styles/components/_sketch-list.scss @@ -13,7 +13,7 @@ width: 100%; padding: #{10 / $base-font-size}rem 0; padding-left: #{20 / $base-font-size}rem; - height: 100%; + max-height: 100%; } .sketches-table__row { diff --git a/server/controllers/project.controller.js b/server/controllers/project.controller.js index cdbfd650..ee749da4 100644 --- a/server/controllers/project.controller.js +++ b/server/controllers/project.controller.js @@ -1,4 +1,5 @@ import Project from '../models/project'; +import User from '../models/user'; export function createProject(req, res) { let projectValues = { @@ -56,3 +57,19 @@ export function getProjects(req, res) { } } + +export function getProjectsForUser(req, res) { + if (req.params.username) { + User.findOne({ username: req.params.username }, (err, user) => { + Project.find({user: user._id}) // eslint-disable-line no-underscore-dangle + .sort('-createdAt') + .select('name files id createdAt updatedAt') + .exec((err, projects) => { + res.json(projects); + }); + }); + } else { + // could just move this to client side + return res.json([]); + } +} diff --git a/server/routes/project.routes.js b/server/routes/project.routes.js index ee8f4654..36bef1b6 100644 --- a/server/routes/project.routes.js +++ b/server/routes/project.routes.js @@ -11,4 +11,6 @@ router.route('/projects/:project_id').get(ProjectController.getProject); router.route('/projects').get(ProjectController.getProjects); +router.route('/:username/projects').get(ProjectController.getProjectsForUser); + export default router; diff --git a/server/routes/server.routes.js b/server/routes/server.routes.js index 90dda69d..afb596ba 100644 --- a/server/routes/server.routes.js +++ b/server/routes/server.routes.js @@ -25,4 +25,8 @@ router.route('/sketches').get((req, res) => { res.sendFile(path.resolve(`${__dirname}/../../index.html`)); }); +router.route('/:username/sketches').get((req, res) => { + res.sendFile(path.resolve(`${__dirname}/../../index.html`)); +}); + export default router;