mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-20 11:03:06 +02:00
add play controls to expanded album list item
This commit is contained in:
@@ -105,6 +105,20 @@
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.play-button-group {
|
||||||
|
position: relative;
|
||||||
|
z-index: 10;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.2s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container:hover .play-button-group {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
.background-image {
|
.background-image {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 0;
|
right: 0;
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import {
|
|||||||
} from '/@/renderer/components/item-list/helpers/item-list-state';
|
} from '/@/renderer/components/item-list/helpers/item-list-state';
|
||||||
import { ItemListItem } from '/@/renderer/components/item-list/types';
|
import { ItemListItem } from '/@/renderer/components/item-list/types';
|
||||||
import { albumQueries } from '/@/renderer/features/albums/api/album-api';
|
import { albumQueries } from '/@/renderer/features/albums/api/album-api';
|
||||||
|
import { usePlayer } from '/@/renderer/features/player/context/player-context';
|
||||||
|
import { PlayButtonGroup } from '/@/renderer/features/shared/components/play-button-group';
|
||||||
import { useFastAverageColor } from '/@/renderer/hooks';
|
import { useFastAverageColor } from '/@/renderer/hooks';
|
||||||
import { useDragDrop } from '/@/renderer/hooks/use-drag-drop';
|
import { useDragDrop } from '/@/renderer/hooks/use-drag-drop';
|
||||||
import { ActionIcon } from '/@/shared/components/action-icon/action-icon';
|
import { ActionIcon } from '/@/shared/components/action-icon/action-icon';
|
||||||
@@ -29,6 +31,7 @@ import { Text } from '/@/shared/components/text/text';
|
|||||||
import { useMergedRef } from '/@/shared/hooks/use-merged-ref';
|
import { useMergedRef } from '/@/shared/hooks/use-merged-ref';
|
||||||
import { LibraryItem, Song } from '/@/shared/types/domain-types';
|
import { LibraryItem, Song } from '/@/shared/types/domain-types';
|
||||||
import { DragOperation, DragTarget, DragTargetMap } from '/@/shared/types/drag-and-drop';
|
import { DragOperation, DragTarget, DragTargetMap } from '/@/shared/types/drag-and-drop';
|
||||||
|
import { Play } from '/@/shared/types/types';
|
||||||
|
|
||||||
interface AlbumTracksTableProps {
|
interface AlbumTracksTableProps {
|
||||||
isDark?: boolean;
|
isDark?: boolean;
|
||||||
@@ -50,11 +53,22 @@ interface ExpandedAlbumListItemProps {
|
|||||||
interface TrackRowProps {
|
interface TrackRowProps {
|
||||||
controls: ReturnType<typeof useDefaultItemListControls>;
|
controls: ReturnType<typeof useDefaultItemListControls>;
|
||||||
internalState: ItemListStateActions;
|
internalState: ItemListStateActions;
|
||||||
|
player: ReturnType<typeof usePlayer>;
|
||||||
serverId: string;
|
serverId: string;
|
||||||
song: NonNullable<AlbumTracksTableProps['songs']>[0];
|
song: NonNullable<AlbumTracksTableProps['songs']>[0];
|
||||||
|
songIndex: number;
|
||||||
|
songs: Song[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const TrackRow = ({ controls, internalState, serverId, song }: TrackRowProps) => {
|
const TrackRow = ({
|
||||||
|
controls,
|
||||||
|
internalState,
|
||||||
|
player,
|
||||||
|
serverId,
|
||||||
|
song,
|
||||||
|
songIndex,
|
||||||
|
songs,
|
||||||
|
}: TrackRowProps) => {
|
||||||
const rowId = internalState.extractRowId(song);
|
const rowId = internalState.extractRowId(song);
|
||||||
const isSelected = useItemSelectionState(internalState, rowId);
|
const isSelected = useItemSelectionState(internalState, rowId);
|
||||||
const isDraggingState = useItemDraggingState(internalState, rowId);
|
const isDraggingState = useItemDraggingState(internalState, rowId);
|
||||||
@@ -107,6 +121,13 @@ const TrackRow = ({ controls, internalState, serverId, song }: TrackRowProps) =>
|
|||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const mergedRef = useMergedRef(containerRef, dragRef);
|
const mergedRef = useMergedRef(containerRef, dragRef);
|
||||||
|
|
||||||
|
const handleDoubleClick = useCallback(() => {
|
||||||
|
if (songs && songIndex !== undefined) {
|
||||||
|
player.addToQueueByData(songs, Play.NOW);
|
||||||
|
player.mediaPlayByIndex(songIndex);
|
||||||
|
}
|
||||||
|
}, [player, songs, songIndex]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Text
|
<Text
|
||||||
className={clsx(styles['track-row'], {
|
className={clsx(styles['track-row'], {
|
||||||
@@ -123,6 +144,7 @@ const TrackRow = ({ controls, internalState, serverId, song }: TrackRowProps) =>
|
|||||||
itemType: LibraryItem.SONG,
|
itemType: LibraryItem.SONG,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
onDoubleClick={handleDoubleClick}
|
||||||
ref={mergedRef}
|
ref={mergedRef}
|
||||||
size="sm"
|
size="sm"
|
||||||
>
|
>
|
||||||
@@ -150,18 +172,24 @@ const AlbumTracksTable = ({ isDark, serverId, songs }: AlbumTracksTableProps) =>
|
|||||||
const internalState = useItemListState(getDataFn, extractRowId);
|
const internalState = useItemListState(getDataFn, extractRowId);
|
||||||
|
|
||||||
const controls = useDefaultItemListControls();
|
const controls = useDefaultItemListControls();
|
||||||
|
const player = usePlayer();
|
||||||
|
|
||||||
|
const fullSongs = songs as Song[] | undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={clsx(styles.tracks, { [styles.dark]: isDark })}>
|
<div className={clsx(styles.tracks, { [styles.dark]: isDark })}>
|
||||||
<ScrollArea>
|
<ScrollArea>
|
||||||
<div className={styles['tracks-list']}>
|
<div className={styles['tracks-list']}>
|
||||||
{songs?.map((song) => (
|
{songs?.map((song, index) => (
|
||||||
<TrackRow
|
<TrackRow
|
||||||
controls={controls}
|
controls={controls}
|
||||||
internalState={internalState}
|
internalState={internalState}
|
||||||
key={song.id}
|
key={song.id}
|
||||||
|
player={player}
|
||||||
serverId={serverId}
|
serverId={serverId}
|
||||||
song={song}
|
song={song}
|
||||||
|
songIndex={index}
|
||||||
|
songs={fullSongs || []}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -178,6 +206,8 @@ export const ExpandedAlbumListItem = ({ internalState, item }: ExpandedAlbumList
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const player = usePlayer();
|
||||||
|
|
||||||
const color = useFastAverageColor({
|
const color = useFastAverageColor({
|
||||||
algorithm: 'sqrt',
|
algorithm: 'sqrt',
|
||||||
id: item.id,
|
id: item.id,
|
||||||
@@ -185,6 +215,19 @@ export const ExpandedAlbumListItem = ({ internalState, item }: ExpandedAlbumList
|
|||||||
srcLoaded: true,
|
srcLoaded: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handlePlay = useCallback(
|
||||||
|
(playType: Play) => {
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.songs) {
|
||||||
|
player.addToQueueByData(data.songs, playType);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[data, player],
|
||||||
|
);
|
||||||
|
|
||||||
if (color.isLoading) {
|
if (color.isLoading) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -271,6 +314,11 @@ export const ExpandedAlbumListItem = ({ internalState, item }: ExpandedAlbumList
|
|||||||
backgroundImage: `url(${data?.imageUrl})`,
|
backgroundImage: `url(${data?.imageUrl})`,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
{data?.songs && data.songs.length > 0 && (
|
||||||
|
<div className={styles.playButtonGroup}>
|
||||||
|
<PlayButtonGroup onPlay={handlePlay} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
|
|||||||
Reference in New Issue
Block a user