mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 10:03:33 +00:00
enable reordering non-smart playlists
This commit is contained in:
parent
0b383b758e
commit
10fca2dc12
11 changed files with 148 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ import type {
|
|||
IDatasource,
|
||||
PaginationChangedEvent,
|
||||
RowDoubleClickedEvent,
|
||||
RowDragEvent,
|
||||
} from '@ag-grid-community/core';
|
||||
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
|
|
@ -18,6 +19,7 @@ import {
|
|||
LibraryItem,
|
||||
PlaylistSongListQuery,
|
||||
QueueSong,
|
||||
Song,
|
||||
SongListSort,
|
||||
SortOrder,
|
||||
} from '/@/renderer/api/types';
|
||||
|
|
@ -44,6 +46,7 @@ import {
|
|||
import { usePlayButtonBehavior } from '/@/renderer/store/settings.store';
|
||||
import { ListDisplayType } from '/@/renderer/types';
|
||||
import { useAppFocus } from '/@/renderer/hooks';
|
||||
import { toast } from '/@/renderer/components';
|
||||
|
||||
interface PlaylistDetailContentProps {
|
||||
tableRef: MutableRefObject<AgGridReactType | null>;
|
||||
|
|
@ -138,6 +141,42 @@ export const PlaylistDetailSongListContent = ({ tableRef }: PlaylistDetailConten
|
|||
[filters, pagination.scrollOffset, playlistId, queryClient, server],
|
||||
);
|
||||
|
||||
const handleDragEnd = useCallback(
|
||||
async (e: RowDragEvent<Song>) => {
|
||||
if (!e.nodes.length) return;
|
||||
|
||||
const trackId = e.node.data?.playlistItemId;
|
||||
if (trackId && e.node.rowIndex !== null && e.overIndex !== e.node.rowIndex) {
|
||||
try {
|
||||
await api.controller.movePlaylistItem({
|
||||
apiClientProps: {
|
||||
server,
|
||||
},
|
||||
query: {
|
||||
endingIndex: e.overIndex,
|
||||
playlistId,
|
||||
startingIndex: e.node.rowIndex + 1,
|
||||
trackId,
|
||||
},
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.playlists.songList(server?.id || '', playlistId),
|
||||
});
|
||||
e.api.refreshInfiniteCache();
|
||||
}, 200);
|
||||
} catch (error) {
|
||||
toast.error({
|
||||
message: (error as Error).message,
|
||||
title: `Failed to move song ${e.node.data?.name} to ${e.overIndex}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
[playlistId, queryClient, server],
|
||||
);
|
||||
|
||||
const handleGridSizeChange = () => {
|
||||
if (page.table.autoFit) {
|
||||
tableRef?.current?.api?.sizeColumnsToFit();
|
||||
|
|
@ -254,6 +293,9 @@ export const PlaylistDetailSongListContent = ({ tableRef }: PlaylistDetailConten
|
|||
paginationAutoPageSize={isPaginationEnabled}
|
||||
paginationPageSize={pagination.itemsPerPage || 100}
|
||||
rowClassRules={rowClassRules}
|
||||
rowDragEntireRow={
|
||||
filters.sortBy === SongListSort.ID && !detailQuery?.data?.rules
|
||||
}
|
||||
rowHeight={page.table.rowHeight || 40}
|
||||
rowModelType="infinite"
|
||||
onBodyScrollEnd={handleScroll}
|
||||
|
|
@ -264,6 +306,7 @@ export const PlaylistDetailSongListContent = ({ tableRef }: PlaylistDetailConten
|
|||
onGridSizeChanged={handleGridSizeChange}
|
||||
onPaginationChanged={onPaginationChanged}
|
||||
onRowDoubleClicked={handleRowDoubleClick}
|
||||
onRowDragEnd={handleDragEnd}
|
||||
/>
|
||||
</VirtualGridAutoSizerContainer>
|
||||
{isPaginationEnabled && (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue