-
Notifications
You must be signed in to change notification settings - Fork 780
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { useEffect, useRef, useState } from "react" | ||
import { Link } from "wouter" | ||
import { Waiting } from "../components/loading" | ||
import { client } from "../main" | ||
import { headersWithAuth } from "../utils/auth" | ||
|
||
export function TimelinePage() { | ||
const [feeds, setFeeds] = useState<Partial<Record<number, { id: number; title: string | null; createdAt: Date; }[]>>>() | ||
const [length, setLength] = useState(0) | ||
const ref = useRef(false) | ||
function fetchFeeds() { | ||
client.feed.timeline.get({ | ||
headers: headersWithAuth() | ||
}).then(({ data }) => { | ||
if (data && typeof data != 'string') { | ||
setLength(data.length) | ||
const groups = Object.groupBy(data, ({ createdAt }) => new Date(createdAt).getFullYear()) | ||
setFeeds(groups) | ||
} | ||
}) | ||
} | ||
useEffect(() => { | ||
if (ref.current) return | ||
fetchFeeds() | ||
ref.current = true | ||
}, []) | ||
return ( | ||
<> | ||
<Waiting wait={feeds}> | ||
<div className="w-full flex flex-col justify-center items-center mb-8 px-4"> | ||
<div className="wauto text-start text-black dark:text-white py-4 text-4xl font-bold"> | ||
<p> | ||
时间轴 | ||
</p> | ||
<div className="flex flex-row justify-between"> | ||
<p className="text-sm mt-4 text-neutral-500 font-normal"> | ||
共有 {length} 篇文章 | ||
</p> | ||
</div> | ||
</div> | ||
{feeds && Object.keys(feeds).sort((a, b) => parseInt(b) - parseInt(a)).map(year => ( | ||
<div key={year} className="wauto flex flex-col justify-center items-start"> | ||
<h1 className="flex flex-row items-center space-x-2"> | ||
<span className="text-2xl font-bold t-primary "> | ||
{year} 年 | ||
</span> | ||
<span className="text-sm t-secondary">{feeds[+year]?.length} 篇</span> | ||
</h1> | ||
<div className="w-full flex flex-col justify-center items-start my-4"> | ||
{feeds[+year]?.map(({ id, title, createdAt }) => ( | ||
<FeedItem key={id} id={id.toString()} title={title || "无标题"} createdAt={new Date(createdAt)} /> | ||
))} | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
</Waiting> | ||
</> | ||
) | ||
} | ||
|
||
export function FeedItem({ id, title, createdAt }: { id: string, title: string, createdAt: Date }) { | ||
const formatter = new Intl.DateTimeFormat('en-US', { day: '2-digit', month: '2-digit' }); | ||
return ( | ||
<div className="flex flex-row pl-8"> | ||
<div className="flex flex-row items-center"> | ||
<div className="w-2 h-2 bg-theme rounded-full"></div> | ||
</div> | ||
<div className="flex-1 rounded-2xl m-2 duration-300 flex flex-row items-center space-x-4 "> | ||
<span className="t-secondary text-sm" title={new Date(createdAt).toLocaleString()}> | ||
{formatter.format(new Date(createdAt))} | ||
</span> | ||
<Link href={`/feed/${id}`} target="_blank" className="text-base t-primary hover:text-theme text-pretty overflow-hidden"> | ||
{title} | ||
</Link> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters