diff options
| author | Noah Loomans <noahloomans@gmail.com> | 2018-06-28 14:04:27 +0200 | 
|---|---|---|
| committer | Noah Loomans <noahloomans@gmail.com> | 2018-06-28 14:04:27 +0200 | 
| commit | ecc6e06e92f23b16817985e87b2e997b754f527d (patch) | |
| tree | 38eed15bfb8fe63113a8db7e71daf1229cb2425d /src/client/react/lib | |
| parent | 9efc432e160b429a0643c38e28140bcf42af30a7 (diff) | |
Move setWeek to an action
Diffstat (limited to 'src/client/react/lib')
| -rw-r--r-- | src/client/react/lib/getHistory.js | 12 | ||||
| -rw-r--r-- | src/client/react/lib/url.js | 18 | 
2 files changed, 24 insertions, 6 deletions
| diff --git a/src/client/react/lib/getHistory.js b/src/client/react/lib/getHistory.js index 642a9a8..5fef902 100644 --- a/src/client/react/lib/getHistory.js +++ b/src/client/react/lib/getHistory.js @@ -1,22 +1,22 @@  import { -  makeSetUser, -  makeSetWeek,    weekFromLocation,    userFromLocation, +  makeUpdatePathname, +  makeUpdateQuery,  } 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); +    const updatePathname = makeUpdatePathname(history); +    const updateQuery = makeUpdateQuery(history);      return {        user,        week, -      setUser, -      setWeek, +      updatePathname, +      updateQuery,      };    };  } diff --git a/src/client/react/lib/url.js b/src/client/react/lib/url.js index fcd3e6a..752fec2 100644 --- a/src/client/react/lib/url.js +++ b/src/client/react/lib/url.js @@ -70,3 +70,21 @@ export function makeSetWeek(history) {      history.push(`${history.location.pathname}?${query}`);    };  } + +export function makeUpdatePathname(history) { +  return function updatePathname(pathname) { +    const query = history.location.search; +    history.push(`/${pathname}${query}`); +  }; +} + +export function makeUpdateQuery(history) { +  return function updateQuery(newQuery) { +    const query = queryString.stringify({ +      ...queryString.parse(history.location.search), +      ...newQuery, +    }); + +    history.push(`${history.location.pathname}?${query}`); +  }; +} | 
