import { UPDATE_URLS } from "../actions/urls"; const defaultState = { "ads": "/ads/", "items": "/items/", "tags": "/tags/", "allSites": [] } function updateURL(state, {id, name, currentSite, allSites, color, scrollingText}) { ["ads", "items", "tags"].forEach(element => { let newURL = new URL(state[element], window.location.origin); newURL.searchParams.set("site", id); state[element] = newURL.pathname + "?" + newURL.searchParams; }); state["site"] = currentSite; state["name"] = name; state["allSites"] = allSites; state["color"] = color; state["scrollingText"] = scrollingText; return state; } export default function urls(state = defaultState, action) { switch (action.type) { case UPDATE_URLS: return updateURL({...state}, action.payload); default: return state; } }