Skip to content

Commit 9e5ce4a

Browse files
show new blooger in the front of the blogger list (#202)
* create new blogger json file * plan and implement spec * remove work file
1 parent e764209 commit 9e5ce4a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/App.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Card, Text } from '@radix-ui/themes'
1+
import { Card, Text, Badge } from '@radix-ui/themes'
22
import { Routes, Route, Link } from 'react-router'
33
import './App.css'
44
import blogsData from './assets/blogs.json'
@@ -25,7 +25,15 @@ interface Blog {
2525
const blogs: Blog[] = blogsData as Blog[];
2626

2727
function Them() {
28-
const { currentItems, currentPage, totalPages, startIndex, endIndex, totalItems, setPage } = usePagination(blogs, 20);
28+
// 计算将最后5个项目前置的数组,并标记这些“最新”项
29+
const sliceCount = Math.min(5, blogs.length);
30+
const lastN = blogs.slice(-sliceCount);
31+
const rest = blogs.slice(0, blogs.length - sliceCount);
32+
const arranged: Blog[] = [...lastN, ...rest];
33+
const toKey = (b: Blog) => `${b.name}|${b.url}`;
34+
const newSet = new Set(lastN.map(toKey));
35+
36+
const { currentItems, currentPage, totalPages, startIndex, endIndex, totalItems, setPage } = usePagination(arranged, 20);
2937
return (
3038
<div className='container mx-auto flex flex-col gap-4'>
3139
<div className='text-center text-sm text-gray-500 mb-2'>
@@ -47,6 +55,11 @@ function Them() {
4755
decoding="async"
4856
/>
4957
</a>
58+
{newSet.has(toKey(blog)) && (
59+
<div className="absolute top-2 right-2 z-10">
60+
<Badge color="green" variant="solid" radius="full">New</Badge>
61+
</div>
62+
)}
5063
</div>
5164
<div>
5265
<a href={blog.url} target="_blank" rel="noopener noreferrer">

0 commit comments

Comments
 (0)