2023-07-19 20:53:49 -07:00
|
|
|
import type { RowDoubleClickedEvent } from '@ag-grid-community/core';
|
2023-01-13 13:51:19 -08:00
|
|
|
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
2023-07-19 20:53:49 -07:00
|
|
|
import { MutableRefObject } from 'react';
|
|
|
|
|
import { useListContext } from '../../../context/list-context';
|
|
|
|
|
import { LibraryItem, QueueSong, SongListQuery } from '/@/renderer/api/types';
|
2023-04-30 22:01:52 -07:00
|
|
|
import { VirtualGridAutoSizerContainer } from '/@/renderer/components/virtual-grid';
|
2023-07-19 20:53:49 -07:00
|
|
|
import { VirtualTable } from '/@/renderer/components/virtual-table';
|
2023-07-18 18:39:39 -07:00
|
|
|
import { useCurrentSongRowStyles } from '/@/renderer/components/virtual-table/hooks/use-current-song-row-styles';
|
2023-07-19 20:53:49 -07:00
|
|
|
import { useVirtualTable } from '/@/renderer/components/virtual-table/hooks/use-virtual-table';
|
|
|
|
|
import { SONG_CONTEXT_MENU_ITEMS } from '/@/renderer/features/context-menu/context-menu-items';
|
|
|
|
|
import { usePlayQueueAdd } from '/@/renderer/features/player';
|
|
|
|
|
import { useCurrentServer } from '/@/renderer/store';
|
|
|
|
|
import { usePlayButtonBehavior } from '/@/renderer/store/settings.store';
|
2023-01-13 13:51:19 -08:00
|
|
|
|
|
|
|
|
interface AlbumArtistSongListContentProps {
|
2023-07-01 19:10:05 -07:00
|
|
|
data: QueueSong[];
|
|
|
|
|
tableRef: MutableRefObject<AgGridReactType | null>;
|
2023-01-13 13:51:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const AlbumArtistDetailTopSongsListContent = ({
|
2023-07-01 19:10:05 -07:00
|
|
|
tableRef,
|
|
|
|
|
data,
|
2023-01-13 13:51:19 -08:00
|
|
|
}: AlbumArtistSongListContentProps) => {
|
2023-07-01 19:10:05 -07:00
|
|
|
const server = useCurrentServer();
|
2023-07-19 20:53:49 -07:00
|
|
|
const { id, pageKey } = useListContext();
|
2023-01-13 13:51:19 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const handlePlayQueueAdd = usePlayQueueAdd();
|
|
|
|
|
const playButtonBehavior = usePlayButtonBehavior();
|
2023-01-13 13:51:19 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const handleRowDoubleClick = (e: RowDoubleClickedEvent<QueueSong>) => {
|
|
|
|
|
if (!e.data) return;
|
2023-05-20 21:31:00 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const rowData: QueueSong[] = [];
|
|
|
|
|
e.api.forEachNode((node) => {
|
|
|
|
|
if (!node.data) return;
|
|
|
|
|
rowData.push(node.data);
|
|
|
|
|
});
|
2023-05-20 21:31:00 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
handlePlayQueueAdd?.({
|
|
|
|
|
byData: rowData,
|
|
|
|
|
initialSongId: e.data.id,
|
|
|
|
|
playType: playButtonBehavior,
|
|
|
|
|
});
|
|
|
|
|
};
|
2023-01-13 13:51:19 -08:00
|
|
|
|
2023-07-19 20:53:49 -07:00
|
|
|
const customFilters: Partial<SongListQuery> = {
|
|
|
|
|
...(id && { artistIds: [id] }),
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-18 18:39:39 -07:00
|
|
|
const { rowClassRules } = useCurrentSongRowStyles({ tableRef });
|
|
|
|
|
|
2023-07-19 20:53:49 -07:00
|
|
|
const tableProps = useVirtualTable({
|
|
|
|
|
contextMenu: SONG_CONTEXT_MENU_ITEMS,
|
|
|
|
|
customFilters,
|
|
|
|
|
itemType: LibraryItem.SONG,
|
|
|
|
|
pageKey,
|
|
|
|
|
server,
|
|
|
|
|
tableRef,
|
|
|
|
|
});
|
|
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<VirtualGridAutoSizerContainer>
|
|
|
|
|
<VirtualTable
|
2023-07-19 20:53:49 -07:00
|
|
|
key={`table-${tableProps.rowHeight}-${server?.id}`}
|
2023-07-01 19:10:05 -07:00
|
|
|
ref={tableRef}
|
2024-09-02 22:31:20 -07:00
|
|
|
shouldUpdateSong
|
2023-07-19 20:53:49 -07:00
|
|
|
{...tableProps}
|
2024-09-02 22:31:20 -07:00
|
|
|
getRowId={(data) => data.data.id}
|
2023-07-18 18:39:39 -07:00
|
|
|
rowClassRules={rowClassRules}
|
2023-07-01 19:10:05 -07:00
|
|
|
rowData={data}
|
|
|
|
|
rowModelType="clientSide"
|
|
|
|
|
rowSelection="multiple"
|
|
|
|
|
onRowDoubleClicked={handleRowDoubleClick}
|
|
|
|
|
/>
|
|
|
|
|
</VirtualGridAutoSizerContainer>
|
|
|
|
|
</>
|
|
|
|
|
);
|
2023-01-13 13:51:19 -08:00
|
|
|
};
|