From ecc6e06e92f23b16817985e87b2e997b754f527d Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Thu, 28 Jun 2018 14:04:27 +0200 Subject: Move setWeek to an action --- src/client/react/lib/getHistory.js | 12 ++++++------ src/client/react/lib/url.js | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) (limited to 'src/client/react/lib') 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}`); + }; +} -- cgit v1.1