diff --git a/pages/profile.js b/pages/profile.js index c6eb074a..3e51688d 100644 --- a/pages/profile.js +++ b/pages/profile.js @@ -52,62 +52,24 @@ const STYLES_USER = css` export default class ProfilePage extends React.Component { render() { - const title = this.props.creator - ? `@${this.props.creator.username}` - : "404"; + const title = this.props.creator ? `@${this.props.creator.username}` : "404"; const url = `https://slate.host/${title}`; - - if (!this.props.creator) { - return ( - -
-

404

-

- This user is not found. -
-
- Run Slate {Constants.values.version} -
- Use Slate's Design System -

-
-
- ); - } - const description = "A user on Slate."; return ( - +
-
+

{title}

- This is an example of a profile page on Slate. Slate is going to be - really cool soon! + This is an example of a profile page on Slate. Slate is going to be really cool soon!

{this.props.creator.slates.map((row) => { - const url = `https://slate.host/@${this.props.creator.username}/${ - row.slatename - }`; + const url = `https://slate.host/@${this.props.creator.username}/${row.slatename}`; return ( - - {url} - + {url}
); @@ -118,9 +80,7 @@ export default class ProfilePage extends React.Component {
Use Slate's Design System
- - View Source ☺ - + View Source ☺

diff --git a/pages/slate.js b/pages/slate.js index d36bbc9d..d82334c1 100644 --- a/pages/slate.js +++ b/pages/slate.js @@ -35,13 +35,7 @@ export default class SlatePage extends React.Component { name: "slate-global-create-carousel", detail: { slides: this.props.slate.data.objects.map((each) => { - return ( - - ); + return ; }), }, }); @@ -54,34 +48,8 @@ export default class SlatePage extends React.Component { }); render() { - const title = this.props.slate - ? `@${this.props.slate.ownername}/${this.props.slate.slatename}` - : "404"; + const title = this.props.slate ? `@${this.props.slate.ownername}/${this.props.slate.slatename}` : "404"; const url = `https://slate.host/${title}`; - - if (!this.props.slate) { - return ( - -
- 404 -
- - This slate is not found. -
-
- Run Slate {Constants.values.version} -
- Use Slate's Design System -
-
-
- ); - } - const description = "A slate."; let image; @@ -90,17 +58,9 @@ export default class SlatePage extends React.Component { } return ( - +
- +
diff --git a/server.js b/server.js index 89ca8547..a0c6bc60 100644 --- a/server.js +++ b/server.js @@ -56,18 +56,23 @@ app.prepare().then(async () => { username: req.params.username, }); + if (!creator) { + return res.redirect("/404"); + } + + if (creator.error) { + return res.redirect("/404"); + } + const slates = await Data.getSlatesByUserId({ userId: creator.id }); return app.render(req, res, "/profile", { viewer, - creator: - creator && !creator.error - ? { - username: creator.username, - data: { photo: creator.data.photo }, - slates: JSON.parse(JSON.stringify(slates)), - } - : null, + creator: { + username: creator.username, + data: { photo: creator.data.photo }, + slates: JSON.parse(JSON.stringify(slates)), + }, }); }); @@ -76,12 +81,12 @@ app.prepare().then(async () => { slatename: req.params.slatename, }); - if (slate) { - slate.ownername = req.params.username; + if (!slate) { + return res.redirect("/404"); } return app.render(req, res, "/slate", { - slate: JSON.parse(JSON.stringify(slate)), + slate: JSON.parse(JSON.stringify({ ...slate, ownername: req.params.username })), }); });