From 44a4f2c49a73a4e0579490780c8ff294f046f7cd Mon Sep 17 00:00:00 2001 From: Tran Duc Son Date: Mon, 29 Aug 2016 22:27:10 +0700 Subject: [PATCH] [Minor]: Change route: '/groups/:id' -> '/groups/:name', '/users/:id' -> '/users/:username'. --- README.md | 2 +- imports/api/groups/server/publications.js | 6 +++--- imports/api/users/server/publications.js | 4 ++++ imports/startup/client/routes.jsx | 4 ++-- imports/ui/components/group_row.jsx | 14 +++++++------- imports/ui/components/messages_content.jsx | 2 +- imports/ui/containers/group_container.jsx | 6 +++--- imports/ui/containers/user_container.jsx | 6 +++--- imports/ui/layouts/navbar.jsx | 2 +- imports/ui/pages/lobby.jsx | 2 +- 10 files changed, 26 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index e39f576..5944ddb 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ $ CLOUDINARY_KEY=ApiKey CLOUDINARY_SECRET=ApiSecret meteor --setti - [x] Remove 'restart' button - [x] Remove fixtures - [x] Clear message text input after sending -- [ ] Change route: `/groups/:id` -> `/groups/:name`, `/users/:id` -> `/users/:name` +- [x] Change route: `/groups/:id` -> `/groups/:name`, `/users/:id` -> `/users/:username` - [x] Group name: format validation and unique - [ ] Show result when approve/vote finished (Notification) - [ ] Separate events diff --git a/imports/api/groups/server/publications.js b/imports/api/groups/server/publications.js index eb084c1..e4b7516 100644 --- a/imports/api/groups/server/publications.js +++ b/imports/api/groups/server/publications.js @@ -15,7 +15,7 @@ Meteor.publish('groups.findAll', (name, page) => { return Groups.find(selector, { fields: Groups.publicFields.findAll, sort: { createdAt: -1 }, limit: GROUPS_PER_PAGE }); }); -Meteor.publish('groups.findOne', id => { - check(id, String); - return Groups.find({ _id: id }, { fields: Groups.publicFields.findOne }); +Meteor.publish('groups.findOneByName', name => { + check(name, String); + return Groups.find({ name: name }, { fields: Groups.publicFields.findOne }); }); diff --git a/imports/api/users/server/publications.js b/imports/api/users/server/publications.js index f95a393..78bde4e 100644 --- a/imports/api/users/server/publications.js +++ b/imports/api/users/server/publications.js @@ -6,3 +6,7 @@ Meteor.publish('users.findOne', id => { check(id, String); return Meteor.users.find({ _id: id }, { fields: { username: 1, brief: 1, activities: 1 } }); }); +Meteor.publish('users.findOneByUsername', username => { + check(username, String); + return Meteor.users.find({ username: username }, { fields: { username: 1, brief: 1, activities: 1 } }); +}); diff --git a/imports/startup/client/routes.jsx b/imports/startup/client/routes.jsx index 610b3e9..51f7b1c 100644 --- a/imports/startup/client/routes.jsx +++ b/imports/startup/client/routes.jsx @@ -14,9 +14,9 @@ export const renderRoutes = () => ( - + - + diff --git a/imports/ui/components/group_row.jsx b/imports/ui/components/group_row.jsx index dc919bb..5d91c27 100644 --- a/imports/ui/components/group_row.jsx +++ b/imports/ui/components/group_row.jsx @@ -19,16 +19,16 @@ export default class GroupRow extends React.Component { return ( - {group.name} + {group.name}
- Owner: {group.getOwner().username} + Owner: {group.getOwner().username}
    {group.getPlayers().map(p =>
  • - + Avatar
  • @@ -58,7 +58,7 @@ export default class GroupRow extends React.Component { } - Go to + Go to { !!Meteor.userId() && (joinedThisGroup || situation.slot != false) && !isPlaying ? !joinedThisGroup && !isPlaying ? @@ -80,12 +80,12 @@ export default class GroupRow extends React.Component { joinGroup() { const { router } = this.context; - const groupId = this.props.group._id; - join.call({ groupId: groupId }, err => { + const { group } = this.props; + join.call({ groupId: group._id }, err => { if (err) { alert(err.reason); } else { - router.push(`/groups/${groupId}`); + router.push(`/groups/${group.name}`); } }); } diff --git a/imports/ui/components/messages_content.jsx b/imports/ui/components/messages_content.jsx index e8e1c7c..ddfa64f 100644 --- a/imports/ui/components/messages_content.jsx +++ b/imports/ui/components/messages_content.jsx @@ -20,7 +20,7 @@ export default class MessagesContent extends React.Component { const otherPlayer = Meteor.userId() != m.senderId; return (
  • - +
    diff --git a/imports/ui/containers/group_container.jsx b/imports/ui/containers/group_container.jsx index f15184c..c0b63e2 100644 --- a/imports/ui/containers/group_container.jsx +++ b/imports/ui/containers/group_container.jsx @@ -3,9 +3,9 @@ import { Groups } from '../../api/groups/groups.jsx'; import { createContainer } from 'meteor/react-meteor-data'; import GroupPage from '../pages/group_page.jsx'; -export default createContainer(({ params: { id } }) => { - const group = Groups.findOne(id); - const loaded = Meteor.subscribe('groups.findOne', id).ready() && Meteor.subscribe('users.findAll').ready(); +export default createContainer(({ params: { name } }) => { + const group = Groups.findOne({ name: name }); + const loaded = Meteor.subscribe('groups.findOneByName', name).ready() && Meteor.subscribe('users.findAll').ready(); return { _user: Meteor.user(), // NOTE: Additional prop: make page automatically re-render even if user logged out group: group, diff --git a/imports/ui/containers/user_container.jsx b/imports/ui/containers/user_container.jsx index 539b3e3..16c5bff 100644 --- a/imports/ui/containers/user_container.jsx +++ b/imports/ui/containers/user_container.jsx @@ -2,11 +2,11 @@ import { Meteor } from 'meteor/meteor'; import { createContainer } from 'meteor/react-meteor-data'; import UserPage from '../pages/user_page.jsx'; -export default createContainer(({ params: { id } }) => { - const loaded = Meteor.subscribe('users.findOne', id).ready(); +export default createContainer(({ params: { username } }) => { + const loaded = Meteor.subscribe('users.findOneByUsername', username).ready(); return { _user: Meteor.user(), // NOTE: Additional prop: make page automatically re-render even if user logged out - user: Meteor.users.findOne(id), + user: Meteor.users.findOne({ username: username }), loaded: loaded, }; }, UserPage); diff --git a/imports/ui/layouts/navbar.jsx b/imports/ui/layouts/navbar.jsx index 46132ba..0e4f598 100644 --- a/imports/ui/layouts/navbar.jsx +++ b/imports/ui/layouts/navbar.jsx @@ -25,7 +25,7 @@ export default class Navbar extends React.Component { {user.username}
  • : diff --git a/imports/ui/pages/lobby.jsx b/imports/ui/pages/lobby.jsx index c763cec..b65f7cc 100644 --- a/imports/ui/pages/lobby.jsx +++ b/imports/ui/pages/lobby.jsx @@ -66,7 +66,7 @@ export default class Lobby extends React.Component { if (err) { this.setState({ error: err.reason }); } else { - router.push(`/groups/${groupId}`); + router.push(`/groups/${name}`); } }); }