Move App component's actions to doDaemonReady action

This commit is contained in:
Igor Gassmann 2017-11-16 18:39:10 -03:00
parent e0aa6e3646
commit 96ab1bf2e2
3 changed files with 21 additions and 30 deletions

View file

@ -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());
};
}

View file

@ -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)),
});

View file

@ -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);