Skip to content

Commit

Permalink
fix: fixed my page and browse
Browse files Browse the repository at this point in the history
  • Loading branch information
Sherlockouo committed Dec 4, 2023
1 parent 78c7163 commit bf29b6a
Show file tree
Hide file tree
Showing 18 changed files with 360 additions and 184 deletions.
2 changes: 1 addition & 1 deletion packages/web/components/ArtistRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const ArtistRow = ({

{/* Artists */}
{artists && (
<div className='no-scrollbar grid w-auto grid-cols-4 grid-cols-5 gap-x-10 gap-y-8 @3xl:grid-cols-5 @7xl:grid-cols-7'>
<div className='no-scrollbar grid w-auto grid-cols-5 gap-x-10 gap-y-8 @3xl:grid-cols-5 @7xl:grid-cols-7'>
{artists.map(artist => (
<div className='snap-start px-2.5 lg:px-0' key={artist.id}>
<Artist artist={artist} key={artist.id} />
Expand Down
20 changes: 11 additions & 9 deletions packages/web/components/CoverRowVirtual.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { prefetchAlbum } from '@/web/api/hooks/useAlbum'
import { prefetchPlaylist } from '@/web/api/hooks/usePlaylist'
import { Virtuoso } from 'react-virtuoso'
import { useTranslation } from 'react-i18next'
import {
import React, {
CSSProperties,
FC,
ReactNode,
Expand All @@ -18,20 +18,21 @@ import {
} from 'react'
import { createPortal } from 'react-dom'
import humanNumber from 'human-number'
import { useWhyDidYouUpdate } from 'ahooks'

const CoverRow = ({
albums,
playlists,
title,
className,
Footer,
}: {
title?: string
className?: string
albums?: Album[]
playlists?: Playlist[]
containerClassName?: string
containerStyle?: CSSProperties
Footer?:React.FC
}) => {
const navigate = useNavigate()
const { showTrackListName } = useSettings()
Expand Down Expand Up @@ -219,19 +220,20 @@ const CoverRow = ({
style={{
height: 'calc(100vh - 132px)',
}}
components={{
Footer:Footer
}}
data={rows}
overscan={15}
overscan={75}
itemSize={el => el.getBoundingClientRect().height + 24}
totalCount={rows.length}
components={{
Header: () => <div className={cx('ease-in-out')}></div>,
// Footer: () => <div className='h-16'></div>,
}}
itemContent={(index, row) => (
<div key={index} className='grid w-full grid-cols-4 gap-4 lg:mb-6 lg:gap-6'>
{row.map((item: Item) => (
{
row.map((item: Item) => (
<CoverItem key={item.id} item={item} />
))}
))
}
</div>
)}
/>
Expand Down
4 changes: 2 additions & 2 deletions packages/web/components/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ function Tabs<T>({
<div
key={tab.id as string}
className={cx(
'mr-1 rounded-12 py-3 px-6 text-16 font-medium backdrop-blur transition duration-500',
'whitespace-nowrap mr-1 rounded-12 py-3 px-6 text-16 font-medium backdrop-blur transition duration-500',
'dark:bg-white/10 dark:text-white/80 hover:dark:bg-white/20 ',
'bg-black/10 text-black/80 hover:bg-black/20',
value === tab.id &&
'bg-accent-color-500 text-black/80 dark:bg-neutral-500 dark:text-white/80',
tab.iconName && 'iterms-center flex flex-row gap-1 whitespace-nowrap'
tab.iconName && 'iterms-center flex flex-row gap-1 '
)}
onClick={() => onChange(tab.id)}
>
Expand Down
100 changes: 100 additions & 0 deletions packages/web/components/TrackList/Track.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import Icon from '@/web/components/Icon'
import Wave from '@/web/components/Animation/Wave'
import { formatDuration, resizeImage } from '@/web/utils/common'
import { State as PlayerState } from '@/web/utils/player'
import { css, cx } from '@emotion/css'
import { Fragment, useEffect } from 'react'
import { NavLink } from 'react-router-dom'
import React from 'react'

const Track = ({
track,
index,
playingTrackID,
state,
handleClick,
}: {
track?: Track
index: number
playingTrackID: number
state: PlayerState
handleClick: (e: React.MouseEvent<HTMLElement>, trackID: number) => void
}) => {
return (
<div
className={cx(
'mb-5 grid',
css`
grid-template-columns: 3fr 2fr 1fr;
`
)}
onClick={e => track && handleClick(e, track.id)}
onContextMenu={e => track && handleClick(e, track.id)}
>
{/* Right part */}
<div className='flex items-center'>
{/* Cover */}
<img
alt='Cover'
className='mr-4 aspect-square h-14 w-14 flex-shrink-0 rounded-12'
src={resizeImage(track?.al?.picUrl || '', 'sm')}
/>

{/* Track Name and Artists */}
<div className='mr-3'>
<div
className={cx(
'line-clamp-1 flex items-center text-16 font-medium transition-colors duration-500',
playingTrackID === track?.id
? 'text-brand-700'
: 'text-neutral-700 dark:text-neutral-200'
)}
>
{track?.name}

{[1318912, 1310848].includes(track?.mark || 0) && (
<Icon name='explicit' className='ml-2 mt-px mr-4 h-3.5 w-3.5 ' />
)}
</div>
<div className='line-clamp-1 mt-1 text-14 font-bold '>
{track?.ar.map((a, index) => (
<Fragment key={a.id + Math.random() * 3.14159}>
{index > 0 && ', '}
<NavLink
className='transition-all duration-300 hover:text-black/70 dark:hover:text-white/70'
to={`/artist/${a.id}`}
>
{a.name}
</NavLink>
</Fragment>
))}
</div>
</div>

{/* Wave icon */}
{playingTrackID === track?.id && (
<div className='ml-5'>
<Wave playing={state === 'playing'} />
</div>
)}
</div>

{/* Album Name */}
<div className='flex items-center'>
<NavLink
to={`/album/${track?.al?.id}`}
className='line-clamp-1 text-14 font-bold transition-colors duration-300 hover:text-white/70'
>
{track?.al?.name}
</NavLink>
</div>

{/* Duration */}
<div className='line-clamp-1 flex items-center justify-end text-14 font-bold'>
{formatDuration(track?.dt || 0, 'en-US', 'hh:mm:ss')}
</div>
</div>
)
}

export default Track
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { formatDuration } from '@/web/utils/common'
import { css, cx } from '@emotion/css'
import player from '@/web/states/player'
import { useSnapshot } from 'valtio'
import Wave from './Animation/Wave'
import Wave from '../Animation/Wave'
import Icon from '@/web/components/Icon'
import useIsMobile from '@/web/hooks/useIsMobile'
import useUserLikedTracksIDs, { useMutationLikeATrack } from '@/web/api/hooks/useUserLikedTracksIDs'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { css, cx } from '@emotion/css'
import { Fragment, useEffect } from 'react'
import { NavLink } from 'react-router-dom'
import { useSnapshot } from 'valtio'
import react from '@vitejs/plugin-react-swc'
import React from 'react'
import { Virtuoso } from 'react-virtuoso'

Expand Down Expand Up @@ -109,12 +108,14 @@ function TrackList({
onPlay,
className,
isLoading,
Header,
}: {
tracks?: Track[]
onPlay: (id: number) => void
className?: string
isLoading?: boolean
placeholderRows?: number
Header?: React.FC
}) {
const { trackID, state } = useSnapshot(player)
let playingTrack = tracks?.find(track => track.id === trackID)
Expand All @@ -136,20 +137,20 @@ function TrackList({

if (e.detail === 2) onPlay?.(trackID)
}

return (
<div className={className}>
<div className={cx('@container',className)}>
<Virtuoso
className='no-scrollbar'
className=' no-scrollbar'
style={{
height: 'calc(100vh - 132px)',
}}
data={tracks}
overscan={20}
components={{
Header
}}
itemSize={el => el.getBoundingClientRect().height + 24}
totalCount={tracks?.length}
itemContent={(index, row) => (
<div key={index} className='h-full mb-1'>
itemContent={(index) => (
<Track
key={tracks![index]?.id || 0}
track={tracks![index] || undefined}
Expand All @@ -158,14 +159,13 @@ function TrackList({
state={state}
handleClick={handleClick}
/>
</div>
)}
/>
</div>
)
}

const TrackListMemo = React.memo(TrackList)
TrackListMemo.displayName = "TrackList"
const TrackListVirtualMemo = React.memo(TrackList)
TrackListVirtualMemo.displayName = "TrackListVirtual"

export default TrackListMemo
export default TrackListVirtualMemo
32 changes: 20 additions & 12 deletions packages/web/hooks/useIntersectionObserver.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import { useState, useEffect, RefObject } from 'react'
import { useState, useEffect, RefObject } from 'react';

const useIntersectionObserver = (element: RefObject<Element>): { onScreen: boolean } => {
const [onScreen, setOnScreen] = useState(false)
const [onScreen, setOnScreen] = useState(false);

useEffect(() => {
if (element.current) {
const observer = new IntersectionObserver(([entry]) => setOnScreen(entry.isIntersecting))
observer.observe(element.current)
return () => {
observer.disconnect()
}
const supportsIntersectionObserver = 'IntersectionObserver' in window;

if (!supportsIntersectionObserver || !element?.current) {
console.warn('Intersection Observer is not supported in this browser or element is undefined.');
return;
}
}, [element, setOnScreen])

const observer = new IntersectionObserver(([entry]) => {
setOnScreen(entry.isIntersecting)
},{threshold:0});
observer.observe(element.current);

return () => {
observer.disconnect();
};
}, [element, setOnScreen]);

return {
onScreen,
}
}
};
};

export default useIntersectionObserver
export default useIntersectionObserver;
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"react-router-dom": "^6.6.1",
"react-use": "^17.4.0",
"react-use-measure": "^2.1.1",
"react-virtuoso": "^2.16.6",
"react-virtuoso": "^4.6.2",
"valtio": "^1.8.0",
"web-audio-api": "^0.2.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/web/pages/Album/Album.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import useAlbum from '@/web/api/hooks/useAlbum'
import useTracks from '@/web/api/hooks/useTracks'
import { useParams } from 'react-router-dom'
import PageTransition from '@/web/components/PageTransition'
import TrackList from '@/web/components/TrackList'
import TrackList from '@/web/components/TrackList/TrackList'
import player from '@/web/states/player'
import toast from 'react-hot-toast'
import { useCallback } from 'react'
Expand Down
2 changes: 1 addition & 1 deletion packages/web/pages/Artist/ArtistSongs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'
import useArtistSongs from '@/web/api/hooks/useArtistSongs'
import useTracks from '@/web/api/hooks/useTracks'
import { FetchArtistSongsParams } from '@/shared/api/Artist'
import TrackList from '../Playlist/TrackList'
import TrackList from '../../components/TrackList/TrackListVirtual'
import player from '@/web/states/player'
import { useParams } from 'react-router-dom'
import ScrollPagination from '@/web/components/ScrollPage'
Expand Down
Loading

0 comments on commit bf29b6a

Please sign in to comment.