aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/react/lib')
-rw-r--r--src/client/react/lib/getHistory.js22
-rw-r--r--src/client/react/lib/url.js10
2 files changed, 32 insertions, 0 deletions
diff --git a/src/client/react/lib/getHistory.js b/src/client/react/lib/getHistory.js
new file mode 100644
index 0000000..642a9a8
--- /dev/null
+++ b/src/client/react/lib/getHistory.js
@@ -0,0 +1,22 @@
+import {
+ makeSetUser,
+ makeSetWeek,
+ weekFromLocation,
+ userFromLocation,
+} from './url';
+
+export default function makeGetHistory(history) {
+ return function getHistory() {
+ const user = userFromLocation(history.location);
+ const week = weekFromLocation(history.location);
+ const setUser = makeSetUser(history);
+ const setWeek = makeSetWeek(history);
+
+ return {
+ user,
+ week,
+ setUser,
+ setWeek,
+ };
+ };
+}
diff --git a/src/client/react/lib/url.js b/src/client/react/lib/url.js
index 644fd74..fcd3e6a 100644
--- a/src/client/react/lib/url.js
+++ b/src/client/react/lib/url.js
@@ -33,6 +33,16 @@ export function userFromMatch(match) {
return user;
}
+export function userFromLocation(location) {
+ const match = location.pathname.match(/^\/([stcr])\/([-0-9a-zA-Z]+)/);
+ if (!match) return null;
+
+ const user = `${match[1]}/${match[2]}`;
+ if (!users.allIds.includes(user)) return null;
+
+ return user;
+}
+
export function weekFromLocation(location) {
const weekStr = queryString.parse(location.search).week;