Update code according to code review.
This commit is contained in:
parent
e0aa6e3646
commit
a578a6b31d
7 changed files with 29 additions and 42 deletions
|
@ -13,13 +13,15 @@ import { doBalanceSubscribe } from "actions/wallet";
|
|||
import { doAuthenticate } from "actions/user";
|
||||
import { doFetchFileInfosAndPublishedClaims } from "actions/file_info";
|
||||
import * as modals from "constants/modal_types";
|
||||
import { selectBalance } from "../selectors/wallet";
|
||||
import { doFetchRewardedContent } from "actions/content";
|
||||
import { selectCurrentModal } from "../selectors/app";
|
||||
|
||||
const { remote, ipcRenderer, shell } = require("electron");
|
||||
const path = require("path");
|
||||
const { download } = remote.require("electron-dl");
|
||||
const fs = remote.require("fs");
|
||||
const { lbrySettings: config } = require("../../../app/package.json");
|
||||
const CHECK_UPGRADE_INTERVAL = 10 * 60 * 1000;
|
||||
|
||||
export function doOpenModal(modal, modalProps = {}) {
|
||||
return {
|
||||
|
@ -131,21 +133,21 @@ export function doCheckUpgradeAvailable() {
|
|||
return function(dispatch, getState) {
|
||||
const state = getState();
|
||||
dispatch({
|
||||
type: types.CHECK_UPGRADE_STARTED,
|
||||
type: types.CHECK_UPGRADE_START,
|
||||
});
|
||||
|
||||
const success = ({ remoteVersion, upgradeAvailable }) => {
|
||||
dispatch({
|
||||
type: types.CHECK_UPGRADE_COMPLETED,
|
||||
type: types.CHECK_UPGRADE_SUCCESS,
|
||||
data: {
|
||||
upgradeAvailable,
|
||||
remoteVersion,
|
||||
},
|
||||
});
|
||||
|
||||
// If there's an available upgrade and the user hasn't skipped it or if there's a newer one, show un upgrade modal
|
||||
if (
|
||||
upgradeAvailable &&
|
||||
!selectCurrentModal(state) &&
|
||||
(!selectIsUpgradeSkipped(state) ||
|
||||
remoteVersion !== selectRemoteVersion(state))
|
||||
) {
|
||||
|
@ -158,27 +160,27 @@ export function doCheckUpgradeAvailable() {
|
|||
}
|
||||
};
|
||||
|
||||
const failure = () => {
|
||||
const fail = () => {
|
||||
dispatch({
|
||||
type: types.CHECK_UPGRADE_FAILED,
|
||||
type: types.CHECK_UPGRADE_FAIL,
|
||||
});
|
||||
};
|
||||
|
||||
lbry.getAppVersionInfo().then(success, failure);
|
||||
lbry.getAppVersionInfo().then(success, fail);
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
Initiate a timer that will check for an app upgrade every 10 minutes.
|
||||
*/
|
||||
export function doInitCheckUpgradeTimer() {
|
||||
export function doCheckUpgradeSubscribe() {
|
||||
return function(dispatch) {
|
||||
const checkUpgradeTimer = setInterval(
|
||||
() => dispatch(doCheckUpgradeAvailable()),
|
||||
600000
|
||||
CHECK_UPGRADE_INTERVAL
|
||||
);
|
||||
dispatch({
|
||||
type: types.CHECK_UPGRADE_TIMER_INITIATED,
|
||||
type: types.CHECK_UPGRADE_SUBSCRIBE,
|
||||
data: { checkUpgradeTimer },
|
||||
});
|
||||
};
|
||||
|
@ -212,11 +214,18 @@ export function doAlertError(errorList) {
|
|||
|
||||
export function doDaemonReady() {
|
||||
return function(dispatch, getState) {
|
||||
const state = getState();
|
||||
|
||||
dispatch(doAuthenticate());
|
||||
dispatch({ type: types.DAEMON_READY });
|
||||
dispatch(doFetchDaemonSettings());
|
||||
dispatch(doBalanceSubscribe());
|
||||
dispatch(doFetchFileInfosAndPublishedClaims());
|
||||
dispatch(doFetchRewardedContent());
|
||||
if (!selectIsUpgradeSkipped(state)) {
|
||||
dispatch(doCheckUpgradeAvailable());
|
||||
}
|
||||
dispatch(doCheckUpgradeSubscribe());
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -2,11 +2,9 @@ import React from "react";
|
|||
import { connect } from "react-redux";
|
||||
import { selectPageTitle } from "selectors/navigation";
|
||||
import { selectUser } from "selectors/user";
|
||||
import { doCheckUpgradeAvailable, doAlertError } from "actions/app";
|
||||
import { doAlertError } from "actions/app";
|
||||
import { doRecordScroll } from "actions/navigation";
|
||||
import { doFetchRewardedContent } from "actions/content";
|
||||
import App from "./view";
|
||||
import { doInitCheckUpgradeTimer } from "../../actions/app";
|
||||
|
||||
const select = (state, props) => ({
|
||||
pageTitle: selectPageTitle(state),
|
||||
|
@ -15,9 +13,6 @@ const select = (state, props) => ({
|
|||
|
||||
const perform = dispatch => ({
|
||||
alertError: errorList => dispatch(doAlertError(errorList)),
|
||||
checkUpgradeAvailable: () => dispatch(doCheckUpgradeAvailable()),
|
||||
initCheckUpgradeTimer: () => dispatch(doInitCheckUpgradeTimer()),
|
||||
fetchRewardedContent: () => dispatch(doFetchRewardedContent()),
|
||||
recordScroll: scrollPosition => dispatch(doRecordScroll(scrollPosition)),
|
||||
});
|
||||
|
||||
|
|
|
@ -7,25 +7,12 @@ import lbry from "lbry";
|
|||
|
||||
class App extends React.PureComponent {
|
||||
componentWillMount() {
|
||||
const {
|
||||
alertError,
|
||||
checkUpgradeAvailable,
|
||||
initCheckUpgradeTimer,
|
||||
fetchRewardedContent,
|
||||
} = this.props;
|
||||
const { alertError } = this.props;
|
||||
|
||||
document.addEventListener("unhandledError", event => {
|
||||
alertError(event.detail);
|
||||
});
|
||||
|
||||
if (!this.props.upgradeSkipped) {
|
||||
checkUpgradeAvailable();
|
||||
}
|
||||
|
||||
initCheckUpgradeTimer();
|
||||
|
||||
fetchRewardedContent();
|
||||
|
||||
this.scrollListener = () => this.props.recordScroll(window.scrollY);
|
||||
|
||||
window.addEventListener("scroll", this.scrollListener);
|
||||
|
|
|
@ -20,8 +20,6 @@ const select = state => ({
|
|||
isForwardDisabled: selectIsForwardDisabled(state),
|
||||
isUpgradeAvailable: selectIsUpgradeAvailable(state),
|
||||
balance: formatCredits(selectBalance(state) || 0, 1),
|
||||
publish: __("Publish"),
|
||||
upgradeLabel: __("Upgrade App"),
|
||||
});
|
||||
|
||||
const perform = dispatch => ({
|
||||
|
|
|
@ -11,8 +11,6 @@ export const Header = props => {
|
|||
isForwardDisabled,
|
||||
isUpgradeAvailable,
|
||||
navigate,
|
||||
publish,
|
||||
upgradeLabel,
|
||||
downloadUpgrade,
|
||||
} = props;
|
||||
return (
|
||||
|
@ -61,7 +59,7 @@ export const Header = props => {
|
|||
onClick={() => navigate("/publish")}
|
||||
button="primary button--flat"
|
||||
icon="icon-upload"
|
||||
label={publish}
|
||||
label={__("Publish")}
|
||||
/>
|
||||
</div>
|
||||
<div className="header__item">
|
||||
|
@ -85,7 +83,7 @@ export const Header = props => {
|
|||
onClick={() => downloadUpgrade()}
|
||||
button="primary button--flat"
|
||||
icon="icon-arrow-up"
|
||||
label={upgradeLabel}
|
||||
label={__("Upgrade App")}
|
||||
/>
|
||||
)}
|
||||
</header>
|
||||
|
|
|
@ -20,10 +20,10 @@ export const UPGRADE_DOWNLOAD_STARTED = "UPGRADE_DOWNLOAD_STARTED";
|
|||
export const UPGRADE_DOWNLOAD_COMPLETED = "UPGRADE_DOWNLOAD_COMPLETED";
|
||||
export const UPGRADE_DOWNLOAD_PROGRESSED = "UPGRADE_DOWNLOAD_PROGRESSED";
|
||||
export const CHECK_UPGRADE_AVAILABLE = "CHECK_UPGRADE_AVAILABLE";
|
||||
export const CHECK_UPGRADE_STARTED = "CHECK_UPGRADE_STARTED";
|
||||
export const CHECK_UPGRADE_COMPLETED = "CHECK_UPGRADE_COMPLETED";
|
||||
export const CHECK_UPGRADE_FAILED = "CHECK_UPGRADE_FAILED";
|
||||
export const CHECK_UPGRADE_TIMER_INITIATED = "CHECK_UPGRADE_TIMER_INITIATED";
|
||||
export const CHECK_UPGRADE_START = "CHECK_UPGRADE_START";
|
||||
export const CHECK_UPGRADE_SUCCESS = "CHECK_UPGRADE_SUCCESS";
|
||||
export const CHECK_UPGRADE_FAIL = "CHECK_UPGRADE_FAIL";
|
||||
export const CHECK_UPGRADE_SUBSCRIBE = "CHECK_UPGRADE_SUBSCRIBE";
|
||||
export const UPDATE_VERSION = "UPDATE_VERSION";
|
||||
export const UPDATE_REMOTE_VERSION = "UPDATE_REMOTE_VERSION";
|
||||
export const SKIP_UPGRADE = "SKIP_UPGRADE";
|
||||
|
|
|
@ -75,14 +75,14 @@ reducers[types.UPDATE_VERSION] = function(state, action) {
|
|||
});
|
||||
};
|
||||
|
||||
reducers[types.CHECK_UPGRADE_COMPLETED] = function(state, action) {
|
||||
reducers[types.CHECK_UPGRADE_SUCCESS] = function(state, action) {
|
||||
return Object.assign({}, state, {
|
||||
isUpgradeAvailable: action.data.upgradeAvailable,
|
||||
remoteVersion: action.data.remoteVersion,
|
||||
});
|
||||
};
|
||||
|
||||
reducers[types.CHECK_UPGRADE_TIMER_INITIATED] = function(state, action) {
|
||||
reducers[types.CHECK_UPGRADE_SUBSCRIBE] = function(state, action) {
|
||||
return Object.assign({}, state, {
|
||||
checkUpgradeTimer: action.data.checkUpgradeTimer,
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue