mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 18:13:31 +00:00
* [scuffed bugfix]: Update table rating/favorite when updated anywhere else Modify player store to have temporary state for favorite/rating update Add effect handler for `virtual-table` to update rating/favorite for players Note that this does not handle song grid view. Using a similar handler for gird view did not work, as it appeared to result in inconsistent state. Finally, this is probably not the optimal solution. Performance appears fine for ~20k items, but no guarantees. * restore should update song * update song rating/favorite/played everywhere except playlist * special rule for playlists * use iterator instead
79 lines
2.8 KiB
TypeScript
79 lines
2.8 KiB
TypeScript
import type { RowDoubleClickedEvent } from '@ag-grid-community/core';
|
|
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
|
import { MutableRefObject } from 'react';
|
|
import { useListContext } from '../../../context/list-context';
|
|
import { LibraryItem, QueueSong, SongListQuery } from '/@/renderer/api/types';
|
|
import { VirtualGridAutoSizerContainer } from '/@/renderer/components/virtual-grid';
|
|
import { VirtualTable } from '/@/renderer/components/virtual-table';
|
|
import { useCurrentSongRowStyles } from '/@/renderer/components/virtual-table/hooks/use-current-song-row-styles';
|
|
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';
|
|
|
|
interface AlbumArtistSongListContentProps {
|
|
data: QueueSong[];
|
|
tableRef: MutableRefObject<AgGridReactType | null>;
|
|
}
|
|
|
|
export const AlbumArtistDetailTopSongsListContent = ({
|
|
tableRef,
|
|
data,
|
|
}: AlbumArtistSongListContentProps) => {
|
|
const server = useCurrentServer();
|
|
const { id, pageKey } = useListContext();
|
|
|
|
const handlePlayQueueAdd = usePlayQueueAdd();
|
|
const playButtonBehavior = usePlayButtonBehavior();
|
|
|
|
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: rowData,
|
|
initialSongId: e.data.id,
|
|
playType: playButtonBehavior,
|
|
});
|
|
};
|
|
|
|
const customFilters: Partial<SongListQuery> = {
|
|
...(id && { artistIds: [id] }),
|
|
};
|
|
|
|
const { rowClassRules } = useCurrentSongRowStyles({ tableRef });
|
|
|
|
const tableProps = useVirtualTable({
|
|
contextMenu: SONG_CONTEXT_MENU_ITEMS,
|
|
customFilters,
|
|
itemType: LibraryItem.SONG,
|
|
pageKey,
|
|
server,
|
|
tableRef,
|
|
});
|
|
|
|
return (
|
|
<>
|
|
<VirtualGridAutoSizerContainer>
|
|
<VirtualTable
|
|
key={`table-${tableProps.rowHeight}-${server?.id}`}
|
|
ref={tableRef}
|
|
shouldUpdateSong
|
|
{...tableProps}
|
|
getRowId={(data) => data.data.id}
|
|
rowClassRules={rowClassRules}
|
|
rowData={data}
|
|
rowModelType="clientSide"
|
|
rowSelection="multiple"
|
|
onRowDoubleClicked={handleRowDoubleClick}
|
|
/>
|
|
</VirtualGridAutoSizerContainer>
|
|
</>
|
|
);
|
|
};
|