34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
'use client';
|
|
|
|
import { motion } from 'motion/react';
|
|
import Image from 'next/image';
|
|
import { useEffect, useState } from 'react';
|
|
import AppLogo from './AppLogo';
|
|
import BottomNav from './BottomNav';
|
|
import { apiRequest } from '../lib/api';
|
|
import type { TestResult } from '../lib/types';
|
|
|
|
export default function DiscoverFeed() {
|
|
const [results, setResults] = useState<TestResult[]>([]);
|
|
const [error, setError] = useState('');
|
|
useEffect(() => {
|
|
apiRequest<TestResult[]>('/api/v1/results/discover').then(setResults).catch((error: Error) => setError(error.message));
|
|
}, []);
|
|
return (
|
|
<main className="pageShell feedPage">
|
|
<AppLogo title="大家最近选了什么" />
|
|
<p className="pageLead">看看同频的人把谁送到了最后</p>
|
|
{error ? <div className="emptyState">{error}</div> : null}
|
|
<section className="waterfall">
|
|
{results.map((result, index) => (
|
|
<motion.article key={result.id} className="testCard" initial={{ opacity: 0, scale: .96 }} animate={{ opacity: 1, scale: 1 }} transition={{ delay: index * .04 }}>
|
|
<Image src={`/assets/test-covers/${result.test_slug}.jpg`} width={900} height={1200} sizes="(max-width: 920px) 50vw, 450px" alt={`${result.test_title}结果封面`} />
|
|
<div className="cardCopy"><p>{result.test_title}</p><h2>{result.champion_name}</h2></div>
|
|
</motion.article>
|
|
))}
|
|
</section>
|
|
<BottomNav />
|
|
</main>
|
|
);
|
|
}
|