Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort queues and courses by name #144

Merged
merged 4 commits into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ with the current date and the next changes should go under a **[Next]** header.

* Add open and closed cards to course pages. ([@genevievehelsel](https://github.com/genevievehelsel) in [#142](https://github.com/illinois/queue/pull/142))
* Upgrade to Next 7 and React 16.5.2. ([@nwalters512](https://github.com/nwalters512) in [#143](https://github.com/illinois/queue/pull/143))
* Sort queues and courses by name. ([@genevievehelsel](https://github.com/genevievehelsel) in [#144](https://github.com/illinois/queue/pull/144))

## 5 September 2018

Expand Down
16 changes: 16 additions & 0 deletions src/components/QueueCardList.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ class QueueCardList extends React.Component {
}))
}

queueSorter(l, r) {
const queueL = this.props.queues[l]
const queueR = this.props.queues[r]
const courseNameL = this.props.courses[queueL.courseId].name
const courseNameR = this.props.courses[queueR.courseId].name

if (courseNameL === courseNameR) {
return queueL.name > queueR.name
}

return courseNameL > courseNameR
}

render() {
const CardCol = ({ children, ...rest }) => (
<Col
Expand All @@ -86,6 +99,9 @@ class QueueCardList extends React.Component {
const handleQueueClick = id => {
Router.pushRoute('queue', { id })
}

this.props.queueIds.sort(this.queueSorter.bind(this))

queues = this.props.queueIds.map(queueId => {
const queue = this.props.queues[queueId]
const courseName = this.props.courses[queue.courseId].name
Expand Down
4 changes: 3 additions & 1 deletion src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ const mapStateToProps = state => ({
showCreateQueueButton:
state.user.user &&
(state.user.user.isAdmin || state.user.user.staffAssignments.length > 0),
courses: mapObjectToArray(state.courses.courses),
courses: mapObjectToArray(state.courses.courses).sort((a, b) => {
return a.name > b.name
}),
queues: mapObjectToArray(state.queues.queues),
})

Expand Down