Clean up various queries
This commit is contained in:
parent
2d62b9d72d
commit
e796b031ea
2 changed files with 39 additions and 41 deletions
|
@ -130,7 +130,7 @@ export const AlbumListGridView = ({ gridRef, itemCount }: any) => {
|
||||||
);
|
);
|
||||||
|
|
||||||
const fetchInitialData = useCallback(() => {
|
const fetchInitialData = useCallback(() => {
|
||||||
const query: Omit<AlbumListQuery, 'startIndex' | 'limit'> = {
|
const query: AlbumListQuery = {
|
||||||
...filter,
|
...filter,
|
||||||
...customFilters,
|
...customFilters,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { MutableRefObject, useCallback, useMemo } from 'react';
|
|
||||||
import type {
|
import type {
|
||||||
BodyScrollEvent,
|
BodyScrollEvent,
|
||||||
ColDef,
|
ColDef,
|
||||||
|
@ -8,23 +7,13 @@ import type {
|
||||||
RowDoubleClickedEvent,
|
RowDoubleClickedEvent,
|
||||||
} from '@ag-grid-community/core';
|
} from '@ag-grid-community/core';
|
||||||
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
||||||
import {
|
|
||||||
useCurrentServer,
|
|
||||||
usePlaylistDetailStore,
|
|
||||||
usePlaylistDetailTablePagination,
|
|
||||||
useSetPlaylistDetailTable,
|
|
||||||
useSetPlaylistDetailTablePagination,
|
|
||||||
} from '/@/renderer/store';
|
|
||||||
import { ListDisplayType } from '/@/renderer/types';
|
|
||||||
import { useQueryClient } from '@tanstack/react-query';
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
import { AnimatePresence } from 'framer-motion';
|
import { AnimatePresence } from 'framer-motion';
|
||||||
import debounce from 'lodash/debounce';
|
import debounce from 'lodash/debounce';
|
||||||
import { useHandleTableContextMenu } from '/@/renderer/features/context-menu';
|
import { MutableRefObject, useCallback, useMemo } from 'react';
|
||||||
import {
|
import { useParams } from 'react-router';
|
||||||
PLAYLIST_SONG_CONTEXT_MENU_ITEMS,
|
import { api } from '/@/renderer/api';
|
||||||
SMART_PLAYLIST_SONG_CONTEXT_MENU_ITEMS,
|
import { queryKeys } from '/@/renderer/api/query-keys';
|
||||||
} from '/@/renderer/features/context-menu/context-menu-items';
|
|
||||||
import { usePlayButtonBehavior } from '/@/renderer/store/settings.store';
|
|
||||||
import {
|
import {
|
||||||
LibraryItem,
|
LibraryItem,
|
||||||
PlaylistSongListQuery,
|
PlaylistSongListQuery,
|
||||||
|
@ -32,15 +21,26 @@ import {
|
||||||
SongListSort,
|
SongListSort,
|
||||||
SortOrder,
|
SortOrder,
|
||||||
} from '/@/renderer/api/types';
|
} from '/@/renderer/api/types';
|
||||||
import { usePlaylistSongList } from '/@/renderer/features/playlists/queries/playlist-song-list-query';
|
|
||||||
import { useParams } from 'react-router';
|
|
||||||
import { usePlayQueueAdd } from '/@/renderer/features/player';
|
|
||||||
import { api } from '/@/renderer/api';
|
|
||||||
import { queryKeys } from '/@/renderer/api/query-keys';
|
|
||||||
import { usePlaylistDetail } from '/@/renderer/features/playlists/queries/playlist-detail-query';
|
|
||||||
import { VirtualGridAutoSizerContainer } from '/@/renderer/components/virtual-grid';
|
import { VirtualGridAutoSizerContainer } from '/@/renderer/components/virtual-grid';
|
||||||
import { getColumnDefs, VirtualTable, TablePagination } from '/@/renderer/components/virtual-table';
|
import { getColumnDefs, TablePagination, VirtualTable } from '/@/renderer/components/virtual-table';
|
||||||
import { useCurrentSongRowStyles } from '/@/renderer/components/virtual-table/hooks/use-current-song-row-styles';
|
import { useCurrentSongRowStyles } from '/@/renderer/components/virtual-table/hooks/use-current-song-row-styles';
|
||||||
|
import { useHandleTableContextMenu } from '/@/renderer/features/context-menu';
|
||||||
|
import {
|
||||||
|
PLAYLIST_SONG_CONTEXT_MENU_ITEMS,
|
||||||
|
SMART_PLAYLIST_SONG_CONTEXT_MENU_ITEMS,
|
||||||
|
} from '/@/renderer/features/context-menu/context-menu-items';
|
||||||
|
import { usePlayQueueAdd } from '/@/renderer/features/player';
|
||||||
|
import { usePlaylistDetail } from '/@/renderer/features/playlists/queries/playlist-detail-query';
|
||||||
|
import { usePlaylistSongList } from '/@/renderer/features/playlists/queries/playlist-song-list-query';
|
||||||
|
import {
|
||||||
|
useCurrentServer,
|
||||||
|
usePlaylistDetailStore,
|
||||||
|
usePlaylistDetailTablePagination,
|
||||||
|
useSetPlaylistDetailTable,
|
||||||
|
useSetPlaylistDetailTablePagination,
|
||||||
|
} from '/@/renderer/store';
|
||||||
|
import { usePlayButtonBehavior } from '/@/renderer/store/settings.store';
|
||||||
|
import { ListDisplayType } from '/@/renderer/types';
|
||||||
|
|
||||||
interface PlaylistDetailContentProps {
|
interface PlaylistDetailContentProps {
|
||||||
tableRef: MutableRefObject<AgGridReactType | null>;
|
tableRef: MutableRefObject<AgGridReactType | null>;
|
||||||
|
@ -97,31 +97,29 @@ export const PlaylistDetailSongListContent = ({ tableRef }: PlaylistDetailConten
|
||||||
const limit = params.endRow - params.startRow;
|
const limit = params.endRow - params.startRow;
|
||||||
const startIndex = params.startRow;
|
const startIndex = params.startRow;
|
||||||
|
|
||||||
const queryKey = queryKeys.playlists.songList(server?.id || '', playlistId, {
|
const query: PlaylistSongListQuery = {
|
||||||
id: playlistId,
|
id: playlistId,
|
||||||
limit,
|
limit,
|
||||||
startIndex,
|
startIndex,
|
||||||
...filters,
|
...filters,
|
||||||
});
|
};
|
||||||
|
|
||||||
|
const queryKey = queryKeys.playlists.songList(
|
||||||
|
server?.id || '',
|
||||||
|
playlistId,
|
||||||
|
query,
|
||||||
|
);
|
||||||
|
|
||||||
if (!server) return;
|
if (!server) return;
|
||||||
|
|
||||||
const songsRes = await queryClient.fetchQuery(
|
const songsRes = await queryClient.fetchQuery(queryKey, async ({ signal }) =>
|
||||||
queryKey,
|
|
||||||
async ({ signal }) =>
|
|
||||||
api.controller.getPlaylistSongList({
|
api.controller.getPlaylistSongList({
|
||||||
apiClientProps: {
|
apiClientProps: {
|
||||||
server,
|
server,
|
||||||
signal,
|
signal,
|
||||||
},
|
},
|
||||||
query: {
|
query,
|
||||||
id: playlistId,
|
|
||||||
limit,
|
|
||||||
startIndex,
|
|
||||||
...filters,
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
{ cacheTime: 1000 * 60 * 1 },
|
|
||||||
);
|
);
|
||||||
|
|
||||||
params.successCallback(songsRes?.items || [], songsRes?.totalRecordCount || 0);
|
params.successCallback(songsRes?.items || [], songsRes?.totalRecordCount || 0);
|
||||||
|
|
Reference in a new issue