diff --git a/frontend/src/components/CommunityToday.tsx b/frontend/src/components/CommunityToday.tsx new file mode 100644 index 0000000..22954ca --- /dev/null +++ b/frontend/src/components/CommunityToday.tsx @@ -0,0 +1,59 @@ +import { useState, useEffect } from 'react' +import { useTranslation } from 'react-i18next' +import { useStore } from '../store' +import ReportButton from './ui/ReportButton' +import type { CommunityPuzzleItem } from '../api' + +export default function CommunityToday() { + const { t } = useTranslation() + const [puzzles, setPuzzles] = useState([]) + const [loading, setLoading] = useState(true) + + useEffect(() => { + fetch('/api/community-puzzles/today') + .then(r => r.json()) + .then(d => { setPuzzles(d.puzzles || []); setLoading(false) }) + .catch(() => setLoading(false)) + }, []) + + const play = (id: string) => { + useStore.getState().loadCommunityPuzzle(id) + window.history.replaceState(null, '', '/') + window.location.reload() + } + + return ( +
+
+ + {t('common.back')} + +

+ {t('communityToday.title')} +

+

+ {t('communityToday.subtitle')} +

+ + {loading &&

{t('common.loading')}

} + + {!loading && puzzles.length === 0 && ( +

{t('communityToday.none')}

+ )} + +
+ {puzzles.map(p => ( + + ))} +
+
+
+ ) +}