Skip to content

Commit

Permalink
autofollow waits for prefs ready
Browse files Browse the repository at this point in the history
  • Loading branch information
jessopb authored and Sean Yesmunt committed Apr 26, 2021
1 parent 03eed6b commit b10b794
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
8 changes: 5 additions & 3 deletions ui/component/userChannelFollowIntro/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import { selectSubscriptions } from 'redux/selectors/subscriptions';
import { doChannelSubscribe } from 'redux/actions/subscriptions';
import UserChannelFollowIntro from './view';
import { selectHomepageData } from 'redux/selectors/settings';
import { selectPrefsReady } from 'redux/selectors/sync';

const select = state => ({
const select = (state) => ({
followedTags: selectFollowedTags(state),
subscribedChannels: selectSubscriptions(state),
homepageData: selectHomepageData(state),
prefsReady: selectPrefsReady(state),
});

const perform = dispatch => ({
channelSubscribe: uri => dispatch(doChannelSubscribe(uri)),
const perform = (dispatch) => ({
channelSubscribe: (uri) => dispatch(doChannelSubscribe(uri)),
});

export default connect(select, perform)(UserChannelFollowIntro);
24 changes: 14 additions & 10 deletions ui/component/userChannelFollowIntro/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,32 @@ type Props = {
onBack: () => void,
channelSubscribe: (sub: Subscription) => void,
homepageData: any,
prefsReady: boolean,
};

const channelsToSubscribe = AUTO_FOLLOW_CHANNELS.trim()
.split(' ')
.filter(x => x !== '');
.filter((x) => x !== '');

function UserChannelFollowIntro(props: Props) {
const { subscribedChannels, channelSubscribe, onContinue, onBack, homepageData } = props;
const { subscribedChannels, channelSubscribe, onContinue, onBack, homepageData, prefsReady } = props;
const { PRIMARY_CONTENT_CHANNEL_IDS } = homepageData;
const followingCount = (subscribedChannels && subscribedChannels.length) || 0;

// subscribe to lbry
useEffect(() => {
if (channelsToSubscribe && channelsToSubscribe.length) {
channelsToSubscribe.forEach(c =>
channelSubscribe({
channelName: parseURI(c).claimName,
uri: c,
})
);
if (channelsToSubscribe && channelsToSubscribe.length && prefsReady) {
const delayedChannelSubscribe = () => {
channelsToSubscribe.forEach((c) =>
channelSubscribe({
channelName: parseURI(c).claimName,
uri: c,
})
);
};
setTimeout(delayedChannelSubscribe, 1000);
}
}, []);
}, [prefsReady]);

return (
<Card
Expand Down

0 comments on commit b10b794

Please sign in to comment.