From f90e404efc1e93cd4df864a97b158faf88929858 Mon Sep 17 00:00:00 2001 From: yun-zhi-ztl Date: Sat, 14 Mar 2026 20:23:36 +0800 Subject: [PATCH] fix(skill): refine starred and rating visual states --- web/src/features/skill/skill-card.tsx | 14 ++++++++------ web/src/features/social/star-button.tsx | 5 +++-- web/src/features/social/use-star.ts | 4 ++-- web/src/i18n/locales/en.json | 5 +---- web/src/i18n/locales/zh.json | 5 +---- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/web/src/features/skill/skill-card.tsx b/web/src/features/skill/skill-card.tsx index 7c20e776..8cd1e162 100644 --- a/web/src/features/skill/skill-card.tsx +++ b/web/src/features/skill/skill-card.tsx @@ -4,6 +4,7 @@ import { useAuth } from '@/features/auth/use-auth' import { useStar } from '@/features/social/use-star' import { Card } from '@/shared/ui/card' import { NamespaceBadge } from '@/shared/components/namespace-badge' +import { Bookmark } from 'lucide-react' interface SkillCardProps { skill: SkillSummary @@ -11,10 +12,10 @@ interface SkillCardProps { highlightStarred?: boolean } -export function SkillCard({ skill, onClick, highlightStarred = false }: SkillCardProps) { +export function SkillCard({ skill, onClick, highlightStarred = true }: SkillCardProps) { const { t } = useTranslation() const { isAuthenticated } = useAuth() - const { data: starStatus } = useStar(skill.id) + const { data: starStatus } = useStar(skill.id, highlightStarred && isAuthenticated) const showStarredBadge = highlightStarred && isAuthenticated && starStatus?.starred return ( @@ -32,7 +33,8 @@ export function SkillCard({ skill, onClick, highlightStarred = false }: SkillCar {skill.displayName} {showStarredBadge ? ( - + + {t('skillCard.starred')} ) : null} @@ -56,20 +58,20 @@ export function SkillCard({ skill, onClick, highlightStarred = false }: SkillCar - {t('skillCard.downloads', { count: skill.downloadCount })} + {skill.downloadCount} - {t('skillCard.stars', { count: skill.starCount })} + {skill.starCount} {skill.ratingAvg !== undefined && skill.ratingCount > 0 && ( - {t('skillCard.rating', { score: skill.ratingAvg.toFixed(1), count: skill.ratingCount })} + {skill.ratingAvg.toFixed(1)} )} diff --git a/web/src/features/social/star-button.tsx b/web/src/features/social/star-button.tsx index 0d6c06fd..f72ac481 100644 --- a/web/src/features/social/star-button.tsx +++ b/web/src/features/social/star-button.tsx @@ -1,7 +1,7 @@ import { useTranslation } from 'react-i18next' import { Button } from '@/shared/ui/button' import { useStar, useToggleStar } from './use-star' -import { Star } from 'lucide-react' +import { Bookmark } from 'lucide-react' import { useAuth } from '@/features/auth/use-auth' interface StarButtonProps { @@ -34,10 +34,11 @@ export function StarButton({ skillId, starCount, onRequireLogin }: StarButtonPro ) diff --git a/web/src/features/social/use-star.ts b/web/src/features/social/use-star.ts index f5ab55e1..d12331b6 100644 --- a/web/src/features/social/use-star.ts +++ b/web/src/features/social/use-star.ts @@ -31,11 +31,11 @@ async function toggleStar(skillId: number, starred: boolean): Promise { } } -export function useStar(skillId: number) { +export function useStar(skillId: number, enabled = true) { return useQuery({ queryKey: ['skills', skillId, 'star'], queryFn: () => getStarStatus(skillId), - enabled: !!skillId, + enabled: !!skillId && enabled, }) } diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json index ee124489..1f4cf42b 100644 --- a/web/src/i18n/locales/en.json +++ b/web/src/i18n/locales/en.json @@ -416,10 +416,7 @@ "star": "Star" }, "skillCard": { - "starred": "Starred", - "downloads": "{{count}} downloads", - "stars": "{{count}} stars", - "rating": "Rating {{score}} ({{count}})" + "starred": "Starred" }, "copyButton": { "copied": "Copied", diff --git a/web/src/i18n/locales/zh.json b/web/src/i18n/locales/zh.json index 69057f8d..9e71b83e 100644 --- a/web/src/i18n/locales/zh.json +++ b/web/src/i18n/locales/zh.json @@ -416,10 +416,7 @@ "star": "收藏" }, "skillCard": { - "starred": "已收藏", - "downloads": "下载 {{count}}", - "stars": "收藏 {{count}}", - "rating": "评分 {{score}} ({{count}})" + "starred": "已收藏" }, "copyButton": { "copied": "已复制",