Update playqueueadd props

This commit is contained in:
jeffvli
2023-05-20 14:55:08 -07:00
parent 7dd56bfb9b
commit 02caf896ff
24 changed files with 53 additions and 44 deletions
@@ -122,7 +122,7 @@ export const CardControls = ({
id: [itemData.id],
type: itemType,
},
play: playType || playButtonBehavior,
playType: playType || playButtonBehavior,
});
};
@@ -134,7 +134,7 @@ export const GridCardControls = ({
id: [itemData.id],
type: itemType,
},
play: playType || playButtonBehavior,
playType: playType || playButtonBehavior,
});
};
@@ -210,7 +210,7 @@ export const AlbumDetailContent = ({ tableRef }: AlbumDetailContentProps) => {
const handlePlay = async (playType?: Play) => {
handlePlayQueueAdd?.({
byData: detailQuery?.data?.songs,
play: playType || playButtonBehavior,
playType: playType || playButtonBehavior,
});
};
@@ -218,9 +218,16 @@ export const AlbumDetailContent = ({ tableRef }: AlbumDetailContentProps) => {
const handleRowDoubleClick = (e: RowDoubleClickedEvent<QueueSong>) => {
if (!e.data) return;
const rowData: QueueSong[] = [];
e.api.forEachNode((node) => {
if (!node.data) return;
rowData.push(node.data);
});
handlePlayQueueAdd?.({
byData: [e.data],
play: playButtonBehavior,
byData: rowData,
playType: playButtonBehavior,
});
};
@@ -294,7 +294,7 @@ export const AlbumListHeaderFilters = ({
const handlePlayQueueAdd = usePlayQueueAdd();
const handlePlay = async (play: Play) => {
const handlePlay = async (playType: Play) => {
if (!itemCount || itemCount === 0 || !server) return;
const query = {
@@ -327,7 +327,7 @@ export const AlbumListHeaderFilters = ({
id: albumIds,
type: LibraryItem.ALBUM,
},
play,
playType,
});
};
@@ -165,7 +165,7 @@ export const AlbumListHeader = ({
const handlePlayQueueAdd = usePlayQueueAdd();
const playButtonBehavior = usePlayButtonBehavior();
const handlePlay = async (play: Play) => {
const handlePlay = async (playType: Play) => {
if (!itemCount || itemCount === 0) return;
const query = {
@@ -198,7 +198,7 @@ export const AlbumListHeader = ({
id: albumIds,
type: LibraryItem.ALBUM,
},
play,
playType,
});
};
@@ -30,7 +30,7 @@ const AlbumDetailRoute = () => {
id: [albumId],
type: LibraryItem.ALBUM,
},
play: playButtonBehavior,
playType: playButtonBehavior,
});
};
@@ -249,7 +249,7 @@ export const AlbumArtistDetailContent = () => {
id: [albumArtistId],
type: LibraryItem.ALBUM_ARTIST,
},
play: playType || playButtonBehavior,
playType: playType || playButtonBehavior,
});
};
@@ -259,7 +259,7 @@ export const AlbumArtistDetailContent = () => {
if (!e.data) return;
handlePlayQueueAdd?.({
byData: [e.data],
play: playButtonBehavior,
playType: playButtonBehavior,
});
};
@@ -36,7 +36,7 @@ export const AlbumArtistDetailTopSongsListContent = ({
if (!e.data) return;
handlePlayQueueAdd?.({
byData: [e.data],
play: playButtonBehavior,
playType: playButtonBehavior,
});
};
@@ -20,10 +20,10 @@ export const AlbumArtistDetailTopSongsListHeader = ({
const handlePlayQueueAdd = usePlayQueueAdd();
const playButtonBehavior = usePlayButtonBehavior();
const handlePlay = async (play: Play) => {
const handlePlay = async (playType: Play) => {
handlePlayQueueAdd?.({
byData: data,
play,
playType,
});
};
@@ -28,7 +28,7 @@ const AlbumArtistDetailRoute = () => {
id: [albumArtistId],
type: LibraryItem.ALBUM_ARTIST,
},
play: playButtonBehavior,
playType: playButtonBehavior,
});
};
@@ -153,34 +153,34 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
});
const handlePlay = useCallback(
(play: Play) => {
(playType: Play) => {
switch (ctx.type) {
case LibraryItem.ALBUM:
handlePlayQueueAdd?.({
byItemType: { id: ctx.data.map((item) => item.id), type: ctx.type },
play,
playType,
});
break;
case LibraryItem.ARTIST:
handlePlayQueueAdd?.({
byItemType: { id: ctx.data.map((item) => item.id), type: ctx.type },
play,
playType,
});
break;
case LibraryItem.ALBUM_ARTIST:
handlePlayQueueAdd?.({
byItemType: { id: ctx.data.map((item) => item.id), type: ctx.type },
play,
playType,
});
break;
case LibraryItem.SONG:
handlePlayQueueAdd?.({ byData: ctx.data, play });
handlePlayQueueAdd?.({ byData: ctx.data, playType });
break;
case LibraryItem.PLAYLIST:
for (const item of ctx.data) {
handlePlayQueueAdd?.({
byItemType: { id: [item.id], type: ctx.type },
play,
playType,
});
}
@@ -154,7 +154,7 @@ export const PlaylistDetailContent = ({ tableRef }: PlaylistDetailContentProps)
id: [playlistId],
type: LibraryItem.PLAYLIST,
},
play: playType || playButtonBehavior,
playType: playType || playButtonBehavior,
});
};
@@ -203,7 +203,7 @@ export const PlaylistDetailContent = ({ tableRef }: PlaylistDetailContentProps)
if (!e.data) return;
handlePlayQueueAdd?.({
byData: [e.data],
play: playButtonBehavior,
playType: playButtonBehavior,
});
};
@@ -214,7 +214,7 @@ export const PlaylistDetailSongListContent = ({ tableRef }: PlaylistDetailConten
if (!e.data) return;
handlePlayQueueAdd?.({
byData: [e.data],
play: playButtonBehavior,
playType: playButtonBehavior,
});
};
@@ -234,7 +234,7 @@ export const PlaylistDetailSongListHeaderFilters = ({
const handlePlay = async (playType: Play) => {
handlePlayQueueAdd?.({
byItemType: { id: [playlistId], type: LibraryItem.PLAYLIST },
play: playType,
playType,
});
};
@@ -31,7 +31,7 @@ export const PlaylistDetailSongListHeader = ({
const handlePlay = async (playType: Play) => {
handlePlayQueueAdd?.({
byItemType: { id: [playlistId], type: LibraryItem.PLAYLIST },
play: playType,
playType,
});
};
@@ -35,7 +35,7 @@ const PlaylistDetailRoute = () => {
id: [playlistId],
type: LibraryItem.PLAYLIST,
},
play: playButtonBehavior,
playType: playButtonBehavior,
});
};
@@ -89,14 +89,14 @@ export const LibraryCommandItem = ({
}
const handlePlay = useCallback(
(e: MouseEvent, id: string, play: Play) => {
(e: MouseEvent, id: string, playType: Play) => {
e.stopPropagation();
handlePlayQueueAdd?.({
byItemType: {
id,
type: itemType,
},
play,
playType,
});
},
[handlePlayQueueAdd, itemType],
@@ -110,7 +110,7 @@ export const SearchContent = ({ tableRef, getDatasource }: SearchContentProps) =
case LibraryItem.SONG:
handlePlayQueueAdd?.({
byData: [e.data],
play: playButtonBehavior,
playType: playButtonBehavior,
});
break;
}
@@ -119,13 +119,13 @@ export const SidebarPlaylistList = ({ data }: SidebarPlaylistListProps) => {
const [debounced] = useDebouncedValue(rect, 25);
const handlePlayPlaylist = useCallback(
(id: string, play: Play) => {
(id: string, playType: Play) => {
handlePlayQueueAdd?.({
byItemType: {
id: [id],
type: LibraryItem.PLAYLIST,
},
play,
playType,
});
},
[handlePlayQueueAdd],
@@ -162,7 +162,7 @@ export const SongListContent = ({ itemCount, tableRef }: SongListContentProps) =
if (!e.data) return;
handlePlayQueueAdd?.({
byData: [e.data],
play: playButtonBehavior,
playType: playButtonBehavior,
});
};
@@ -261,7 +261,7 @@ export const SongListHeaderFilters = ({
handleFilterChange(filter);
};
const handlePlay = async (play: Play) => {
const handlePlay = async (playType: Play) => {
if (!itemCount || itemCount === 0) return;
const query: SongListQuery = { startIndex: 0, ...filter, ...customFilters };
@@ -270,7 +270,7 @@ export const SongListHeaderFilters = ({
id: query,
type: LibraryItem.SONG,
},
play,
playType,
});
};
@@ -94,7 +94,7 @@ export const SongListHeader = ({
const playButtonBehavior = usePlayButtonBehavior();
const handlePlay = async (play: Play) => {
const handlePlay = async (playType: Play) => {
if (!itemCount || itemCount === 0) return;
const query: SongListQuery = { startIndex: 0, ...filter, ...customFilters };
@@ -103,7 +103,7 @@ export const SongListHeader = ({
id: query,
type: LibraryItem.SONG,
},
play,
playType,
});
};
+6 -5
View File
@@ -56,7 +56,7 @@ export interface QueueData {
export interface PlayerSlice extends PlayerState {
actions: {
addToQueue: (songs: QueueSong[], type: Play) => PlayerData;
addToQueue: (args: { initialIndex: number; playType: Play; songs: QueueSong[] }) => PlayerData;
autoNext: () => PlayerData;
checkIsFirstTrack: () => boolean;
checkIsLastTrack: () => boolean;
@@ -95,7 +95,8 @@ export const usePlayerStore = create<PlayerSlice>()(
devtools(
immer((set, get) => ({
actions: {
addToQueue: (songs, type) => {
addToQueue: (args) => {
const { playType, songs } = args;
const { shuffledIndex } = get().current;
const shuffledQueue = get().queue.shuffled;
const queueSongs = map(songs, (song) => ({
@@ -103,7 +104,7 @@ export const usePlayerStore = create<PlayerSlice>()(
uniqueId: nanoid(),
}));
if (type === Play.NOW) {
if (playType === Play.NOW) {
if (get().shuffle === PlayerShuffle.TRACK) {
const shuffledSongs = shuffle(queueSongs);
const foundIndex = queueSongs.findIndex(
@@ -131,7 +132,7 @@ export const usePlayerStore = create<PlayerSlice>()(
state.current.song = queueSongs[0];
});
}
} else if (type === Play.LAST) {
} else if (playType === Play.LAST) {
// Shuffle the queue after the current track
const shuffledQueueWithNewSongs =
get().shuffle === PlayerShuffle.TRACK
@@ -148,7 +149,7 @@ export const usePlayerStore = create<PlayerSlice>()(
state.queue.default = [...get().queue.default, ...queueSongs];
state.queue.shuffled = shuffledQueueWithNewSongs;
});
} else if (type === Play.NEXT) {
} else if (playType === Play.NEXT) {
const queue = get().queue.default;
const currentIndex = get().current.index;
+2 -1
View File
@@ -154,7 +154,8 @@ export type PlayQueueAddOptions = {
id: string[] | any;
type: LibraryItem;
};
play: Play;
initialIndex?: number;
playType: Play;
};
export type GridCardData = {