// @flow import * as ICONS from 'constants/icons'; import React from 'react'; import Page from 'component/page'; import { Lbryio } from 'lbryinc'; import ChannelSelector from 'component/channelSelector'; import ClaimPreview from 'component/claimPreview'; import Card from 'component/common/card'; import Spinner from 'component/spinner'; import Icon from 'component/common/icon'; import usePersistedState from 'effects/use-persisted-state'; type Props = { channels: Array, }; export default function CreatorDashboardPage(props: Props) { const { channels } = props; const [stats, setStats] = React.useState(); const [selectedChannelUrl, setSelectedChannelUrl] = usePersistedState('analytics-selected-channel'); const [fetchingStats, setFetchingStats] = React.useState(false); const topChannel = channels && channels.reduce((top, channel) => { const topClaimCount = (top && top.meta && top.meta.claims_in_channel) || 0; const currentClaimCount = (channel && channel.meta && channel.meta.claims_in_channel) || 0; // $FlowFixMe return topClaimCount >= currentClaimCount ? top : channel.canonical_url; }); const selectedChannelClaim = channels && channels.find(claim => claim.canonical_url === selectedChannelUrl); const selectedChannelClaimId = selectedChannelClaim && selectedChannelClaim.claim_id; React.useEffect(() => { // set default channel if (!selectedChannelUrl && topChannel) { setSelectedChannelUrl(topChannel); } }, [selectedChannelUrl, topChannel]); React.useEffect(() => { if (selectedChannelClaimId && !fetchingStats) { setFetchingStats(true); Lbryio.call('reports', 'content', { claim_id: selectedChannelClaimId }) .then(res => { setFetchingStats(false); setStats(res); }) .catch(() => { setFetchingStats(false); }); } }, [selectedChannelClaimId, setFetchingStats]); return (
{ setStats(null); setSelectedChannelUrl(newChannelUrl); }} />
{fetchingStats && !stats && (
)} {!fetchingStats && !stats &&
This channel doesn't have any publishes
} {stats && (
{stats.ChannelSubs} followers} icon={ICONS.SUBSCRIBE} subtitle={
{stats.ChannelSubChange > 0 ? '+' : '-'} {stats.ChannelSubChange || 0} this week {stats.ChannelSubChange > 0 && }
} /> {stats.AllContentViews} views} subtitle={{stats.AllContentViewsChange || 0} this week} />
Most Viewed Claim
} body={
{stats.VideoViewsTopAllTime} views - {stats.VideoViewChangeTopAllTime} new {stats.VideoViewChangeTopAllTime > 0 && ( )}
} />
} /> )}
); }