2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2017-12-21 22:08:54 +01:00
|
|
|
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';
|
2019-01-22 19:29:45 +01:00
|
|
|
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,
|
2019-01-22 19:29:45 +01:00
|
|
|
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() {
|
2018-12-17 20:53:59 +01:00
|
|
|
const { fetchFeaturedUris, fetchRewardedContent, fetchRewards } = this.props;
|
2018-06-19 22:59:31 +02:00
|
|
|
fetchFeaturedUris();
|
2018-08-28 23:53:20 +02:00
|
|
|
fetchRewardedContent();
|
2018-08-28 22:46:50 +02:00
|
|
|
|
|
|
|
this.continousFetch = setInterval(() => {
|
|
|
|
fetchFeaturedUris();
|
2018-08-28 23:53:20 +02:00
|
|
|
fetchRewardedContent();
|
2018-11-30 21:30:24 +01:00
|
|
|
fetchRewards();
|
2018-08-28 22:46:50 +02:00
|
|
|
}, 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-11 02:59:47 +02:00
|
|
|
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
|
|
|
|
2017-05-11 02:59:47 +02:00
|
|
|
return (
|
2019-05-07 04:35:04 +02:00
|
|
|
<Page notContained isLoading={!hasContent && fetchingFeaturedUris} className="main--no-padding">
|
2019-01-22 19:29:45 +01:00
|
|
|
<FirstRun />
|
2017-07-15 21:15:17 +02:00
|
|
|
{hasContent &&
|
2019-01-24 22:20:43 +01:00
|
|
|
Object.keys(featuredUris).map(category => (
|
|
|
|
<CategoryList
|
2019-02-04 05:20:57 +01:00
|
|
|
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)}
|
|
|
|
/>
|
|
|
|
))}
|
2017-12-21 22:08:54 +01:00
|
|
|
{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-11 02:59:47 +02:00
|
|
|
}
|
2017-05-04 05:44:08 +02:00
|
|
|
}
|
|
|
|
|
2017-05-25 18:29:56 +02:00
|
|
|
export default DiscoverPage;
|