import useUser from '@/web/api/hooks/useUser' import Appearance from './Appearance' import { css, cx } from '@emotion/css' import { useState } from 'react' import UserCard from './UserCard' import { useTranslation } from 'react-i18next' import { motion, useAnimationControls } from 'framer-motion' import General from './General' import Player from './Player' import PageTransition from '@/web/components/PageTransition' import { ease } from '@/web/utils/const' export const categoryIds = ['general', 'appearance', 'player', 'lyrics', 'lab'] as const export type Category = typeof categoryIds[number] const Sidebar = ({ activeCategory, setActiveCategory, }: { activeCategory: string setActiveCategory: (category: Category) => void }) => { const { t } = useTranslation() const categories: { name: string; id: Category }[] = [ { name: t`settings.general`, id: 'general' }, { name: t`settings.appearance`, id: 'appearance' }, { name: t`settings.player`, id: 'player' }, { name: t`settings.lyrics`, id: 'lyrics' }, { name: t`settings.lab`, id: 'lab' }, ] const animation = useAnimationControls() const onClick = (categoryId: Category) => { setActiveCategory(categoryId) const index = categories.findIndex(category => category.id === categoryId) animation.start({ y: index * 40 + 11.5 }) } return (
{categories.map(category => ( onClick(category.id)} initial={{ x: activeCategory === category.id ? 12 : 0 }} animate={{ x: activeCategory === category.id ? 12 : 0 }} className={cx( 'flex items-center rounded-lg px-3 py-2 font-medium transition-colors duration-500', activeCategory === category.id ? 'text-brand-700' : 'text-white/50 hover:text-white/90' )} > {category.name} ))}
) } const Settings = () => { const [activeCategory, setActiveCategory] = useState('general') const { data: user } = useUser() const categoriesAndComponents: { id: Category; component: JSX.Element }[] = [ { id: 'general', component: }, { id: 'appearance', component: }, { id: 'player', component: }, { id: 'lyrics', component: 开发中 }, { id: 'lab', component: 开发中 }, ] return (
{user?.profile && }
{categoriesAndComponents.map(categoryAndComponent => { if (categoryAndComponent.id === activeCategory) { return (
{categoryAndComponent.component}
) } })}
) } export default Settings