diff --git a/src/pages/Home/index.tsx b/src/pages/Home/index.tsx index 83cfa44..87b4b0d 100644 --- a/src/pages/Home/index.tsx +++ b/src/pages/Home/index.tsx @@ -26,6 +26,8 @@ export function Home() { const [rec, setRec] = useState([]); const [latest, setLatest] = useState([]); const [latestPosts, setLatestPosts] = useState([]); + const [popular, setPopular] = useState([]); + const [popularPosts, setPopularPosts] = useState([]); const [err, setErr] = useState(null); const recRowRef = useRef(null); const categoryRowRef = useRef(null); @@ -42,8 +44,9 @@ export function Home() { getJSON(`/api/categories${catQ}`), getJSON<{ items: Post[] }>(`/api/posts/recommended${postQ}&limit=12`), getJSON<{ items: Post[] }>(`/api/posts/latest${postQ}&limit=8`), + getJSON<{ items: Post[] }>(`/api/posts${postQ}&sort=popular&limit=8`), ]) - .then(([c, r, l]) => { + .then(([c, r, l, p]) => { setCats(itemsOrEmpty(c)); setRec( itemsOrEmpty(r.items).map((post) => @@ -57,6 +60,13 @@ export function Home() { postToResource(post, lang, itemsOrEmpty(c)), ), ); + const popularItems = itemsOrEmpty(p.items); + setPopularPosts(popularItems); + setPopular( + popularItems.map((post) => + postToResource(post, lang, itemsOrEmpty(c)), + ), + ); }) .catch((e) => setErr(String(e))); }, [lang]); @@ -127,6 +137,7 @@ export function Home() { }; const latestPlaceholderCount = Math.max(0, 5 - latest.length); + const popularPlaceholderCount = Math.max(0, 5 - popular.length); const recommendedDotCount = Math.max(1, Math.min(4, rec.length || 4)); const activeRecommendedDot = Math.min( recommendedDotCount - 1, @@ -340,7 +351,31 @@ export function Home() { -