attempt to disable back/forward buttons

This commit is contained in:
Jeremy Kauffman 2017-08-15 19:29:55 -04:00
parent 86b4f8e82c
commit 22fbf13715
7 changed files with 54 additions and 16 deletions

View file

@ -14,7 +14,6 @@ Web UI version numbers should always match the corresponding version of LBRY App
* *
### Changed ### Changed
* Updated to daemon [0.15](https://github.com/lbryio/lbry/releases). Most relevant changes for app are improved announcing of content and a fix for the daemon getting stuck running.
* Some form field refactoring as we progress towards form sanity. * Some form field refactoring as we progress towards form sanity.
* When an "Open" button is clicked on a show page, if the file fails to open, the app will try to open the file's folder. * When an "Open" button is clicked on a show page, if the file fails to open, the app will try to open the file's folder.
* Removed confusing placeholder text from email input * Removed confusing placeholder text from email input

View file

@ -1,6 +1,8 @@
import * as types from "constants/action_types"; import * as types from "constants/action_types";
import lbry from "lbry"; import lbry from "lbry";
import { import {
selectIsBackDisabled,
selectIsForwardDisabled,
selectUpdateUrl, selectUpdateUrl,
selectUpgradeDownloadPath, selectUpgradeDownloadPath,
selectUpgradeDownloadItem, selectUpgradeDownloadItem,
@ -31,7 +33,7 @@ export function doNavigate(path, params = {}, options = {}) {
const state = getState(); const state = getState();
const pageTitle = selectPageTitle(state); const pageTitle = selectPageTitle(state);
dispatch(doHistoryPush({ params }, pageTitle, url)); dispatch(doHistoryPush({ params, is_last_page: true }, pageTitle, url));
}; };
} }
@ -77,18 +79,19 @@ export function doChangePath(path, options = {}) {
export function doHistoryBack() { export function doHistoryBack() {
return function(dispatch, getState) { return function(dispatch, getState) {
if (!history.state) return; if (!selectIsBackDisabled(getState())) {
if (history.state.index === 0) return; history.back();
dispatch({ type: types.HISTORY_NAVIGATE });
history.back(); }
}; };
} }
export function doHistoryForward() { export function doHistoryForward() {
return function(dispatch, getState) { return function(dispatch, getState) {
if (!history.state) return; if (!selectIsForwardDisabled(getState())) {
history.forward();
history.forward(); dispatch({ type: types.HISTORY_NAVIGATE });
}
}; };
} }
@ -96,6 +99,7 @@ export function doHistoryPush(currentState, title, relativeUrl) {
return function(dispatch, getState) { return function(dispatch, getState) {
title += " - LBRY"; title += " - LBRY";
history.pushState(currentState, title, `#${relativeUrl}`); history.pushState(currentState, title, `#${relativeUrl}`);
dispatch({ type: types.HISTORY_NAVIGATE });
}; };
} }
@ -274,7 +278,11 @@ export function doDaemonReady() {
return function(dispatch, getState) { return function(dispatch, getState) {
const path = window.location.hash || "#/discover"; const path = window.location.hash || "#/discover";
const params = parseQueryParams(path.split("?")[1] || ""); const params = parseQueryParams(path.split("?")[1] || "");
history.replaceState({ params, index: 0 }, document.title, `${path}`); history.replaceState(
{ params, is_first_page: true },
document.title,
`${path}`
);
dispatch(doAuthenticate()); dispatch(doAuthenticate());
dispatch({ dispatch({
type: types.DAEMON_READY, type: types.DAEMON_READY,

View file

@ -1,11 +1,14 @@
import React from "react"; import React from "react";
import { formatCredits } from "utils"; import { formatCredits } from "utils";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { selectIsBackDisabled, selectIsForwardDisabled } from "selectors/app";
import { selectBalance } from "selectors/wallet"; import { selectBalance } from "selectors/wallet";
import { doNavigate, doHistoryBack, doHistoryForward } from "actions/app"; import { doNavigate, doHistoryBack, doHistoryForward } from "actions/app";
import Header from "./view"; import Header from "./view";
const select = state => ({ const select = state => ({
isBackDisabled: selectIsBackDisabled(state),
isForwardDisabled: selectIsForwardDisabled(state),
balance: formatCredits(selectBalance(state), 1), balance: formatCredits(selectBalance(state), 1),
publish: __("Publish"), publish: __("Publish"),
}); });

View file

@ -3,13 +3,22 @@ import Link from "component/link";
import WunderBar from "component/wunderbar"; import WunderBar from "component/wunderbar";
export const Header = props => { export const Header = props => {
const { balance, back, forward, navigate, publish } = props; const {
balance,
back,
forward,
isBackDisabled,
isForwardDisabled,
navigate,
publish,
} = props;
console.log(props);
return ( return (
<header id="header"> <header id="header">
<div className="header__item"> <div className="header__item">
<Link <Link
onClick={back} onClick={back}
disabled={isBackDisabled}
button="alt button--flat" button="alt button--flat"
icon="icon-arrow-left" icon="icon-arrow-left"
title={__("Back")} title={__("Back")}
@ -18,6 +27,7 @@ export const Header = props => {
<div className="header__item"> <div className="header__item">
<Link <Link
onClick={forward} onClick={forward}
disabled={isForwardDisabled}
button="alt button--flat" button="alt button--flat"
icon="icon-arrow-right" icon="icon-arrow-right"
title={__("Forward")} title={__("Forward")}

View file

@ -1,7 +1,7 @@
export const CHANGE_PATH = "CHANGE_PATH"; export const CHANGE_PATH = "CHANGE_PATH";
export const OPEN_MODAL = "OPEN_MODAL"; export const OPEN_MODAL = "OPEN_MODAL";
export const CLOSE_MODAL = "CLOSE_MODAL"; export const CLOSE_MODAL = "CLOSE_MODAL";
export const HISTORY_BACK = "HISTORY_BACK"; export const HISTORY_NAVIGATE = "HISTORY_NAVIGATE";
export const SHOW_SNACKBAR = "SHOW_SNACKBAR"; export const SHOW_SNACKBAR = "SHOW_SNACKBAR";
export const REMOVE_SNACKBAR_SNACK = "REMOVE_SNACKBAR_SNACK"; export const REMOVE_SNACKBAR_SNACK = "REMOVE_SNACKBAR_SNACK";
export const WINDOW_FOCUSED = "WINDOW_FOCUSED"; export const WINDOW_FOCUSED = "WINDOW_FOCUSED";
@ -112,5 +112,4 @@ export const CLAIM_REWARD_STARTED = "CLAIM_REWARD_STARTED";
export const CLAIM_REWARD_SUCCESS = "CLAIM_REWARD_SUCCESS"; export const CLAIM_REWARD_SUCCESS = "CLAIM_REWARD_SUCCESS";
export const CLAIM_REWARD_FAILURE = "CLAIM_REWARD_FAILURE"; export const CLAIM_REWARD_FAILURE = "CLAIM_REWARD_FAILURE";
export const CLAIM_REWARD_CLEAR_ERROR = "CLAIM_REWARD_CLEAR_ERROR"; export const CLAIM_REWARD_CLEAR_ERROR = "CLAIM_REWARD_CLEAR_ERROR";
export const FETCH_REWARD_CONTENT_COMPLETED = export const FETCH_REWARD_CONTENT_COMPLETED = "FETCH_REWARD_CONTENT_COMPLETED";
"FETCH_REWARD_CONTENT_COMPLETED";

View file

@ -1,6 +1,5 @@
import * as types from "constants/action_types"; import * as types from "constants/action_types";
import * as modalTypes from "constants/modal_types"; import * as modalTypes from "constants/modal_types";
import lbry from "lbry";
const currentPath = () => { const currentPath = () => {
const hash = document.location.hash; const hash = document.location.hash;
@ -15,6 +14,8 @@ const win = remote.BrowserWindow.getFocusedWindow();
const reducers = {}; const reducers = {};
const defaultState = { const defaultState = {
isLoaded: false, isLoaded: false,
isBackDisabled: true,
isForwardDisabled: true,
currentPath: currentPath(), currentPath: currentPath(),
pathAfterAuth: "/discover", pathAfterAuth: "/discover",
platform: process.platform, platform: process.platform,
@ -47,6 +48,7 @@ reducers[types.DAEMON_VERSION_MISMATCH] = function(state, action) {
reducers[types.CHANGE_PATH] = function(state, action) { reducers[types.CHANGE_PATH] = function(state, action) {
return Object.assign({}, state, { return Object.assign({}, state, {
currentPath: action.data.path, currentPath: action.data.path,
isForwardDisabled: !action.data.isBack,
}); });
}; };
@ -163,6 +165,13 @@ reducers[types.WINDOW_FOCUSED] = function(state, action) {
}); });
}; };
reducers[types.HISTORY_NAVIGATE] = (state, action) => {
return Object.assign({}, state, {
isBackDisabled: !history.state || history.state.is_first_page === true,
isForwardDisabled: !history.state,
});
};
export default function reducer(state = defaultState, action) { export default function reducer(state = defaultState, action) {
const handler = reducers[action.type]; const handler = reducers[action.type];
if (handler) return handler(state, action); if (handler) return handler(state, action);

View file

@ -216,3 +216,13 @@ export const selectPathAfterAuth = createSelector(
_selectState, _selectState,
state => state.pathAfterAuth state => state.pathAfterAuth
); );
export const selectIsBackDisabled = createSelector(
_selectState,
state => state.isBackDisabled
);
export const selectIsForwardDisabled = createSelector(
_selectState,
state => state.isForwardDisabled
);