Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
85a6a52
fix(toast): keep the rounded, centered toast style on phones
anqtal Nov 22, 2026
2af3af8
fix(header): make the logo easter egg toast last long enough to notice
anqtal Nov 22, 2026
3a70ef8
fix(majview): play the plain tap judge at the end of EX and break hol…
anqtal Nov 22, 2026
ae7707f
fix(majview): don't cut off judge/answer sounds when merging notes a …
anqtal Nov 22, 2026
5f850d1
feat(song): YouTube-style song page on phones
anqtal Nov 22, 2026
10d7a80
revert(song): don't pin the preview player while playing on phones
anqtal Nov 22, 2026
5243e30
fix(song): tighten the gap under the tabs on phones
anqtal Nov 22, 2026
92eb7e7
fix(majview): recover from iOS zombie AudioContexts that still report…
anqtal Nov 22, 2026
4b9e62e
feat(song): put the chart file tab after the leaderboard
anqtal Nov 22, 2026
02bc451
feat(song): show ID and HASH right below the play count
anqtal Nov 22, 2026
a2a129e
feat(song): put like/dislike left of the download button on phones
anqtal Nov 22, 2026
d45f3a1
fix(radar): trim the empty space above and below the radar
anqtal Nov 22, 2026
60d8a28
fix(song): style the phone vote control like the action buttons besid…
anqtal Nov 22, 2026
e55809b
feat(majview): hook the preview up to system media controls
anqtal Nov 22, 2026
3bfa7fe
fix(majview): show the real position in system media controls and all…
anqtal Nov 22, 2026
c800e52
fix(home): keep the first collection card aligned when returning to t…
anqtal Nov 22, 2026
112c5f5
feat(home): drop the prev/next buttons from the home rows
anqtal Nov 22, 2026
0784147
fix(song): stop the phone action row from widening the page
anqtal Nov 22, 2026
52318ac
feat(home): drop the sort tabs from the weekly ranking
anqtal Nov 22, 2026
e443ac2
fix(majview): make the system media scrubber usable and simplify the …
anqtal Nov 22, 2026
9d2ba3f
feat(home): show each weekly ranking as its own row
anqtal Nov 22, 2026
58fd0e2
feat(home): turn the all-charts and recommendation tabs into rows
anqtal Nov 22, 2026
acdecee
fix(home): stop clipping the collection card shadow on touch devices
anqtal Nov 22, 2026
f9436b4
feat(collection): call the card heart what it is: subscribe
anqtal Nov 22, 2026
d1d421a
feat(home): show collections as playlist tiles in the same row layout…
anqtal Nov 22, 2026
88c4cbf
feat(home): put personal picks first, then recently active and recent…
anqtal Nov 22, 2026
6d29734
revert(majview): restore the media session hook from 3bfa7fe
anqtal Nov 22, 2026
5f38c25
feat(song): put votes and actions right under the player on desktop
anqtal Nov 22, 2026
350ea54
test(song): mock ChartVoteBadge now that the song page always renders it
anqtal Nov 22, 2026
e7da379
feat(song): make the desktop preview player a full-width rectangle
anqtal Nov 22, 2026
f7dbdf5
fix(song): drop the extra blank space above the song header
anqtal Nov 22, 2026
7fcb257
feat(song): move difficulty selection into the desktop sidebar as a v…
anqtal Nov 22, 2026
d9dcc8f
feat(song): show tags as one row right under the action buttons
anqtal Nov 22, 2026
8aef63d
fix(majview): keep the bottom note counter above the fullscreen contr…
anqtal Nov 22, 2026
17a4655
feat(majview): larger note counters on wide desktop players
anqtal Nov 22, 2026
ae50644
feat(song): show comments only under the preview tab on desktop
anqtal Nov 22, 2026
8943bc5
feat(search): drop the visible results heading above the search box
anqtal Nov 22, 2026
ade3fe3
feat(majview): tap to show and hide the fullscreen controls on touch …
anqtal Nov 22, 2026
d62d2b8
feat(header): add a search button to the top bar
anqtal Nov 22, 2026
a4fb572
fix(header): open the search box over the top bar instead of below it
anqtal Nov 22, 2026
1e1f1c2
fix(header): keep the top bar search box to 36rem, centered
anqtal Nov 22, 2026
306c1da
fix(header): give every phone top bar button the same 40px boxed style
anqtal Nov 22, 2026
b55f771
feat(header): expand the desktop search box to the left of the button
anqtal Nov 22, 2026
1f7e7ba
fix(search): tidier search suggestions
anqtal Nov 22, 2026
a9efd55
fix(header): animate the desktop search box opening leftward
anqtal Nov 22, 2026
b032c47
feat(header): keep a search box in the desktop top bar
anqtal Nov 22, 2026
fdfd885
fix(song): tighten the desktop gaps above the header and under its di…
anqtal Nov 22, 2026
a42ed71
fix(header): let the logo easter egg toasts stack and start below the…
anqtal Nov 22, 2026
97ac753
fix(song): call the sidebar section chart info and divide it from dif…
anqtal Nov 22, 2026
341859c
Merge remote-tracking branch 'origin/main' into feat/home-song-page-r…
anqtal Nov 22, 2026
d1b3951
fix(song): tighten the phone gap between the header and the tabs
anqtal Nov 22, 2026
f0b8acf
fix(song): stop the phone vote control from stretching
anqtal Nov 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/chart/RadarPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export default function RadarPlot({ feature }: RadarPlotProps) {

return (
<svg
viewBox="0 0 320 360"
// 上下各留 150(约 166 分):以前按满分 200 留了 180,一般的谱面上下都空出一大块。
// 更高的分数仍然画得出来(overflow-visible),只是会伸到框外
viewBox="0 30 320 300"
className="block w-full overflow-visible text-white/90"
role="img"
aria-label={`${labels.map((label, i) => `${label}: ${values[i] ?? '—'}`).join(', ')}; ${estiLabel}: ${esti?.toFixed(2) ?? '—'}`}
Expand Down
22 changes: 11 additions & 11 deletions src/components/collection/CollectionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { Collection, CollectionSongList } from '@/types';
import { useFavorites } from '@/hooks';
import { LuListMusic, LuUser } from 'react-icons/lu';
import { CARD_SURFACE_CLASS } from '@/components/ui/surface';
import { SubscribeIcon } from './CollectionSubscribeButton';

const fetcher = (url: string) => fetch(url, { mode: 'cors', credentials: 'include' }).then((res) => res.json());

Expand Down Expand Up @@ -117,7 +118,7 @@ const CollectionCardContent = memo(({ collection, isManaging, onDelete }: Collec
</div>
</div>

{/* Favorite button */}
{/* 订阅按钮:和歌单页的“订阅”是同一个操作、同样的提示(以前这里叫“收藏”、是爱心) */}
{!isManaging && (
<m.button
initial={{ opacity: 0, scale: 0.8 }}
Expand All @@ -126,22 +127,21 @@ const CollectionCardContent = memo(({ collection, isManaging, onDelete }: Collec
whileTap={{ scale: 0.9 }}
onClick={(e) => {
e.stopPropagation();
toggleFavorite(collection.id);
toggleFavorite(collection.id, {
added: t("collection/CollectionPage.SubscribeSuccess"),
removed: t("collection/CollectionPage.UnsubscribeSuccess"),
});
}}
disabled={isFavoriteLoading}
className={`absolute top-2.5 right-2.5 z-10 flex justify-center items-center border-none rounded-lg w-7 h-7 text-sm cursor-pointer transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${isFavorited
? 'bg-pink-500/15 hover:bg-pink-500/25 text-pink-300'
? 'bg-blue-500/20 hover:bg-blue-500/30 text-blue-300'
: 'bg-transparent hover:bg-white/10 text-white/45 hover:text-white'
}`}
title={isFavorited ? t("collection/CollectionCard.Unfavorite") : t("collection/CollectionCard.Favorite")}
title={isFavorited ? t("collection/CollectionPage.Subscribed") : t("collection/CollectionPage.Subscribe")}
aria-label={isFavorited ? t("collection/CollectionPage.Subscribed") : t("collection/CollectionPage.Subscribe")}
aria-pressed={isFavorited}
>
{isFavoriteLoading ? (
<LoadingSpinner size="14px" />
) : isFavorited ? (
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z" /></svg>
) : (
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z" /></svg>
)}
{isFavoriteLoading ? <LoadingSpinner size="14px" /> : <SubscribeIcon subscribed={isFavorited} size={14} />}
</m.button>
)}

Expand Down
23 changes: 15 additions & 8 deletions src/components/collection/CollectionSubscribeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,24 @@ export default function CollectionSubscribeButton({ collectionId }: { collection
>
{isLoadingFavorites || isSubscriptionPending ? (
<LoadingSpinner size={16} />
) : isSubscribed ? (
<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
<path d="m5 12 4 4L19 6" />
</svg>
) : (
<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<path d="M18 8a6 6 0 0 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9" />
<path d="M10 21h4" />
</svg>
<SubscribeIcon subscribed={isSubscribed} size={16} />
)}
<span>{isSubscribed ? t("collection/CollectionPage.Subscribed") : t("collection/CollectionPage.Subscribe")}</span>
</button>
);
}

/** 订阅图标:没订阅是铃铛,订阅了是对勾(歌单页按钮和歌单卡片共用) */
export function SubscribeIcon({ subscribed, size }: { subscribed: boolean; size: number }) {
return subscribed ? (
<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
<path d="m5 12 4 4L19 6" />
</svg>
) : (
<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<path d="M18 8a6 6 0 0 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9" />
<path d="M10 21h4" />
</svg>
);
}
4 changes: 2 additions & 2 deletions src/components/header/AuthSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export default function AuthSection() {
{/* 移动端:下拉菜单形式 */}
<div className="md:hidden block relative">
<button
className={`${HAMBURGER_BUTTON_BASE} ${isMobileAuthMenuOpen ? HAMBURGER_BUTTON_ACTIVE : HAMBURGER_BUTTON_HOVER}`}
className={`${HAMBURGER_BUTTON_BASE} w-10 px-0 ${isMobileAuthMenuOpen ? HAMBURGER_BUTTON_ACTIVE : HAMBURGER_BUTTON_HOVER}`}
onClick={() => setIsMobileAuthMenuOpen(!isMobileAuthMenuOpen)}
aria-expanded={isMobileAuthMenuOpen}
aria-label={t("shared/AuthSection.AccountActions")}
>
<AiOutlineUser className="font-medium text-white/85 text-base" />
<AiOutlineUser aria-hidden="true" className="w-[18px] h-[18px] text-white/85" />
</button>

<Dropdown isOpen={isMobileAuthMenuOpen} onClose={() => setIsMobileAuthMenuOpen(false)} position="right" className="p-1.5 w-[min(13rem,calc(100vw-1.5rem))]">
Expand Down
92 changes: 92 additions & 0 deletions src/components/header/HeaderSearch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
import { LuSearch, LuX } from 'react-icons/lu';
import SearchBox from '@/components/search/SearchBox';
import { MOBILE_ICON_BUTTON } from './styles';

/**
* 顶栏的搜索按钮(和首页、搜索页同一个 SearchBox,带联想):
* - 电脑上(inline):顶栏里常驻一个输入框,不需要先点按钮;
* - 手机上:顶栏太窄,搜索框直接盖住整条顶栏,右边是关闭按钮。
* 回车或选中联想进入搜索页。点外面、按 Esc、换页都会收起。
*/
export default function HeaderSearch({ inline = false }: { inline?: boolean }) {
const { t } = useTranslation();
const navigate = useNavigate();
const location = useLocation();
const [open, setOpen] = useState(false);
const containerRef = useRef<HTMLDivElement>(null);

// 换页就收起(包括搜索后跳到搜索页)
const [lastPath, setLastPath] = useState(location.pathname + location.search);
if (lastPath !== location.pathname + location.search) {
setLastPath(location.pathname + location.search);
setOpen(false);
}

useEffect(() => {
if (!open) return;
const onPointerDown = (event: PointerEvent) => {
if (!containerRef.current?.contains(event.target as Node)) setOpen(false);
};
const onKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') setOpen(false);
};
document.addEventListener('pointerdown', onPointerDown);
document.addEventListener('keydown', onKeyDown);
return () => {
document.removeEventListener('pointerdown', onPointerDown);
document.removeEventListener('keydown', onKeyDown);
};
}, [open]);

const label = t('search/SearchPage.Title');
const submit = (value: string) => {
setOpen(false);
navigate(value ? '/search?search=' + encodeURIComponent(value) : '/search');
};
if (inline) {
// 和顶栏按钮一样高(36px);宽度随窗口变
return (
<div className="w-56 lg:w-64 xl:w-72 [&_input]:h-9">
<SearchBox value="" onSubmit={submit} />
</div>
);
}

return (
<div ref={containerRef} className="relative">
<button
type="button"
onClick={() => setOpen(!open)}
aria-expanded={open}
aria-label={label}
title={label}
className={`grid place-items-center border rounded-xl w-10 md:w-9 h-10 md:h-9 text-white/75 hover:text-white transition-colors duration-150 cursor-pointer touch-manipulation ${
open ? 'bg-white/10 border-white/20 text-white' : 'border-transparent hover:bg-white/[0.06]'
} ${MOBILE_ICON_BUTTON}`}
>
<LuSearch aria-hidden="true" className="w-[18px] h-[18px]" />
</button>
{open && (
// 盖住整条顶栏:和顶栏一样高、一样的底色
<div className="top-0 right-0 left-0 z-1001 fixed bg-[rgb(9_11_17/96%)] backdrop-blur-xl pt-[env(safe-area-inset-top)] border-white/[0.07] border-b">
{/* 搜索框不铺满整条顶栏:最宽 36rem,居中,关闭按钮紧挨在右边;手机上自然占满 */}
<div className="flex justify-center items-center gap-2 mx-auto px-3 sm:px-4 max-w-[calc(36rem+3.5rem)] h-(--header-height)">
<SearchBox value="" autoFocus onSubmit={submit} />
<button
type="button"
onClick={() => setOpen(false)}
aria-label={t('shared/header.CloseSearch')}
title={t('shared/header.CloseSearch')}
className="grid place-items-center hover:bg-white/[0.06] rounded-xl w-10 h-10 text-white/75 hover:text-white transition-colors cursor-pointer shrink-0"
>
<LuX aria-hidden="true" className="w-5 h-5" />
</button>
</div>
</div>
)}
</div>
);
}
3 changes: 2 additions & 1 deletion src/components/header/LanguageMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next';
import { setLanguage, useLanguage } from '@/i18n';
import { LANGUAGE_CONFIG, SUPPORTED_LANGUAGES } from '@/config/i18n';
import Dropdown from './Dropdown';
import { MOBILE_ICON_BUTTON } from './styles';

/** 顶栏右上角的语言切换菜单 */
export default function LanguageMenu() {
Expand All @@ -17,7 +18,7 @@ export default function LanguageMenu() {
type="button"
className={`flex items-center gap-1.5 px-2.5 border rounded-xl h-10 md:h-9 font-medium text-white/75 hover:text-white text-sm transition-colors duration-150 cursor-pointer touch-manipulation ${
isOpen ? 'bg-white/10 border-white/20 text-white' : 'border-transparent hover:bg-white/[0.06]'
}`}
} ${MOBILE_ICON_BUTTON}`}
onClick={() => setIsOpen(!isOpen)}
aria-expanded={isOpen}
aria-haspopup="true"
Expand Down
5 changes: 3 additions & 2 deletions src/components/header/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useUserContext } from '@/hooks';
import UserAvatar from '@/components/user/UserAvatar';
import { handleLogout as logoutUtil } from '@/utils';
import Dropdown from './Dropdown';
import { MOBILE_ICON_BUTTON } from './styles';
import { LuFileMusic, LuHouse, LuListMusic, LuLogOut, LuTrophy } from 'react-icons/lu';

const MENU_ITEM = 'flex items-center gap-3 bg-transparent px-3 border-none rounded-lg w-full h-10 text-white/80 hover:text-white text-sm no-underline hover:bg-white/[0.06] transition-colors cursor-pointer';
Expand Down Expand Up @@ -71,13 +72,13 @@ export default function UserMenu({ username }: UserMenuProps) {
<button
className={`group flex items-center gap-2 p-1 md:pr-3 border-none rounded-full h-10 font-medium text-sm cursor-pointer touch-manipulation transition-colors duration-150 ${
isOpen ? 'bg-white/10 text-white' : 'bg-transparent text-white/85 hover:bg-white/[0.06] hover:text-white'
}`}
} ${MOBILE_ICON_BUTTON}`}
onClick={() => setIsOpen(canHover() ? true : !isOpen)}
aria-expanded={isOpen}
aria-label={t("shared/UserMenu.UserMenu")}
>
<UserAvatar
className={`w-8 h-8 rounded-full object-cover ring-1 transition-shadow duration-150 ${isOpen ? 'ring-2 ring-blue-400/70' : 'ring-white/15 group-hover:ring-white/40'}`}
className={`w-7 md:w-8 h-7 md:h-8 rounded-full object-cover ring-1 transition-shadow duration-150 ${isOpen ? 'ring-2 ring-blue-400/70' : 'ring-white/15 group-hover:ring-white/40'}`}
username={username}
avatarId={user?.avatarId}
/>
Expand Down
6 changes: 5 additions & 1 deletion src/components/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Navigation from './Navigation';
import UserMenu from './UserMenu';
import AuthSection from './AuthSection';
import LanguageMenu from './LanguageMenu';
import HeaderSearch from './HeaderSearch';

/**
* 统一顶部导航栏组件
Expand All @@ -22,7 +23,7 @@ export default function UnifiedHeader() {
<header className="top-0 right-0 left-0 z-1000 fixed bg-[rgb(9_11_17/72%)] backdrop-blur-xl backdrop-saturate-150 pt-[env(safe-area-inset-top)] border-white/[0.07] border-b">
<div className="flex justify-between items-center gap-4 mx-auto px-3 sm:px-4 max-w-320 h-(--header-height)">
{/* 左侧区域:Logo + 导航 */}
<div className="flex flex-1 items-center gap-6 2xl:gap-8 min-w-0">
<div className="flex flex-1 items-center gap-1.5 md:gap-6 2xl:gap-8 min-w-0">
{/* Logo Section */}
<div className="hidden md:flex items-center shrink-0">
<Link to="/" className="flex items-center rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-400/70 no-underline">
Expand All @@ -32,6 +33,8 @@ export default function UnifiedHeader() {

{/* Main Navigation */}
<Navigation />
{/* 手机上搜索按钮放在菜单按钮旁边:右边已经有语言和头像,再放会挤到中间的 Logo */}
<div className="md:hidden"><HeaderSearch /></div>
</div>

{/* 移动端中间Logo */}
Expand All @@ -43,6 +46,7 @@ export default function UnifiedHeader() {

{/* Language + User Section */}
<div className="flex items-center gap-1.5 shrink-0">
<div className="hidden md:block"><HeaderSearch inline /></div>
<LanguageMenu />
<div className="relative flex items-center">
{isLoading ? (
Expand Down
3 changes: 3 additions & 0 deletions src/components/header/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ export const HAMBURGER_BUTTON_BASE = 'flex items-center justify-center gap-1.5 p
export const HAMBURGER_BUTTON_ACTIVE = 'bg-white/10 border-white/20';

export const HAMBURGER_BUTTON_HOVER = 'hover:bg-white/[0.08] hover:border-white/20';

/** 手机顶栏右侧 / 左侧的图标按钮:和菜单按钮一样的 40×40 圆角方框、同样的边框和底色(电脑上各自保持原样) */
export const MOBILE_ICON_BUTTON = 'max-md:grid max-md:place-items-center max-md:p-0 max-md:w-10 max-md:h-10 max-md:rounded-xl max-md:border max-md:border-white/10 max-md:bg-white/[0.04] max-md:hover:bg-white/[0.08] max-md:hover:border-white/20';
7 changes: 5 additions & 2 deletions src/components/header/useLogoEasterEgg.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { useTranslation } from 'react-i18next';
import { toast } from 'react-toastify';

/** 点 xxlb 头像的彩蛋(“不要点我”):顶栏 Logo 和页脚头像共用 */
/**
* 点 xxlb 头像的彩蛋(“不要点我”):顶栏 Logo 和页脚头像共用。
* 连点就一条条叠起来(彩蛋就是要能点出一大堆);每条停 1.5 秒,太短的话手机上进场动画刚播完就没了。
*/
export function useLogoEasterEgg() {
const { t } = useTranslation();
return () => {
toast.error(t("shared/MajdataLogo.FUCKYOU"), {
position: 'top-center',
autoClose: 500,
autoClose: 1500,
});
};
}
65 changes: 65 additions & 0 deletions src/components/home/CollectionTile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
import useSWR from 'swr';
import { LuListMusic } from 'react-icons/lu';
import { endpoints } from '@/config/api';
import { apiFetcher } from '@/utils/apiClient';
import { useFavorites } from '@/hooks';
import LoadingSpinner from '@/components/ui/LoadingSpinner';
import { SubscribeIcon } from '@/components/collection/CollectionSubscribeButton';
import type { Collection, CollectionSongList } from '@/types';

/**
* 首页歌单横栏的卡片:和谱面卡片一样的大封面(歌单第一张谱面的封面),像视频网站的播放列表那样,
* 封面上面露出两层“叠在后面的卡片”,右下角是谱面数量;右上角是订阅按钮(和歌单页的“订阅”同一个操作)。
*/
export default function CollectionTile({ collection }: { collection: Collection }) {
const { t } = useTranslation();
const href = '/collection?id=' + collection.id;
const { data } = useSWR<CollectionSongList>(endpoints.collection.songlist(collection.id), apiFetcher, { revalidateOnFocus: false });
const coverId = data?.items?.[0];
const { favoriteIds, toggleFavorite, isPending } = useFavorites();
const subscribed = favoriteIds.has(collection.id);
const pending = isPending(collection.id);
const subscribeLabel = subscribed ? t('collection/CollectionPage.Subscribed') : t('collection/CollectionPage.Subscribe');

return (
<div className="group min-w-0">
{/* 上面两层是“后面叠着的卡片”,越往后越窄、越淡 */}
<div className="relative pt-2">
<div aria-hidden="true" className="top-0 absolute inset-x-4 bg-white/12 rounded-t-lg h-2" />
<div aria-hidden="true" className="top-1 absolute inset-x-2 bg-white/22 rounded-t-lg h-2" />
<Link to={href} className="block relative bg-white/5 rounded-xl aspect-[4/3] overflow-hidden" aria-label={collection.name}>
{coverId ? (
<img src={endpoints.maichart.image(coverId)} alt="" loading="lazy" draggable={false} className="w-full h-full object-cover group-hover:scale-[1.03] transition-transform duration-300" />
) : (
<span className="grid place-items-center w-full h-full text-white/30"><LuListMusic aria-hidden="true" className="w-8 h-8" /></span>
)}
{/* 谱面数量 */}
<span className="right-2 bottom-2 absolute flex items-center gap-1 bg-black/70 px-1.5 py-0.5 rounded font-semibold text-white text-xs tabular-nums pointer-events-none"
title={t('collection/CollectionCard.CountLabel')}>
<LuListMusic aria-hidden="true" className="w-3.5 h-3.5" />{collection.count}
</span>
</Link>
<button
type="button"
onClick={() => toggleFavorite(collection.id, {
added: t('collection/CollectionPage.SubscribeSuccess'),
removed: t('collection/CollectionPage.UnsubscribeSuccess'),
})}
disabled={pending}
aria-pressed={subscribed}
aria-label={subscribeLabel}
title={subscribeLabel}
className={`top-4 right-2 absolute grid place-items-center backdrop-blur-sm rounded-lg w-8 h-8 transition-colors cursor-pointer disabled:cursor-not-allowed disabled:opacity-60 ${subscribed ? 'bg-blue-500/85 hover:bg-blue-500 text-white' : 'bg-black/55 hover:bg-black/70 text-white/85 hover:text-white'}`}
>
{pending ? <LoadingSpinner size={14} /> : <SubscribeIcon subscribed={subscribed} size={15} />}
</button>
</div>
<Link to={href} className="block mt-2.5 font-semibold text-white group-hover:text-blue-200 text-sm truncate no-underline transition-colors">
{collection.name}
</Link>
<div className="mt-0.5 text-white/50 text-xs truncate">{collection.createdBy}</div>
</div>
);
}
Loading
Loading