-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* style: Add placeholder div style: Fixed FeedCard width fix: Can't delete cache chore: Adding clear adjacent feed cache refactor: Adjacent feeds API feat: Adding some cache function style: Change flex direction on mobile screens feat: Adding adjacent feeds to the frontend feat: Adding adjacent feeds API to the backend * style: 调整上一篇/下一篇样式 Signed-off-by: Xeu <[email protected]> --------- Signed-off-by: Xeu <[email protected]> Co-authored-by: Sittymin <[email protected]>
- Loading branch information
Showing
12 changed files
with
304 additions
and
55 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
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,81 @@ | ||
import {useEffect, useState} from "react"; | ||
import {client} from "../main.tsx"; | ||
import {timeago} from "../utils/timeago.ts"; | ||
import {Link} from "wouter"; | ||
import {useTranslation} from "react-i18next"; | ||
|
||
export type AdjacentFeed = { | ||
id: number; | ||
title: string | null; | ||
summary: string; | ||
hashtags: { | ||
id: number; | ||
name: string; | ||
}[]; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
}; | ||
export type AdjacentFeeds = { | ||
nextFeed: AdjacentFeed | null; | ||
previousFeed: AdjacentFeed | null; | ||
}; | ||
|
||
export function AdjacentSection({id, setError}: { id: string, setError: (error: string) => void }) { | ||
const [adjacentFeeds, setAdjacentFeeds] = useState<AdjacentFeeds>(); | ||
|
||
useEffect(() => { | ||
client.feed | ||
.adjacent({id}) | ||
.get() | ||
.then(({data, error}) => { | ||
if (error) { | ||
setError(error.value as string); | ||
} else if (data && typeof data !== "string") { | ||
setAdjacentFeeds(data); | ||
} | ||
}); | ||
}, [id, setError]); | ||
return ( | ||
<div className="rounded-2xl bg-w m-2 grid grid-cols-1 sm:grid-cols-2"> | ||
<AdjacentCard data={adjacentFeeds?.previousFeed} type="previous"/> | ||
<AdjacentCard data={adjacentFeeds?.nextFeed} type="next"/> | ||
</div> | ||
) | ||
} | ||
|
||
export function AdjacentCard({data, type}: { data: AdjacentFeed | null | undefined, type: "previous" | "next" }) { | ||
const direction = type === "previous" ? "text-start" : "text-end" | ||
const radius = type === "previous" ? "rounded-l-2xl" : "rounded-r-2xl" | ||
const {t} = useTranslation() | ||
if (!data) { | ||
return (<div className="w-full p-6 duration-300"> | ||
<p className={`t-secondary w-full ${direction}`}> | ||
{type === "previous" ? "Previous" : "Next"} | ||
</p> | ||
<h1 className={`text-xl text-gray-700 dark:text-white text-pretty truncate ${direction}`}> | ||
{t('no_more')} | ||
</h1> | ||
</div>); | ||
} | ||
return ( | ||
<Link href={`/feed/${data.id}`} target="_blank" | ||
className={`w-full p-6 duration-300 bg-button ${radius}`}> | ||
<p className={`t-secondary w-full ${direction}`}> | ||
{type === "previous" ? "Previous" : "Next"} | ||
</p> | ||
<h1 className={`text-xl font-bold text-gray-700 dark:text-white text-pretty truncate ${direction}`}> | ||
{data.title} | ||
</h1> | ||
<p className={`space-x-2 ${direction}`}> | ||
<span className="text-gray-400 text-sm" title={new Date(data.createdAt).toLocaleString()}> | ||
{data.createdAt === data.updatedAt ? timeago(data.createdAt) : t('feed_card.published$time', {time: timeago(data.createdAt)})} | ||
</span> | ||
{data.createdAt !== data.updatedAt && | ||
<span className="text-gray-400 text-sm" title={new Date(data.updatedAt).toLocaleString()}> | ||
{t('feed_card.updated$time', {time: timeago(data.updatedAt)})} | ||
</span> | ||
} | ||
</p> | ||
</Link> | ||
) | ||
} |
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
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
Oops, something went wrong.