-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
967667c
commit 440c5f1
Showing
5 changed files
with
58 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
import { forEach, isNil, map, none } from 'ramda' | ||
|
||
const usersElem = document.querySelector('.users') | ||
|
||
const updateUsers = presence => { | ||
const usersElem = document.querySelector('.users') | ||
usersElem.innerHTML = '' | ||
|
||
// let users = list presences with the help of a listBy function | ||
users.forEach(user => addUser(user)) | ||
const users = presence.list(userData) | ||
forEach(addUser(usersElem))(users) | ||
|
||
// implement a feature that | ||
// 1. checks if all fo the users in the present list have voted, i.e. have points values that are not nil | ||
// 2. displays the user's vote next to their name if so | ||
if (allHaveEstimated(users)) { | ||
forEach(showPoints(usersElem))(users) | ||
} | ||
} | ||
|
||
const listBy = (username, {metas: [{points}, ..._rest]}) => { | ||
// build out the listBy function so that it returns a list of users | ||
// where each user looks like this: | ||
// {username: username, points: points} | ||
} | ||
const userData = (userId, { metas: [{ points }, ..._rest]}) => ({ userId, points }) | ||
|
||
const showPoints = ({userId, points}) => { | ||
const showPoints = usersElem => ({userId, points}) => { | ||
const userElem = document.querySelector(`.${userId}.user-estimate`) | ||
userElem.innerHTML = points | ||
} | ||
|
||
const addUser = user => { | ||
const addUser = usersElem => ({userId, points}) => { | ||
const userElem = document.createElement('dt') | ||
userElem.appendChild(document.createTextNode(user.username)) | ||
userElem.appendChild(document.createTextNode(userId)) | ||
userElem.setAttribute('class', 'col-8') | ||
|
||
const estimateElem = document.createElement('dd') | ||
estimateElem.setAttribute('class', `${user.username} user-estimate col-4`) | ||
estimateElem.setAttribute('class', `${userId} user-estimate col-4`) | ||
|
||
usersElem.appendChild(userElem) | ||
usersElem.appendChild(estimateElem) | ||
} | ||
|
||
const allHaveEstimated = users => { | ||
const pointsCollection = map(({ points }) => points)(users) | ||
|
||
return none(isNil)(pointsCollection) | ||
} | ||
|
||
export default updateUsers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.