aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/lib
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-02-02 15:52:33 +0100
committerNoah Loomans <noahloomans@gmail.com>2018-02-02 15:52:33 +0100
commit30376908301dae90d40532210d382c8edc088ac6 (patch)
tree88c7d228d637f1f5381acf701b75d0fb47b4e7f4 /src/client/react/lib
parent614f1c499207a6bebe1457b5b42550c5221286ad (diff)
Get user and week from context
Diffstat (limited to 'src/client/react/lib')
-rw-r--r--src/client/react/lib/url.js24
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));
+}