From 9595b1707d942333c5f750f55f3dc864339eb841 Mon Sep 17 00:00:00 2001 From: 6ea86b96 <6ea86b96@gmail.com> Date: Fri, 23 Jun 2017 03:11:52 +0700 Subject: [PATCH] Fix refreshing --- ui/js/actions/app.js | 5 +---- ui/js/main.js | 21 +++++++++++---------- ui/js/reducers/app.js | 8 +++++++- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/ui/js/actions/app.js b/ui/js/actions/app.js index 9f6214d39..669ce0010 100644 --- a/ui/js/actions/app.js +++ b/ui/js/actions/app.js @@ -67,11 +67,8 @@ export function doHistoryBack() { export function doHistoryPush(params, title, relativeUrl) { return function(dispatch, getState) { - let pathParts = window.location.pathname.split("/"); - pathParts[pathParts.length - 1] = relativeUrl.replace(/^\//, ""); - const url = pathParts.join("/"); title += " - LBRY"; - history.pushState(params, title, url); + history.pushState(params, title, `#${relativeUrl}`); }; } diff --git a/ui/js/main.js b/ui/js/main.js index 78eceb235..331eccc11 100644 --- a/ui/js/main.js +++ b/ui/js/main.js @@ -28,19 +28,20 @@ window.addEventListener("contextmenu", event => { }); window.addEventListener("popstate", (event, param) => { - const params = event.state; - const pathParts = document.location.pathname.split("/"); - const route = "/" + pathParts[pathParts.length - 1]; - const queryString = toQueryString(params); + event.preventDefault(); + const hash = document.location.hash; let action; - if (route.match(/html$/)) { - action = doChangePath("/discover"); - } else { - action = doChangePath(`${route}?${queryString}`); - } - app.store.dispatch(action); + if (hash !== "") { + const url = hash.split("#")[1]; + const params = event.state; + const queryString = toQueryString(params); + + app.store.dispatch(doChangePath(`${url}?${queryString}`)); + } else { + app.store.dispatch(doChangePath("/discover")); + } }); ipcRenderer.on("open-uri-requested", (event, uri) => { diff --git a/ui/js/reducers/app.js b/ui/js/reducers/app.js index d5c95bde5..2a638ede4 100644 --- a/ui/js/reducers/app.js +++ b/ui/js/reducers/app.js @@ -1,10 +1,16 @@ import * as types from "constants/action_types"; import lbry from "lbry"; +const currentPath = () => { + const hash = document.location.hash; + if (hash !== "") return hash.split("#")[1]; + else return "/discover"; +}; + const reducers = {}; const defaultState = { isLoaded: false, - currentPath: "discover", + currentPath: currentPath(), platform: process.platform, upgradeSkipped: sessionStorage.getItem("upgradeSkipped"), daemonReady: false,