From 42d8653d3d6ddc838626bd99b587bc4b03b9e166 Mon Sep 17 00:00:00 2001 From: Ou Date: Sat, 12 Oct 2024 21:31:33 +0800 Subject: [PATCH] pref: ui --- package.json | 1 + pnpm-lock.yaml | 3 +++ server/routes/[id].ts | 4 ---- shared/colors.ts | 30 +++++------------------------- shared/type.util.ts | 4 ++++ src/components/header.tsx | 7 +++++-- src/components/section/card.tsx | 24 ++++++++++++++++-------- src/components/section/index.tsx | 8 ++++---- src/routes/__root.tsx | 31 +++++++++++++++++-------------- src/styles/globals.css | 2 +- uno.config.ts | 27 +++++++++++++++++++-------- 11 files changed, 75 insertions(+), 66 deletions(-) diff --git a/package.json b/package.json index b540590..b366914 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "@types/md5": "^2.3.5", "@types/react": "^18.3.11", "@types/react-dom": "^18.3.0", + "@unocss/rule-utils": "^0.63.4", "@vitejs/plugin-react-swc": "^3.7.1", "bumpp": "^9.7.1", "eslint": "^9.12.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e2ee696..11f760f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -126,6 +126,9 @@ importers: '@types/react-dom': specifier: ^18.3.0 version: 18.3.0 + '@unocss/rule-utils': + specifier: ^0.63.4 + version: 0.63.4 '@vitejs/plugin-react-swc': specifier: ^3.7.1 version: 3.7.1(vite@5.4.8(@types/node@22.6.1)(terser@5.33.0)) diff --git a/server/routes/[id].ts b/server/routes/[id].ts index 3776004..7046d64 100644 --- a/server/routes/[id].ts +++ b/server/routes/[id].ts @@ -1,7 +1,6 @@ import { TTL } from "@shared/consts" import type { SourceID, SourceResponse } from "@shared/types" import { sources } from "@shared/sources" -import { delay } from "@shared/utils" import { sourcesFn } from "#/sources" import { Cache } from "#/cache" @@ -29,9 +28,6 @@ export default defineEventHandler(async (event): Promise => { // 默认 10 分钟,是低于 TTL 的,但部分 Source 的间隔会超过 TTL,甚至有的一天刷新一次。 const interval = sources[id].interval if (now - cache.updated < interval) { - if (id === "cankaoxiaoxi") { - await delay(2000) - } return { status: "success", data: { diff --git a/shared/colors.ts b/shared/colors.ts index dc952aa..3542851 100644 --- a/shared/colors.ts +++ b/shared/colors.ts @@ -1,26 +1,6 @@ -export const colors = [ - "blue", // #0000FF - "indigo", // #4B0082 - "violet", // #EE82EE - "purple", // #800080 - "fuchsia", // #FF00FF - "pink", // #FFC0CB - "rose", // #FF007F - "amber", // #FFBF00 - "yellow", // #FFFF00 - "lime", // #00FF00 - "green", // #008000 - "emerald", // #50C878 - "teal", // #008080 - "cyan", // #00FFFF - "sky", // #87CEEB - "slate", // #708090 - "gray", // #808080 - "zinc", // #A0A0A0 - "neutral", // #828282 - "stone", // #D2B48C - "red", // #FF0000 - "orange", // #FFA500 -] as const +import { colors as c } from "unocss/preset-mini" +import { typeSafeObjectKeys } from "./type.util" -export type Color = typeof colors[number] +export const colors = typeSafeObjectKeys(c) + +export type Color = Exclude diff --git a/shared/type.util.ts b/shared/type.util.ts index a5178f6..0257517 100644 --- a/shared/type.util.ts +++ b/shared/type.util.ts @@ -13,3 +13,7 @@ export function typeSafeObjectFromEntries< export function typeSafeObjectEntries>(obj: T): { [K in keyof T]: [K, T[K]] }[keyof T][] { return Object.entries(obj) as { [K in keyof T]: [K, T[K]] }[keyof T][] } + +export function typeSafeObjectKeys>(obj: T): (keyof T)[] { + return Object.keys(obj) as (keyof T)[] +} diff --git a/src/components/header.tsx b/src/components/header.tsx index b3ad988..ababbfa 100644 --- a/src/components/header.tsx +++ b/src/components/header.tsx @@ -59,14 +59,17 @@ export function Header() { logo News - Now + + N + ow + {`v${Version}`} - + diff --git a/src/components/section/card.tsx b/src/components/section/card.tsx index 4b1decb..6dc0434 100644 --- a/src/components/section/card.tsx +++ b/src/components/section/card.tsx @@ -4,7 +4,7 @@ import { useQuery } from "@tanstack/react-query" import clsx from "clsx" import { useInView } from "react-intersection-observer" import { useAtom } from "jotai" -import { forwardRef, useCallback, useImperativeHandle, useRef } from "react" +import { forwardRef, useCallback, useImperativeHandle, useMemo, useRef } from "react" import { sources } from "@shared/sources" import type { SyntheticListenerMap } from "@dnd-kit/core/dist/hooks/utilities" import { ofetch } from "ofetch" @@ -42,7 +42,7 @@ export const CardWrapper = forwardRef(({ id, isDragg
{sources[id].name} - {sources[id]?.title && {sources[id].title}} + {sources[id]?.title && {sources[id].title}} - 正在刷新 + 拖拽中
-
+
-
+
) } @@ -129,6 +129,8 @@ function NewsCard({ id, inView, handleListeners }: NewsCardProps) { })) }, [setRefetchSource, id]) + const isFreshFetching = useMemo(() => query.isFetching && !query.isPlaceholderData, [query]) + return ( <>
@@ -169,12 +171,18 @@ function NewsCard({ id, inView, handleListeners }: NewsCardProps) {
- {sources[id].type === "hottest" ? : } +
+ {sources[id].type === "hottest" ? : } +
) diff --git a/src/components/section/index.tsx b/src/components/section/index.tsx index 0f9c6d9..51eb1be 100644 --- a/src/components/section/index.tsx +++ b/src/components/section/index.tsx @@ -17,8 +17,8 @@ export function Section({ id }: { id: SectionID }) { <>
{sectionIds.map(section => ( @@ -27,8 +27,8 @@ export function Section({ id }: { id: SectionID }) { to="/s/$section" params={{ section }} className={clsx( - "op-90", - id === section && "color-primary font-bold op-100!", + "text-sm", + id === section ? "color-primary font-bold" : "op-70 dark:op-90", )} > {metadata[section].name} diff --git a/src/routes/__root.tsx b/src/routes/__root.tsx index 6cf9a35..3f442b1 100644 --- a/src/routes/__root.tsx +++ b/src/routes/__root.tsx @@ -6,11 +6,9 @@ import "virtual:uno.css" import type { QueryClient } from "@tanstack/react-query" import { Author, Homepage } from "@shared/consts" import clsx from "clsx" -import { useEffect } from "react" import { Header } from "~/components/header" import { useOnReload } from "~/hooks/useOnReload" import { OverlayScrollbar } from "~/components/common/overlay-scrollbar" -import { useSticky } from "~/hooks/useSticky" export const Route = createRootRouteWithContext<{ queryClient: QueryClient @@ -28,23 +26,28 @@ function NotFoundComponent() { function RootComponent() { useOnReload() - const { ref, isSticky } = useSticky() - useEffect(() => { - console.log(isSticky) - }, [isSticky]) return ( <> -
- -
+
-
+