90 lines
2.8 KiB
TypeScript
Raw Normal View History

2022-10-28 20:29:04 +08:00
import Tabs from '@/web/components/Tabs'
2023-01-24 16:29:33 +08:00
import { fetchDailyRecommendPlaylists, fetchRecommendedPlaylists } from '@/web/api/playlist'
2022-06-14 23:23:34 +08:00
import { PlaylistApiNames } from '@/shared/api/Playlists'
import { useState } from 'react'
2022-08-03 23:48:39 +08:00
import { useQuery } from '@tanstack/react-query'
2022-10-28 20:29:04 +08:00
import CoverRowVirtual from '@/web/components/CoverRowVirtual'
import PageTransition from '@/web/components/PageTransition'
2022-06-14 23:23:34 +08:00
import { playerWidth, topbarHeight } from '@/web/utils/const'
import { cx, css } from '@emotion/css'
2022-10-28 20:29:04 +08:00
import CoverRow from '@/web/components/CoverRow'
2022-06-14 23:23:34 +08:00
import topbarBackground from '@/web/assets/images/topbar-background.png'
const reactQueryOptions = {
refetchOnWindowFocus: false,
refetchInterval: 1000 * 60 * 60, // 1 hour
2022-06-25 13:47:07 +08:00
refetchOnMount: false,
2022-06-14 23:23:34 +08:00
}
const Recommend = () => {
2022-08-03 23:48:39 +08:00
const { data: dailyRecommendPlaylists, isLoading: isLoadingDaily } = useQuery(
[PlaylistApiNames.FetchDailyRecommendPlaylists],
2022-06-14 23:23:34 +08:00
() => fetchDailyRecommendPlaylists(),
reactQueryOptions
)
2022-08-03 23:48:39 +08:00
const { data: recommendedPlaylists, isLoading: isLoading } = useQuery(
2022-06-14 23:23:34 +08:00
[PlaylistApiNames.FetchRecommendedPlaylists, { limit: 200 }],
() => fetchRecommendedPlaylists({ limit: 200 }),
reactQueryOptions
)
2022-08-03 23:48:39 +08:00
const playlists =
isLoadingDaily || isLoading
? []
2023-01-24 16:29:33 +08:00
: [...(dailyRecommendPlaylists?.recommend || []), ...(recommendedPlaylists?.result || [])]
2022-06-14 23:23:34 +08:00
2022-08-03 23:48:39 +08:00
return <CoverRowVirtual playlists={playlists} />
2022-06-14 23:23:34 +08:00
2022-08-03 23:48:39 +08:00
// return <CoverRow playlists={playlists} />
2022-06-14 23:23:34 +08:00
}
const All = () => {
return <div></div>
}
const categories = [
{ id: 'recommend', name: 'Recommend', component: <Recommend /> },
{ id: 'all', name: 'All', component: <All /> },
{ id: 'featured', name: 'Featured', component: <Recommend /> },
{ id: 'official', name: 'Official', component: <Recommend /> },
{ id: 'charts', name: 'Charts', component: <Recommend /> },
]
const categoriesKeys = categories.map(c => c.id)
type Key = typeof categoriesKeys[number]
const Browse = () => {
const [active, setActive] = useState<Key>('recommend')
return (
<PageTransition>
2022-08-03 23:48:39 +08:00
<div className='relative'>
{/* Topbar background */}
<div
className={cx(
'pointer-events-none fixed top-0 left-10 z-10 hidden lg:block',
css`
height: 230px;
`
)}
2023-01-24 16:29:33 +08:00
style={{
right: `${playerWidth + 32}px`,
backgroundImage: `url(${topbarBackground})`,
}}
2022-08-03 23:48:39 +08:00
></div>
2022-06-14 23:23:34 +08:00
2022-08-03 23:48:39 +08:00
<Tabs
tabs={categories}
value={active}
onChange={category => setActive(category)}
className='absolute top-0 z-10 mt-2.5 px-2.5 lg:mt-0 lg:px-0'
/>
2022-06-14 23:23:34 +08:00
2022-08-03 23:48:39 +08:00
<div className='absolute inset-0 mx-2.5 mt-5 lg:mx-0 lg:mt-0'>
{categories.find(c => c.id === active)?.component}
</div>
2022-06-14 23:23:34 +08:00
</div>
</PageTransition>
)
}
export default Browse