import { useState, useEffect } from 'react'; import { FormattedMessage } from 'react-intl'; import { importFetchedStatuses, importFetchedAccounts, } from 'mastodon/actions/importer'; import { apiRequestGet, apiRequestPost } from 'mastodon/api'; import { LoadingIndicator } from 'mastodon/components/loading_indicator'; import { me } from 'mastodon/initial_state'; import type { Account } from 'mastodon/models/account'; import type { AnnualReport as AnnualReportData } from 'mastodon/models/annual_report'; import type { Status } from 'mastodon/models/status'; import { useAppSelector, useAppDispatch } from 'mastodon/store'; import { Archetype } from './archetype'; import { Followers } from './followers'; import { HighlightedPost } from './highlighted_post'; import { MostUsedHashtag } from './most_used_hashtag'; import { NewPosts } from './new_posts'; import { Percentile } from './percentile'; interface AnnualReportResponse { annual_reports: AnnualReportData[]; accounts: Account[]; statuses: Status[]; } export const AnnualReport: React.FC<{ year: string; }> = ({ year }) => { const [response, setResponse] = useState(null); const [loading, setLoading] = useState(false); const currentAccount = useAppSelector((state) => me ? state.accounts.get(me) : undefined, ); const dispatch = useAppDispatch(); useEffect(() => { setLoading(true); apiRequestGet(`v1/annual_reports/${year}`) .then((data) => { dispatch(importFetchedStatuses(data.statuses)); dispatch(importFetchedAccounts(data.accounts)); setResponse(data); setLoading(false); return apiRequestPost(`v1/annual_reports/${year}/read`); }) .catch(() => { setLoading(false); }); }, [dispatch, year, setResponse, setLoading]); if (loading) { return ; } const report = response?.annual_reports[0]; if (!report) { return null; } return (

); };