diff --git a/src/components/chart/RadarPlot.tsx b/src/components/chart/RadarPlot.tsx index bb190692..0c1c705c 100644 --- a/src/components/chart/RadarPlot.tsx +++ b/src/components/chart/RadarPlot.tsx @@ -40,7 +40,9 @@ export default function RadarPlot({ feature }: RadarPlotProps) { return ( `${label}: ${values[i] ?? '—'}`).join(', ')}; ${estiLabel}: ${esti?.toFixed(2) ?? '—'}`} diff --git a/src/components/collection/CollectionCard.tsx b/src/components/collection/CollectionCard.tsx index 06c091ed..59c86183 100644 --- a/src/components/collection/CollectionCard.tsx +++ b/src/components/collection/CollectionCard.tsx @@ -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()); @@ -117,7 +118,7 @@ const CollectionCardContent = memo(({ collection, isManaging, onDelete }: Collec - {/* Favorite button */} + {/* 订阅按钮:和歌单页的“订阅”是同一个操作、同样的提示(以前这里叫“收藏”、是爱心) */} {!isManaging && ( { 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 ? ( - - ) : isFavorited ? ( - - ) : ( - - )} + {isFavoriteLoading ? : } )} diff --git a/src/components/collection/CollectionSubscribeButton.tsx b/src/components/collection/CollectionSubscribeButton.tsx index 02b9f25a..53f5c339 100644 --- a/src/components/collection/CollectionSubscribeButton.tsx +++ b/src/components/collection/CollectionSubscribeButton.tsx @@ -28,17 +28,24 @@ export default function CollectionSubscribeButton({ collectionId }: { collection > {isLoadingFavorites || isSubscriptionPending ? ( - ) : isSubscribed ? ( - ) : ( - + )} {isSubscribed ? t("collection/CollectionPage.Subscribed") : t("collection/CollectionPage.Subscribe")} ); } + +/** 订阅图标:没订阅是铃铛,订阅了是对勾(歌单页按钮和歌单卡片共用) */ +export function SubscribeIcon({ subscribed, size }: { subscribed: boolean; size: number }) { + return subscribed ? ( + + ) : ( + + ); +} diff --git a/src/components/header/AuthSection.tsx b/src/components/header/AuthSection.tsx index 59bd2d67..3a2766b8 100644 --- a/src/components/header/AuthSection.tsx +++ b/src/components/header/AuthSection.tsx @@ -30,12 +30,12 @@ export default function AuthSection() { {/* 移动端:下拉菜单形式 */}
setIsMobileAuthMenuOpen(false)} position="right" className="p-1.5 w-[min(13rem,calc(100vw-1.5rem))]"> diff --git a/src/components/header/HeaderSearch.tsx b/src/components/header/HeaderSearch.tsx new file mode 100644 index 00000000..44096cbd --- /dev/null +++ b/src/components/header/HeaderSearch.tsx @@ -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(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 ( +
+ +
+ ); + } + + return ( +
+ + {open && ( + // 盖住整条顶栏:和顶栏一样高、一样的底色 +
+ {/* 搜索框不铺满整条顶栏:最宽 36rem,居中,关闭按钮紧挨在右边;手机上自然占满 */} +
+ + +
+
+ )} +
+ ); +} diff --git a/src/components/header/LanguageMenu.tsx b/src/components/header/LanguageMenu.tsx index d70762ec..987bec90 100644 --- a/src/components/header/LanguageMenu.tsx +++ b/src/components/header/LanguageMenu.tsx @@ -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() { @@ -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" diff --git a/src/components/header/UserMenu.tsx b/src/components/header/UserMenu.tsx index b3ef3871..90fd4cb1 100644 --- a/src/components/header/UserMenu.tsx +++ b/src/components/header/UserMenu.tsx @@ -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'; @@ -71,13 +72,13 @@ export default function UserMenu({ username }: UserMenuProps) { +
+ + {collection.name} + +
{collection.createdBy}
+ + ); +} diff --git a/src/components/home/CollectionsRow.tsx b/src/components/home/CollectionsRow.tsx index 2701efc4..db5ad706 100644 --- a/src/components/home/CollectionsRow.tsx +++ b/src/components/home/CollectionsRow.tsx @@ -1,116 +1,39 @@ -import { useLayoutEffect, useRef, useState, type CSSProperties } from 'react'; import { useTranslation } from 'react-i18next'; import { Link } from 'react-router-dom'; import useSWR from 'swr'; -import { Swiper, SwiperSlide } from 'swiper/react'; -import { FreeMode, Mousewheel } from 'swiper/modules'; -import type { Swiper as SwiperInstance } from 'swiper'; -import 'swiper/css'; -import 'swiper/css/free-mode'; -import { NATIVE_SCROLL } from './touchScroll'; import { LuChevronRight } from 'react-icons/lu'; import { endpoints } from '@/config/api'; import { apiFetcher } from '@/utils/apiClient'; -import CollectionCard from '@/components/collection/CollectionCard'; -import { CARD_SURFACE_CLASS } from '@/components/ui/surface'; -import { CarouselHeader } from './carousel'; +import CollectionTile from './CollectionTile'; +import TileRow from './TileRow'; import type { Collection } from '@/types'; const COUNT = 12; -/** 卡片阴影向两边扩散的宽度(CARD_SURFACE_CLASS 里最大的那层阴影:60px 模糊) */ -const SHADOW_BLEED = 60; /** - * 滑动区域往内容列两边各伸出多少:最多是阴影的宽度,但不能超出屏幕边缘 - * (超出的话手机会把整页缩小,桌面窄窗口也会多出横向滚动) - */ -function useShadowBleed() { - const ref = useRef(null); - const [bleed, setBleed] = useState(0); - useLayoutEffect(() => { - const element = ref.current; - if (!element) return; - const measure = () => { - const rect = element.getBoundingClientRect(); - const room = Math.min(rect.left, document.documentElement.clientWidth - rect.right); - setBleed(Math.max(0, Math.min(SHADOW_BLEED, Math.floor(room)))); - }; - measure(); - const observer = new ResizeObserver(measure); - observer.observe(element); - window.addEventListener('resize', measure); - return () => { - observer.disconnect(); - window.removeEventListener('resize', measure); - }; - }, []); - return [ref, bleed] as const; -} - -/** - * 首页“歌单广场”横栏:歌单广场第一页的歌单,和最近上传一样横向自由滑动,标题旁边可以进入完整的歌单广场。 + * 首页“歌单广场”横栏:歌单广场第一页的歌单,和上面的谱面横栏同一种版式(大封面、横向自由滑动), + * 卡片做成播放列表的样子;标题旁边可以进入完整的歌单广场。 */ export default function CollectionsRow() { const { t } = useTranslation(); const { data } = useSWR(endpoints.collection.list(0, COUNT), apiFetcher, { revalidateOnFocus: false }); - const [swiper, setSwiper] = useState(null); - const [sectionRef, bleed] = useShadowBleed(); if (data && data.length === 0) return null; - const step = (direction: -1 | 1) => { - if (!swiper || !data) return; - const shown = Math.max(1, Math.floor((swiper.width - 2 * bleed) / ((swiper.slides[0]?.offsetWidth ?? swiper.width) + 12))); - swiper.slideTo(Math.max(0, Math.min(data.length - 1, swiper.activeIndex + direction * shown))); - }; - return ( -
- - {t('home/HomeHighlights.CollectionsHint')} - - {t('home/HomeHighlights.ViewAll')}
+ + {t('home/HomeHighlights.CollectionsHint')} + + {t('home/HomeHighlights.ViewAll')}