diff options
author | Noah Loomans <noahloomans@gmail.com> | 2018-02-02 15:52:33 +0100 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2018-02-02 15:52:33 +0100 |
commit | 30376908301dae90d40532210d382c8edc088ac6 (patch) | |
tree | 88c7d228d637f1f5381acf701b75d0fb47b4e7f4 /src/client/react/lib | |
parent | 614f1c499207a6bebe1457b5b42550c5221286ad (diff) |
Get user and week from context
Diffstat (limited to 'src/client/react/lib')
-rw-r--r-- | src/client/react/lib/url.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/client/react/lib/url.js b/src/client/react/lib/url.js new file mode 100644 index 0000000..3b7f6b4 --- /dev/null +++ b/src/client/react/lib/url.js @@ -0,0 +1,24 @@ +import moment from 'moment'; +import queryString from 'query-string'; +import users from '../users'; +import purifyWeek from './purifyWeek'; + +export function userFromMatch(match) { + const user = `${match.params.type}/${match.params.value}`; + + if (!users.allIds.includes(user)) { + return null; + } + + return user; +} + +export function weekFromLocation(location) { + const weekStr = queryString.parse(location.search).week; + + if (!weekStr) { + return moment().week(); + } + + return purifyWeek(parseInt(weekStr, 10)); +} |