Skip to content

Commit

Permalink
fix virtual table for songs, nan, restrict song list filters
Browse files Browse the repository at this point in the history
  • Loading branch information
kgarner7 committed Sep 24, 2024
1 parent 5c7e588 commit b509794
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 25 deletions.
30 changes: 15 additions & 15 deletions src/renderer/api/subsonic/subsonic-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,20 +697,6 @@ export const SubsonicController: ControllerEndpoint = {
totalRecordCount: res.body.randomSongs?.song?.length || 0,
};
},
removeFromPlaylist: async ({ query, apiClientProps }) => {
const res = await ssApiClient(apiClientProps).updatePlaylist({
query: {
playlistId: query.id,
songIndexToRemove: query.songId,
},
});

if (res.status !== 200) {
throw new Error('Failed to add to playlist');
}

return null;
},
getServerInfo: async (args) => {
const { apiClientProps } = args;

Expand Down Expand Up @@ -987,7 +973,7 @@ export const SubsonicController: ControllerEndpoint = {
throw new Error('Failed to get song list count');
}

const songCount = res.body.searchResult3.song?.length;
const songCount = res.body.searchResult3.song?.length || 0;

totalRecordCount += songCount;
startIndex += songCount;
Expand Down Expand Up @@ -1201,6 +1187,20 @@ export const SubsonicController: ControllerEndpoint = {

return url;
},
removeFromPlaylist: async ({ query, apiClientProps }) => {
const res = await ssApiClient(apiClientProps).updatePlaylist({
query: {
playlistId: query.id,
songIndexToRemove: query.songId,
},
});

if (res.status !== 200) {
throw new Error('Failed to add to playlist');
}

return null;
},
scrobble: async (args) => {
const { query, apiClientProps } = args;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export const useVirtualTable = <TFilter extends BaseQuery<any>>({
const hasMoreRows = results?.items?.length === BLOCK_SIZE;
const lastRowIndex = hasMoreRows
? undefined
: (properties.filter.offset || 0) + results.items.length;
: params.startRow + results.items.length;

params.successCallback(
results?.items || [],
Expand Down Expand Up @@ -342,6 +342,7 @@ export const useVirtualTable = <TFilter extends BaseQuery<any>>({
alwaysShowHorizontalScroll: true,
autoFitColumns: properties.table.autoFit,
blockLoadDebounceMillis: 200,
cacheBlockSize: BLOCK_SIZE,
getRowId: (data: GetRowIdParams<any>) => data.data.id,
infiniteInitialRowCount: itemCount || 100,
pagination: isPaginationEnabled,
Expand Down
7 changes: 4 additions & 3 deletions src/renderer/features/player/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,15 @@ export const getSongsByQuery = async (args: {

const res = await queryClient.fetchQuery(
queryKey,
async ({ signal }) =>
api.controller.getSongList({
async ({ signal }) => {
return api.controller.getSongList({
apiClientProps: {
server,
signal,
},
query: queryFilter,
}),
});
},
{
cacheTime: 1000 * 60,
staleTime: 1000 * 60,
Expand Down
13 changes: 8 additions & 5 deletions src/renderer/features/songs/components/subsonic-song-filter.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeEvent, useMemo } from 'react';
import { Divider, Group, Stack } from '@mantine/core';
import debounce from 'lodash/debounce';
import { GenreListSort, LibraryItem, SortOrder } from '/@/renderer/api/types';
import { GenreListSort, LibraryItem, SongListQuery, SortOrder } from '/@/renderer/api/types';
import { Select, Switch, Text } from '/@/renderer/components';
import { useGenreList } from '/@/renderer/features/genres';
import { SongListFilter, useListFilterByKey, useListStoreActions } from '/@/renderer/store';
Expand All @@ -22,9 +22,9 @@ export const SubsonicSongFilters = ({
}: SubsonicSongFiltersProps) => {
const { t } = useTranslation();
const { setFilter } = useListStoreActions();
const filter = useListFilterByKey({ key: pageKey });
const filter = useListFilterByKey<SongListQuery>({ key: pageKey });

const isGenrePage = customFilters?._custom?.navidrome?.genre_id !== undefined;
const isGenrePage = customFilters?.genreIds !== undefined;

const genreListQuery = useGenreList({
query: {
Expand Down Expand Up @@ -58,6 +58,7 @@ export const SubsonicSongFilters = ({

const toggleFilters = [
{
disabled: filter.genreIds !== undefined || isGenrePage || !!filter.searchTerm,
label: t('filter.isFavorited', { postProcess: 'sentenceCase' }),
onChange: (e: ChangeEvent<HTMLInputElement>) => {
const updatedFilters = setFilter({
Expand All @@ -71,7 +72,7 @@ export const SubsonicSongFilters = ({

onFilterChange(updatedFilters);
},
value: filter.isFavorite,
value: filter.favorite,
},
];

Expand All @@ -85,6 +86,7 @@ export const SubsonicSongFilters = ({
<Text>{filter.label}</Text>
<Switch
checked={filter?.value || false}
disabled={filter.disabled}
size="xs"
onChange={filter.onChange}
/>
Expand All @@ -97,7 +99,8 @@ export const SubsonicSongFilters = ({
clearable
searchable
data={genreList}
defaultValue={filter.genre}
defaultValue={filter.genreIds ? filter.genreIds[0] : undefined}
disabled={!!filter.searchTerm}
label={t('entity.genre', { count: 1, postProcess: 'titleCase' })}
width={150}
onChange={handleGenresFilter}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/features/songs/routes/song-list-route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const TrackListRoute = () => {
async (args: { initialSongId?: string; playType: Play }) => {
if (!itemCount || itemCount === 0) return;
const { initialSongId, playType } = args;
const query: SongListQuery = { startIndex: 0, ...songListFilter };
const query: SongListQuery = { ...songListFilter, limit: itemCount, startIndex: 0 };

if (albumArtistId) {
handlePlayQueueAdd?.({
Expand Down

0 comments on commit b509794

Please sign in to comment.