From 7030f3dec09f3d7b35043233efcbad86797b1a6c Mon Sep 17 00:00:00 2001 From: Ou Date: Fri, 18 Oct 2024 11:27:21 +0800 Subject: [PATCH] chore: optimize code structure --- src/components/column/card.tsx | 24 +++++++++++------------ src/components/column/index.tsx | 28 ++------------------------- src/components/column/navbar.tsx | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 38 deletions(-) create mode 100644 src/components/column/navbar.tsx diff --git a/src/components/column/card.tsx b/src/components/column/card.tsx index e13bbad..d0713e0 100644 --- a/src/components/column/card.tsx +++ b/src/components/column/card.tsx @@ -98,7 +98,7 @@ function NewsCard({ id, inView, handleListeners }: NewsCardProps) { <>
- {sources[id]?.title && {sources[id].title}} - +
@@ -152,7 +152,7 @@ function NewsCard({ id, inView, handleListeners }: NewsCardProps) { ) } -function UpdateTime({ query }: Query) { +function UpdatedTime({ query }: Query) { const updatedTime = useRelativeTime(query.data?.updatedTime ?? "") if (updatedTime) return `${updatedTime}更新` if (query.isError) return "获取失败" @@ -168,12 +168,17 @@ function ExtraInfo({ item }: { item: NewsItem }) { } } +function NewsUpdatedTime({ date }: { date: string }) { + const relativeTime = useRelativeTime(date) + return <>{relativeTime} +} + function NewsListHot({ query }: Query) { const items = query.data?.items return ( <> {items?.map((item, i) => ( - + {i + 1} @@ -191,11 +196,6 @@ function NewsListHot({ query }: Query) { ) } -function UpdatedTime({ item }: { item: NewsItem }) { - const relativeTime = useRelativeTime(item?.extra?.date) - return <>{relativeTime} -} - function NewsListTimeLine({ query }: Query) { const items = query.data?.items return ( @@ -203,9 +203,9 @@ function NewsListTimeLine({ query }: Query) { {items?.map(item => (
  • - - - + + + {item?.extra?.date && } diff --git a/src/components/column/index.tsx b/src/components/column/index.tsx index 1491427..9bc96fe 100644 --- a/src/components/column/index.tsx +++ b/src/components/column/index.tsx @@ -1,11 +1,8 @@ -import { columnIds, metadata } from "@shared/metadata" import type { ColumnID } from "@shared/types" -import { Link } from "@tanstack/react-router" -import clsx from "clsx" import { useAtom } from "jotai" import { useEffect } from "react" -import { useTitle } from "react-use" import { Dnd } from "./dnd" +import { NavBar } from "./navbar" import { currentColumnIDAtom } from "~/atoms" export function Column({ id }: { id: ColumnID }) { @@ -13,30 +10,9 @@ export function Column({ id }: { id: ColumnID }) { useEffect(() => { setCurrentColumnID(id) }, [id, setCurrentColumnID]) - useTitle(`NewsNow | ${metadata[id].name}`) return ( <> -
    - - {columnIds.map(columnId => ( - - {metadata[columnId].name} - - ))} - -
    + { currentColumnID === id && } ) diff --git a/src/components/column/navbar.tsx b/src/components/column/navbar.tsx new file mode 100644 index 0000000..f14536b --- /dev/null +++ b/src/components/column/navbar.tsx @@ -0,0 +1,33 @@ +import { columnIds, metadata } from "@shared/metadata" +import type { ColumnID } from "@shared/types" +import { Link } from "@tanstack/react-router" +import clsx from "clsx" +import { useTitle } from "react-use" + +export function NavBar({ id }: { id: ColumnID }) { + useTitle(`NewsNow | ${metadata[id].name}`) + return ( +
    + + {columnIds.map(columnId => ( + + {metadata[columnId].name} + + ))} + +
    + ) +}