autofollow waits for prefs ready

This commit is contained in:
zeppi 2021-04-25 01:31:19 -04:00 committed by Sean Yesmunt
parent 03eed6b961
commit b10b79432f
2 changed files with 19 additions and 13 deletions

View file

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

View file

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