import { useMemo } from 'preact/hooks' import contributors from '../../contributors.json' import { Store } from '../Store.js' import { shuffle } from '../Utils.js' import { Card, ChangelogEntry, Footer, GeneratorCard, Giscus, ToolCard, ToolGroup } from '../components/index.js' import { WhatsNewTime } from '../components/whatsnew/WhatsNewTime.jsx' import { useLocale, useTitle } from '../contexts/index.js' import { useAsync } from '../hooks/useAsync.js' import { useMediaQuery } from '../hooks/useMediaQuery.js' import { fetchChangelogs, fetchVersions, fetchWhatsNew } from '../services/DataFetcher.js' const MIN_FAVORITES = 2 const MAX_FAVORITES = 5 interface Props { path?: string, } export function Home({}: Props) { const { locale } = useLocale() useTitle(locale('title.home')) const smallScreen = useMediaQuery('(max-width: 580px)') return
{smallScreen ? /* mobile */ <> : /* desktop */ <>
{!smallScreen &&
} }
} function PopularGenerators() { const { locale } = useLocale() return } function FavoriteGenerators() { const { locale } = useLocale() const favorites = useMemo(() => { const history: string[] = [] for (const id of Store.getGeneratorHistory().reverse()) { if (!history.includes(id)) { history.push(id) } } return history.slice(0, MAX_FAVORITES) }, []) if (favorites.length < MIN_FAVORITES) return <> return {favorites.map(f => )} } function Guides() { const { locale } = useLocale() return } function Tools() { const { locale } = useLocale() return } function Versions() { const { locale } = useLocale() const { value: versions } = useAsync(fetchVersions, []) const release = useMemo(() => versions?.find(v => v.type === 'release'), [versions]) return {(versions?.[0] && release) && <> {versions[0].id !== release.id && ( )} } } function Changelog() { const { locale } = useLocale() const hugeScreen = useMediaQuery('(min-width: 960px)') const { value: changes } = useAsync(fetchChangelogs, []) const latestChanges = useMemo(() => changes?.sort((a, b) => b.order - a.order).slice(0, 2), [changes]) return {latestChanges?.map(change => )} } function WhatsNew() { const { locale } = useLocale() const { value: items } = useAsync(fetchWhatsNew) return {items?.slice(0, 3).map(item => }>{item.title})} } function Contributors() { const supporters = useMemo(() => { return contributors.filter(c => c.types.includes('support') || c.types.includes('infrastructure')) }, []) const otherContributors = useMemo(() => { return shuffle(contributors.filter(c => !supporters.includes(c))) }, []) return

Supporters

Contributors

} interface ContributorsListProps { list: typeof contributors large?: boolean } function ContributorsList({ list, large }: ContributorsListProps) { const { locale } = useLocale() return
{list.map((c) => `• ${locale('contributor.' + t)}`).join('\n')}`}> {c.name} )}
}