import React, { useEffect, useState } from 'react' import { css, cx } from '@emotion/css' import Icon from '../Icon' import { useLocation, useNavigate } from 'react-router-dom' import { useAnimation, motion } from 'framer-motion' import { ease } from '@/web/utils/const' import useIsMobile from '@/web/hooks/useIsMobile' import { breakpoint as bp } from '@/web/utils/const' import { useSnapshot } from 'valtio' import uiStates from '@/web/states/uiStates' import persistedUiStates from '@/web/states/persistedUiStates' const tabs = [ { name: 'MY MUSIC', path: '/', icon: 'my', }, { name: 'DISCOVER', path: '/discover', icon: 'explore', }, { name: 'BROWSE', path: '/browse', icon: 'discovery', }, { name: 'LYRICS', path: '/lyrics', icon: 'lyrics', }, ] as const const getNameByPath = (path: string): string => { return tabs.find(tab => tab.path === path)?.name || '' } const TabName = () => { const location = useLocation() const [name, setName] = useState(getNameByPath(location.pathname)) const controls = useAnimation() useEffect(() => { const newName = getNameByPath(location.pathname) const animate = async () => { await controls.start('out') setName(newName) await controls.start('in') } if (newName !== name) animate() }, [controls, location.pathname, name]) return (
{name}
) } const Tabs = () => { const location = useLocation() const navigate = useNavigate() const controls = useAnimation() const [active, setActive] = useState( location.pathname || tabs[0].path ) const animate = async (path: string) => { await controls.start((p: string) => p === path && location.pathname !== path ? 'scale' : 'reset' ) await controls.start('reset') } return (
{tabs.map(tab => ( { if ('vibrate' in navigator) { navigator.vibrate(20) } animate(tab.path) }} onClick={() => { setActive(tab.path) navigate(tab.path) }} custom={tab.path} variants={{ scale: { scale: 0.8 }, reset: { scale: 1 }, }} className={cx( active === tab.path ? 'text-brand-600 dark:text-brand-700' : 'lg:hover:text-black lg:dark:hover:text-white' )} > ))}
) } const MenuBar = () => { const isMobile = useIsMobile() return (
{!isMobile && }
) } export default MenuBar