lbry-desktop/src/ui/page/discover/view.jsx

83 lines
2.2 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import React from 'react';
2018-03-26 23:32:43 +02:00
import Page from 'component/page';
2018-05-23 06:35:34 +02:00
import CategoryList from 'component/categoryList';
import FirstRun from 'component/firstRun';
2017-12-08 21:14:35 +01:00
2018-03-26 23:32:43 +02:00
type Props = {
fetchFeaturedUris: () => void,
2018-08-28 23:53:20 +02:00
fetchRewardedContent: () => void,
fetchRewards: () => void,
2018-03-26 23:32:43 +02:00
fetchingFeaturedUris: boolean,
featuredUris: {},
};
2017-12-08 21:14:35 +01:00
2018-03-26 23:32:43 +02:00
class DiscoverPage extends React.PureComponent<Props> {
2018-06-19 22:59:31 +02:00
constructor() {
super();
this.continousFetch = undefined;
}
2019-01-24 22:20:43 +01:00
componentDidMount() {
const { fetchFeaturedUris, fetchRewardedContent, fetchRewards } = this.props;
2018-06-19 22:59:31 +02:00
fetchFeaturedUris();
2018-08-28 23:53:20 +02:00
fetchRewardedContent();
this.continousFetch = setInterval(() => {
fetchFeaturedUris();
2018-08-28 23:53:20 +02:00
fetchRewardedContent();
fetchRewards();
}, 1000 * 60 * 60);
2018-06-19 22:59:31 +02:00
}
componentWillUnmount() {
this.clearContinuousFetch();
2017-05-07 09:39:13 +02:00
}
2018-10-10 16:13:43 +02:00
getCategoryLinkPartByCategory(category: string) {
const channelName = category.substr(category.indexOf('@'));
if (!channelName.includes('#')) {
return null;
}
return channelName;
}
2018-10-10 17:02:20 +02:00
trimClaimIdFromCategory(category: string) {
return category.split('#')[0];
}
2018-10-10 16:13:43 +02:00
continousFetch: ?IntervalID;
2018-06-19 22:59:31 +02:00
clearContinuousFetch() {
if (this.continousFetch) {
clearInterval(this.continousFetch);
this.continousFetch = null;
}
}
render() {
2017-06-06 23:19:12 +02:00
const { featuredUris, fetchingFeaturedUris } = this.props;
2018-03-26 23:32:43 +02:00
const hasContent = typeof featuredUris === 'object' && Object.keys(featuredUris).length;
const failedToLoad = !fetchingFeaturedUris && !hasContent;
2019-01-24 22:20:43 +01:00
return (
2019-05-07 04:35:04 +02:00
<Page notContained isLoading={!hasContent && fetchingFeaturedUris} className="main--no-padding">
<FirstRun />
2017-07-15 21:15:17 +02:00
{hasContent &&
2019-01-24 22:20:43 +01:00
Object.keys(featuredUris).map(category => (
<CategoryList
lazyLoad
2019-01-24 22:20:43 +01:00
key={category}
category={this.trimClaimIdFromCategory(category)}
2019-01-30 08:39:00 +01:00
uris={featuredUris[category]}
2019-01-24 22:20:43 +01:00
categoryLink={this.getCategoryLinkPartByCategory(category)}
/>
))}
{failedToLoad && <div className="empty">{__('Failed to load landing content.')}</div>}
2018-03-26 23:32:43 +02:00
</Page>
2017-06-06 23:19:12 +02:00
);
}
2017-05-04 05:44:08 +02:00
}
2017-05-25 18:29:56 +02:00
export default DiscoverPage;