From 96ab1bf2e2fbcdfc1685c9282de07ba827d34b84 Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Thu, 16 Nov 2017 18:39:10 -0300 Subject: [PATCH] Move App component's actions to doDaemonReady action --- ui/js/actions/app.js | 29 +++++++++++++++++++---------- ui/js/component/app/index.js | 7 +------ ui/js/component/app/view.jsx | 15 +-------------- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/ui/js/actions/app.js b/ui/js/actions/app.js index 8679000ca..e26bb3ff5 100644 --- a/ui/js/actions/app.js +++ b/ui/js/actions/app.js @@ -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()); }; } diff --git a/ui/js/component/app/index.js b/ui/js/component/app/index.js index 4b49f92cf..52ca853ef 100644 --- a/ui/js/component/app/index.js +++ b/ui/js/component/app/index.js @@ -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)), }); diff --git a/ui/js/component/app/view.jsx b/ui/js/component/app/view.jsx index 9ec001bd1..eea6ffcfe 100644 --- a/ui/js/component/app/view.jsx +++ b/ui/js/component/app/view.jsx @@ -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);