Add language based channels to Auto follow (#523)

* Refactor userChannelFollowIntro

* Add community based channels to signup auto follow

* Add German channels

* Remove main english channels and leave only community ones for auto follow
This commit is contained in:
saltrafael 2021-12-20 17:35:59 -03:00 committed by GitHub
parent 2be14c86c3
commit 8c32b36aa0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 87 additions and 65 deletions

View file

@ -1,20 +1,19 @@
import { connect } from 'react-redux';
import { selectFollowedTags } from 'redux/selectors/tags';
import { selectSubscriptions } from 'redux/selectors/subscriptions';
import { doChannelSubscribe } from 'redux/actions/subscriptions';
import UserChannelFollowIntro from './view';
import { selectHomepageData } from 'redux/selectors/settings';
import { selectHomepageData, selectLanguage } from 'redux/selectors/settings';
import { selectPrefsReady } from 'redux/selectors/sync';
import { selectSubscriptions } from 'redux/selectors/subscriptions';
import UserChannelFollowIntro from './view';
const select = (state) => ({
followedTags: selectFollowedTags(state),
subscribedChannels: selectSubscriptions(state),
homepageData: selectHomepageData(state),
language: selectLanguage(state),
prefsReady: selectPrefsReady(state),
subscribedChannels: selectSubscriptions(state),
});
const perform = (dispatch) => ({
channelSubscribe: (uri) => dispatch(doChannelSubscribe(uri)),
channelSubscribe: (channelName, uri) => dispatch(doChannelSubscribe({ channelName, uri })),
});
export default connect(select, perform)(UserChannelFollowIntro);

View file

@ -1,28 +1,35 @@
// @flow
import React, { useEffect } from 'react';
import ClaimListDiscover from 'component/claimListDiscover';
import * as CS from 'constants/claim_search';
import Nag from 'component/common/nag';
import { CUSTOM_HOMEPAGE, SIMPLE_SITE, SITE_NAME } from 'config';
import { parseURI } from 'util/lbryURI';
import * as CS from 'constants/claim_search';
import COMMUNITY_CHANNELS from 'constants/community_channels';
import Button from 'component/button';
import Card from 'component/common/card';
import { AUTO_FOLLOW_CHANNELS, CUSTOM_HOMEPAGE, SIMPLE_SITE, SITE_NAME } from 'config';
import ClaimListDiscover from 'component/claimListDiscover';
import Nag from 'component/common/nag';
import React from 'react';
type Props = {
subscribedChannels: Array<Subscription>,
onContinue: () => void,
channelSubscribe: (sub: Subscription) => void,
homepageData: any,
language: string,
prefsReady: boolean,
subscribedChannels: Array<Subscription>,
channelSubscribe: (string, string) => void,
onContinue: () => void,
};
const channelsToSubscribe = AUTO_FOLLOW_CHANNELS.trim()
.split(' ')
.filter((x) => x !== '');
function UserChannelFollowIntro(props: Props) {
const { subscribedChannels, channelSubscribe, onContinue, homepageData, prefsReady } = props;
const { homepageData, language, prefsReady, subscribedChannels, channelSubscribe, onContinue } = props;
const { PRIMARY_CONTENT, LATEST } = homepageData;
const autoFollowChannels = COMMUNITY_CHANNELS[language] || COMMUNITY_CHANNELS['en'];
const channelsToSubscribe = autoFollowChannels
.trim()
.split(' ')
.filter((x) => x !== '');
let channelIds;
if (CUSTOM_HOMEPAGE) {
if (LATEST) {
@ -31,31 +38,29 @@ function UserChannelFollowIntro(props: Props) {
channelIds = PRIMARY_CONTENT.channelIds;
}
}
const followingCount = (subscribedChannels && subscribedChannels.length) || 0;
const followingCountIgnoringAutoFollows = (subscribedChannels || []).filter(
(channel) => !channelsToSubscribe.includes(channel.uri)
).length;
// subscribe to lbry
useEffect(() => {
// subscribe to odysee channels
React.useEffect(() => {
if (channelsToSubscribe && channelsToSubscribe.length && prefsReady) {
const delayedChannelSubscribe = () => {
channelsToSubscribe.forEach((c) => {
channelsToSubscribe.forEach((channelUri) => {
let claimName;
try {
const { claimName: name } = parseURI(c);
const { claimName: name } = parseURI(channelUri);
claimName = name;
} catch (e) {}
if (claimName) {
channelSubscribe({
channelName: claimName,
uri: c,
});
}
if (claimName) channelSubscribe(claimName, channelUri);
});
};
setTimeout(delayedChannelSubscribe, 1000);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [prefsReady]);
return (
@ -66,43 +71,41 @@ function UserChannelFollowIntro(props: Props) {
{ SITE_NAME }
)}
actions={
<React.Fragment>
<div className="section__body">
<ClaimListDiscover
hideFilters={SIMPLE_SITE}
hideAdvancedFilter={SIMPLE_SITE}
meta={
<Button
button={subscribedChannels.length < 1 ? 'alt' : 'primary'}
onClick={onContinue}
label={subscribedChannels.length < 1 ? __('Skip') : __('Continue')}
/>
}
defaultOrderBy={SIMPLE_SITE ? CS.ORDER_BY_TOP : CS.ORDER_BY_TRENDING}
defaultFreshness={CS.FRESH_ALL}
claimType="channel"
claimIds={CUSTOM_HOMEPAGE && channelIds ? channelIds : undefined}
defaultTags={followingCount > 3 ? CS.TAGS_FOLLOWED : undefined}
maxPages={SIMPLE_SITE ? 3 : undefined}
/>
{followingCount > 0 && (
<Nag
type="helpful"
message={
followingCountIgnoringAutoFollows === 1
? __('Nice! You are currently following %followingCount% creator', {
followingCount: followingCountIgnoringAutoFollows,
})
: __('Nice! You are currently following %followingCount% creators', {
followingCount: followingCountIgnoringAutoFollows,
})
}
actionText={__('Continue')}
<div className="section__body">
<ClaimListDiscover
hideFilters={SIMPLE_SITE}
hideAdvancedFilter={SIMPLE_SITE}
meta={
<Button
button={subscribedChannels.length < 1 ? 'alt' : 'primary'}
onClick={onContinue}
label={subscribedChannels.length < 1 ? __('Skip') : __('Continue')}
/>
)}
</div>
</React.Fragment>
}
defaultOrderBy={SIMPLE_SITE ? CS.ORDER_BY_TOP : CS.ORDER_BY_TRENDING}
defaultFreshness={CS.FRESH_ALL}
claimType="channel"
claimIds={(CUSTOM_HOMEPAGE && channelIds) || undefined}
defaultTags={followingCount > 3 ? CS.TAGS_FOLLOWED : undefined}
maxPages={SIMPLE_SITE ? 3 : undefined}
/>
{followingCountIgnoringAutoFollows > 0 && (
<Nag
type="helpful"
message={__(
followingCountIgnoringAutoFollows === 1
? 'Nice! You are currently following %following_count% creator'
: 'Nice! You are currently following %following_count% creators',
{
following_count: followingCountIgnoringAutoFollows,
}
)}
actionText={__('Continue')}
onClick={onContinue}
/>
)}
</div>
}
/>
);

View file

@ -0,0 +1,20 @@
import { AUTO_FOLLOW_CHANNELS } from 'config';
const PT_BR_CHANNELS =
'lbry://@odyseebr#152e0ea25fb58b8f0719714a1b9ffe7344429e62' +
' ' +
'lbry://@ajuda#d3a0afbe782c5ad13c944bdf12c1387302868c73';
const DE_CHANNELS =
'lbry://@OdyseeDE#1c44ca079e0e3a824881184fdffcf1864cb2649e' +
' ' +
'lbry://@OdyseeHilfe#14dd52c6105698159df73eb1fac89da477f895ea';
const COMMUNITY_CHANNELS = {
en: AUTO_FOLLOW_CHANNELS,
'pt-BR': PT_BR_CHANNELS,
es: 'lbry://@ayuda#7385d06a753744996461f5aa30daa570b85bd8d2',
de: DE_CHANNELS,
};
export default COMMUNITY_CHANNELS;