Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add autodownload toggle to subscriptions page #1898

Merged
merged 2 commits into from Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/renderer/page/subscriptions/index.js
@@ -1,30 +1,32 @@
import { connect } from 'react-redux';
import * as settings from 'constants/settings';
import {
selectSubscriptionClaims,
selectSubscriptions,
selectSubscriptionsBeingFetched,
selectIsFetchingSubscriptions,
selectNotifications,
} from 'redux/selectors/subscriptions';
import { doFetchClaimsByChannel } from 'redux/actions/content';
import { setSubscriptionNotifications, doFetchMySubscriptions } from 'redux/actions/subscriptions';
import { doSetClientSetting } from 'redux/actions/settings';
import { makeSelectClientSetting } from 'redux/selectors/settings';
import SubscriptionsPage from './view';

const select = state => ({
loading:
selectIsFetchingSubscriptions(state) ||
Boolean(Object.keys(selectSubscriptionsBeingFetched(state)).length),
subscriptionsBeingFetched: selectSubscriptionsBeingFetched(state),
subscriptions: selectSubscriptions(state),
subscriptionClaims: selectSubscriptionClaims(state),
notifications: selectNotifications(state),
autoDownload: makeSelectClientSetting(settings.AUTO_DOWNLOAD)(state),
});

export default connect(
select,
{
doFetchClaimsByChannel,
setSubscriptionNotifications,
doFetchMySubscriptions,
doSetClientSetting,
}
)(SubscriptionsPage);
58 changes: 21 additions & 37 deletions src/renderer/page/subscriptions/view.jsx
@@ -1,26 +1,32 @@
// @flow
import React from 'react';
import Page from 'component/page';
import * as settings from 'constants/settings';
import type { Subscription } from 'types/subscription';
import * as NOTIFICATION_TYPES from 'constants/notification_types';
import Button from 'component/button';
import FileList from 'component/fileList';
import type { Claim } from 'types/claim';
import isDev from 'electron-is-dev';
import HiddenNsfwClaims from 'component/hiddenNsfwClaims';
import { FormField, FormRow } from 'component/common/form';

type Props = {
doFetchClaimsByChannel: (string, number) => void,
doFetchMySubscriptions: () => void,
setSubscriptionNotifications: ({}) => void,
subscriptions: Array<Subscription>,
subscriptionClaims: Array<{ uri: string, claims: Array<Claim> }>,
subscriptionsBeingFetched: {},
notifications: {},
loading: boolean,
autoDownload: boolean,
doSetClientSetting: (string, boolean) => void,
};

export default class extends React.PureComponent<Props> {
constructor() {
super();
(this: any).onAutoDownloadChange = this.onAutoDownloadChange.bind(this);
}

componentDidMount() {
const { notifications, setSubscriptionNotifications, doFetchMySubscriptions } = this.props;
doFetchMySubscriptions();
Expand All @@ -37,43 +43,12 @@ export default class extends React.PureComponent<Props> {
setSubscriptionNotifications(newNotifications);
}

componentDidUpdate() {
const {
subscriptions,
subscriptionClaims,
doFetchClaimsByChannel,
subscriptionsBeingFetched,
} = this.props;

const subscriptionClaimMap = {};
subscriptionClaims.forEach(claim => {
/*
This check added 6/20/18 to fix function receiving empty claims unexpectedly.
The better fix is ensuring channels aren't added to byId if there are no associated claims
We are adding this now with the redesign release to ensure users see the correct subscriptions
*/
if (claim.claims.length) {
subscriptionClaimMap[claim.uri] = 1;
} else if (isDev) {
// eslint-disable no-console
console.error(
`Claim for ${
claim.uri
} was added to byId in redux but there are no loaded fetched claims. This shouldn't happen because a subscription should have claims attached to it.`
);
// eslint-enable no-console
}
});

subscriptions.forEach(sub => {
if (!subscriptionClaimMap[sub.uri] && !subscriptionsBeingFetched[sub.uri]) {
doFetchClaimsByChannel(sub.uri, 1);
}
});
onAutoDownloadChange(event: SyntheticInputEvent<*>) {
this.props.doSetClientSetting(settings.AUTO_DOWNLOAD, event.target.checked);
}

render() {
const { subscriptions, subscriptionClaims, loading } = this.props;
const { subscriptions, subscriptionClaims, loading, autoDownload } = this.props;

let claimList = [];
subscriptionClaims.forEach(claimData => {
Expand All @@ -85,6 +60,15 @@ export default class extends React.PureComponent<Props> {
return (
<Page notContained loading={loading}>
<HiddenNsfwClaims uris={subscriptionUris} />
<FormRow alignRight>
<FormField
type="checkbox"
name="auto_download"
onChange={this.onAutoDownloadChange}
checked={autoDownload}
prefix={__('Automatically download new content from your subscriptions')}
/>
</FormRow>
{!subscriptions.length && (
<div className="page__empty">
{__("It looks like you aren't subscribed to any channels yet.")}
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/redux/actions/subscriptions.js
Expand Up @@ -8,7 +8,7 @@ import type { Subscription } from 'types/subscription';
import { selectSubscriptions } from 'redux/selectors/subscriptions';
import { makeSelectClientSetting } from 'redux/selectors/settings';
import { Lbry, buildURI, parseURI } from 'lbry-redux';
import { doPurchaseUri } from 'redux/actions/content';
import { doPurchaseUri, doFetchClaimsByChannel } from 'redux/actions/content';
import { doClaimRewardType } from 'redux/actions/rewards';
import Promise from 'bluebird';
import Lbryio from 'lbryio';
Expand Down Expand Up @@ -91,6 +91,8 @@ export const doFetchMySubscriptions = () => (dispatch: Dispatch, getState: () =>
type: ACTIONS.FETCH_SUBSCRIPTIONS_SUCCESS,
data: subscriptions,
});

subscriptions.forEach(({ uri }) => dispatch(doFetchClaimsByChannel(uri)));
})
.catch(() => {
dispatch({
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Expand Up @@ -5651,9 +5651,9 @@ lazy-val@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/lazy-val/-/lazy-val-1.0.3.tgz#bb97b200ef00801d94c317e29dc6ed39e31c5edc"

lbry-redux@lbryio/lbry-redux#ada4880c5d0758c7973aff9d443a87874d98b320:
lbry-redux@lbryio/lbry-redux#31f7afa8a37f5741dac01fc1ecdf153f3bed95dc:
version "0.0.1"
resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/ada4880c5d0758c7973aff9d443a87874d98b320"
resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/31f7afa8a37f5741dac01fc1ecdf153f3bed95dc"
dependencies:
proxy-polyfill "0.1.6"
reselect "^3.0.0"
Expand Down