2020-01-02 17:30:27 +01:00
|
|
|
// @flow
|
2020-01-20 17:47:03 +01:00
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
import * as PAGES from 'constants/pages';
|
2020-03-09 19:33:58 +01:00
|
|
|
import * as CS from 'constants/claim_search';
|
2020-01-02 17:30:27 +01:00
|
|
|
import React from 'react';
|
2020-01-20 17:47:03 +01:00
|
|
|
import moment from 'moment';
|
2020-01-02 17:30:27 +01:00
|
|
|
import Page from 'component/page';
|
2020-01-20 17:47:03 +01:00
|
|
|
import Button from 'component/button';
|
|
|
|
import ClaimTilesDiscover from 'component/claimTilesDiscover';
|
2020-02-17 20:12:28 +01:00
|
|
|
import I18nMessage from 'component/i18nMessage';
|
2020-01-20 17:47:03 +01:00
|
|
|
import { parseURI } from 'lbry-redux';
|
|
|
|
import { toCapitalCase } from 'util/string';
|
2020-01-02 17:30:27 +01:00
|
|
|
|
2020-01-20 17:47:03 +01:00
|
|
|
type Props = {
|
|
|
|
authenticated: boolean,
|
|
|
|
followedTags: Array<Tag>,
|
|
|
|
subscribedChannels: Array<Subscription>,
|
|
|
|
};
|
2020-01-02 17:30:27 +01:00
|
|
|
|
2020-01-20 17:47:03 +01:00
|
|
|
type RowDataItem = {
|
|
|
|
title: string,
|
|
|
|
link?: string,
|
|
|
|
help?: any,
|
|
|
|
options?: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
function HomePage(props: Props) {
|
|
|
|
const { followedTags, subscribedChannels, authenticated } = props;
|
2020-04-02 19:02:12 +02:00
|
|
|
const showPersonalizedChannels = (authenticated || !IS_WEB) && subscribedChannels && subscribedChannels.length > 0;
|
|
|
|
const showPersonalizedTags = (authenticated || !IS_WEB) && followedTags && followedTags.length > 0;
|
|
|
|
const showIndividualTags = showPersonalizedTags && followedTags.length < 5;
|
2020-01-20 17:47:03 +01:00
|
|
|
let rowData: Array<RowDataItem> = [];
|
|
|
|
|
2020-04-02 19:02:12 +02:00
|
|
|
// if you are following channels, always show that first
|
|
|
|
if (showPersonalizedChannels) {
|
|
|
|
let releaseTime = `>${Math.floor(
|
|
|
|
moment()
|
|
|
|
.subtract(1, 'year')
|
|
|
|
.startOf('week')
|
|
|
|
.unix()
|
|
|
|
)}`;
|
|
|
|
|
|
|
|
// Warning - hack below
|
|
|
|
// If users are following more than 20 channels or tags, limit results to stuff less than 6 months old
|
|
|
|
// This helps with timeout issues for users that are following a ton of stuff
|
|
|
|
// https://github.com/lbryio/lbry-sdk/issues/2420
|
|
|
|
if (subscribedChannels.length > 20) {
|
|
|
|
releaseTime = `>${Math.floor(
|
2020-01-24 22:09:46 +01:00
|
|
|
moment()
|
2020-04-02 19:02:12 +02:00
|
|
|
.subtract(6, 'months')
|
2020-01-24 22:09:46 +01:00
|
|
|
.startOf('week')
|
|
|
|
.unix()
|
|
|
|
)}`;
|
2020-04-02 19:02:12 +02:00
|
|
|
}
|
2020-01-24 22:09:46 +01:00
|
|
|
|
2020-04-02 19:02:12 +02:00
|
|
|
rowData.push({
|
|
|
|
title: 'Recent From Following',
|
|
|
|
link: `/$/${PAGES.CHANNELS_FOLLOWING}`,
|
|
|
|
options: {
|
|
|
|
orderBy: ['release_time'],
|
|
|
|
releaseTime: releaseTime,
|
|
|
|
pageSize: subscribedChannels.length > 3 ? 8 : 4,
|
|
|
|
channelIds: subscribedChannels.map(subscription => {
|
|
|
|
const { channelClaimId } = parseURI(subscription.uri);
|
|
|
|
return channelClaimId;
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2020-01-24 22:09:46 +01:00
|
|
|
|
2020-04-02 19:02:12 +02:00
|
|
|
if (showPersonalizedTags && !showIndividualTags) {
|
|
|
|
rowData.push({
|
|
|
|
title: 'Trending For Your Tags',
|
|
|
|
link: `/$/${PAGES.TAGS_FOLLOWING}`,
|
|
|
|
options: {
|
|
|
|
tags: followedTags.map(tag => tag.name),
|
|
|
|
claimType: ['stream'],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2020-01-20 17:47:03 +01:00
|
|
|
|
2020-04-02 19:02:12 +02:00
|
|
|
if (showPersonalizedTags && showIndividualTags) {
|
|
|
|
followedTags.forEach((tag: Tag) => {
|
2020-01-20 17:47:03 +01:00
|
|
|
rowData.push({
|
|
|
|
title: `Trending for #${toCapitalCase(tag.name)}`,
|
2020-02-28 16:11:55 +01:00
|
|
|
link: `/$/${PAGES.DISCOVER}?t=${tag.name}`,
|
2020-01-20 17:47:03 +01:00
|
|
|
options: {
|
|
|
|
pageSize: 4,
|
|
|
|
tags: [tag.name],
|
2020-03-25 21:44:35 +01:00
|
|
|
claimType: ['stream'],
|
2020-01-20 17:47:03 +01:00
|
|
|
},
|
|
|
|
});
|
2020-04-02 19:02:12 +02:00
|
|
|
});
|
2020-01-20 17:47:03 +01:00
|
|
|
}
|
|
|
|
|
2020-04-02 19:02:12 +02:00
|
|
|
rowData.push({
|
|
|
|
title: 'Top Content from Today',
|
|
|
|
link: `/$/${PAGES.DISCOVER}?${CS.ORDER_BY_KEY}=${CS.ORDER_BY_TOP}&${CS.FRESH_KEY}=${CS.FRESH_DAY}`,
|
|
|
|
options: {
|
|
|
|
pageSize: showPersonalizedChannels || showPersonalizedTags ? 4 : 8,
|
|
|
|
orderBy: ['effective_amount'],
|
|
|
|
claimType: ['stream'],
|
|
|
|
releaseTime: `>${Math.floor(
|
|
|
|
moment()
|
|
|
|
.subtract(1, 'day')
|
|
|
|
.startOf('day')
|
|
|
|
.unix()
|
|
|
|
)}`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
rowData.push({
|
|
|
|
title: 'Trending On LBRY',
|
|
|
|
link: `/$/${PAGES.DISCOVER}`,
|
|
|
|
options: {
|
|
|
|
pageSize: showPersonalizedChannels || showPersonalizedTags ? 4 : 8,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-04-17 18:21:00 +02:00
|
|
|
rowData.push({
|
|
|
|
title: '#covidcuts',
|
|
|
|
link: `/$/${PAGES.DISCOVER}?t=covidcuts&${CS.ORDER_BY_KEY}=${CS.ORDER_BY_NEW}`,
|
|
|
|
options: {
|
|
|
|
tags: ['covidcuts'],
|
|
|
|
orderBy: ['release_time'],
|
|
|
|
pageSize: 3,
|
|
|
|
prefixUris: ['lbry://@lbry#3f/covidcuts'],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-04-02 19:02:12 +02:00
|
|
|
if (!showPersonalizedChannels) {
|
|
|
|
rowData.push({
|
|
|
|
title: 'Top Channels On LBRY',
|
|
|
|
link: `/$/${PAGES.DISCOVER}?claim_type=channel&${CS.ORDER_BY_KEY}=${CS.ORDER_BY_TOP}&${CS.FRESH_KEY}=${CS.FRESH_ALL}`,
|
2020-01-20 17:47:03 +01:00
|
|
|
options: {
|
|
|
|
orderBy: ['effective_amount'],
|
2020-04-02 19:02:12 +02:00
|
|
|
claimType: ['channel'],
|
2020-01-20 17:47:03 +01:00
|
|
|
},
|
2020-04-02 19:02:12 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-17 18:21:00 +02:00
|
|
|
rowData.push({
|
|
|
|
title: 'Trending Classics',
|
|
|
|
link: `/$/${PAGES.DISCOVER}?${CS.ORDER_BY_KEY}=${CS.ORDER_BY_TRENDING}&${CS.FRESH_KEY}=${CS.FRESH_WEEK}`,
|
2020-04-02 19:02:12 +02:00
|
|
|
options: {
|
2020-04-17 18:21:00 +02:00
|
|
|
pageSize: 4,
|
|
|
|
claimType: ['stream'],
|
|
|
|
releaseTime: `<${Math.floor(
|
2020-04-02 19:02:12 +02:00
|
|
|
moment()
|
2020-04-17 18:21:00 +02:00
|
|
|
.subtract(6, 'month')
|
2020-04-02 19:02:12 +02:00
|
|
|
.startOf('day')
|
|
|
|
.unix()
|
|
|
|
)}`,
|
|
|
|
},
|
2020-04-17 18:21:00 +02:00
|
|
|
});
|
2020-01-20 17:47:03 +01:00
|
|
|
|
2020-02-06 21:11:00 +01:00
|
|
|
rowData.push({
|
|
|
|
title: 'Latest From @lbrycast',
|
|
|
|
link: `/@lbrycast:4`,
|
|
|
|
options: {
|
|
|
|
orderBy: ['release_time'],
|
|
|
|
pageSize: 4,
|
|
|
|
channelIds: ['4c29f8b013adea4d5cca1861fb2161d5089613ea'],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-01-20 17:47:03 +01:00
|
|
|
rowData.push({
|
|
|
|
title: 'Latest From @lbry',
|
|
|
|
link: `/@lbry:3f`,
|
|
|
|
options: {
|
|
|
|
orderBy: ['release_time'],
|
|
|
|
pageSize: 4,
|
|
|
|
channelIds: ['3fda836a92faaceedfe398225fb9b2ee2ed1f01a'],
|
|
|
|
},
|
|
|
|
});
|
2020-01-02 17:30:27 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Page>
|
2020-02-17 20:12:28 +01:00
|
|
|
{(authenticated || !IS_WEB) && !subscribedChannels.length && (
|
|
|
|
<div className="notice-message">
|
|
|
|
<h1 className="section__title">{__('LBRY Works Better If You Are Following Channels')}</h1>
|
|
|
|
<p className="section__subtitle">
|
|
|
|
<I18nMessage
|
|
|
|
tokens={{
|
|
|
|
discover_channels_link: (
|
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
navigate={`/$/${PAGES.CHANNELS_FOLLOWING_DISCOVER}`}
|
|
|
|
label={__('Find new channels to follow')}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
You aren't currently following any channels. %discover_channels_link%.
|
|
|
|
</I18nMessage>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
)}
|
2020-01-20 17:47:03 +01:00
|
|
|
{rowData.map(({ title, link, help, options = {} }) => (
|
|
|
|
<div key={title} className="claim-grid__wrapper">
|
|
|
|
<h1 className="section__actions">
|
|
|
|
{link ? (
|
|
|
|
<Button
|
|
|
|
className="claim-grid__title"
|
|
|
|
button="link"
|
|
|
|
navigate={link}
|
|
|
|
iconRight={ICONS.ARROW_RIGHT}
|
|
|
|
label={title}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<span className="claim-grid__title">{title}</span>
|
|
|
|
)}
|
|
|
|
{help}
|
|
|
|
</h1>
|
|
|
|
|
|
|
|
<ClaimTilesDiscover {...options} />
|
|
|
|
</div>
|
|
|
|
))}
|
2020-01-02 17:30:27 +01:00
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default HomePage;
|