Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[slightly less scuffed bugfix]: Update table rating/favorite when updated anywhere … #707

Merged
merged 6 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/remote/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ export const useRemoteStore = create<SettingsSlice>()(
}
case 'song': {
set((state) => {
console.log(data);
state.info.song = data;
});
break;
Expand Down
130 changes: 0 additions & 130 deletions src/renderer/components/virtual-table/hooks/use-rating.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/renderer/components/virtual-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { NoteCell } from '/@/renderer/components/virtual-table/cells/note-cell';
import { RowIndexCell } from '/@/renderer/components/virtual-table/cells/row-index-cell';
import i18n from '/@/i18n/i18n';
import { formatDateAbsolute, formatDateRelative, formatSizeString } from '/@/renderer/utils/format';
import { useTableChange } from '/@/renderer/hooks/use-song-change';

export * from './table-config-dropdown';
export * from './table-pagination';
Expand Down Expand Up @@ -475,6 +476,7 @@ export interface VirtualTableProps extends AgGridReactProps {
pagination: TablePaginationType;
setPagination: any;
};
shouldUpdateSong?: boolean;
stickyHeader?: boolean;
transparentHeader?: boolean;
}
Expand All @@ -492,6 +494,7 @@ export const VirtualTable = forwardRef(
onGridReady,
onGridSizeChanged,
paginationProps,
shouldUpdateSong,
...rest
}: VirtualTableProps,
ref: Ref<AgGridReactType | null>,
Expand All @@ -506,6 +509,8 @@ export const VirtualTable = forwardRef(
}
});

useTableChange(tableRef, shouldUpdateSong === true);

const defaultColumnDefs: ColDef = useMemo(() => {
return {
lockPinned: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ export const AlbumDetailContent = ({ tableRef, background }: AlbumDetailContentP
key={`table-${tableConfig.rowHeight}`}
ref={tableRef}
autoHeight
shouldUpdateSong
stickyHeader
suppressCellFocus
suppressLoadingOverlay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,14 +560,15 @@ export const AlbumArtistDetailContent = ({ background }: AlbumArtistDetailConten
autoFitColumns
autoHeight
deselectOnClickOutside
shouldUpdateSong
stickyHeader
suppressCellFocus
suppressHorizontalScroll
suppressLoadingOverlay
suppressRowDrag
columnDefs={topSongsColumnDefs}
enableCellChangeFlash={false}
getRowId={(data) => data.data.uniqueId}
getRowId={(data) => data.data.id}
rowData={topSongs}
rowHeight={60}
rowSelection="multiple"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ export const AlbumArtistDetailTopSongsListContent = ({
<VirtualTable
key={`table-${tableProps.rowHeight}-${server?.id}`}
ref={tableRef}
shouldUpdateSong
{...tableProps}
getRowId={(data) => data.data.uniqueId}
getRowId={(data) => data.data.id}
rowClassRules={rowClassRules}
rowData={data}
rowModelType="clientSide"
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/features/player/mutations/scrobble-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { api } from '/@/renderer/api';
import { ScrobbleResponse, ScrobbleArgs } from '/@/renderer/api/types';
import { MutationOptions } from '/@/renderer/lib/react-query';
import { getServerById, useIncrementQueuePlayCount } from '/@/renderer/store';
import { usePlayEvent } from '/@/renderer/store/event.store';

export const useSendScrobble = (options?: MutationOptions) => {
const incrementPlayCount = useIncrementQueuePlayCount();
const sendPlayEvent = usePlayEvent();

return useMutation<
ScrobbleResponse,
Expand All @@ -23,6 +25,7 @@ export const useSendScrobble = (options?: MutationOptions) => {
// Manually increment the play count for the song in the queue if scrobble was submitted
if (variables.query.submission) {
incrementPlayCount([variables.query.id]);
sendPlayEvent([variables.query.id]);
}
},
...options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,14 @@ export const PlaylistDetailContent = ({ tableRef }: PlaylistDetailContentProps)
autoFitColumns
autoHeight
deselectOnClickOutside
shouldUpdateSong
stickyHeader
suppressCellFocus
suppressHorizontalScroll
suppressLoadingOverlay
suppressRowDrag
columnDefs={columnDefs}
getRowId={(data) => {
// It's possible that there are duplicate song ids in a playlist
return `${data.data.id}-${data.data.pageIndex}`;
}}
getRowId={(data) => `${data.data.id}-${data.data.pageIndex}`}
rowClassRules={rowClassRules}
rowData={playlistSongData}
rowHeight={60}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export const PlaylistDetailSongListContent = ({ tableRef }: PlaylistDetailConten
key={`table-${page.display}-${page.table.rowHeight}-${server?.id}`}
ref={tableRef}
alwaysShowHorizontalScroll
shouldUpdateSong
autoFitColumns={page.table.autoFit}
columnDefs={columnDefs}
context={{
Expand Down
1 change: 1 addition & 0 deletions src/renderer/features/search/components/search-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const SearchContent = ({ tableRef }: SearchContentProps) => {
getRowId={(data) => data.data.id}
infiniteInitialRowCount={25}
rowClassRules={rowClassRules}
shouldUpdateSong={itemType === LibraryItem.SONG}
onRowDoubleClicked={handleRowDoubleClick}
/>
</VirtualGridAutoSizerContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { MutationHookArgs } from '/@/renderer/lib/react-query';
import { getServerById, useSetAlbumListItemDataById, useSetQueueFavorite } from '/@/renderer/store';
import isElectron from 'is-electron';
import { useFavoriteEvent } from '/@/renderer/store/event.store';

const remote = isElectron() ? window.electron.remote : null;

Expand All @@ -20,6 +21,7 @@ export const useCreateFavorite = (args: MutationHookArgs) => {
const queryClient = useQueryClient();
const setAlbumListData = useSetAlbumListItemDataById();
const setQueueFavorite = useSetQueueFavorite();
const setFavoriteEvent = useFavoriteEvent();

return useMutation<
FavoriteResponse,
Expand Down Expand Up @@ -47,6 +49,7 @@ export const useCreateFavorite = (args: MutationHookArgs) => {
if (variables.query.type === LibraryItem.SONG) {
remote?.updateFavorite(true, serverId, variables.query.id);
setQueueFavorite(variables.query.id, true);
setFavoriteEvent(variables.query.id, true);
}

// We only need to set if we're already on the album detail page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { MutationHookArgs } from '/@/renderer/lib/react-query';
import { getServerById, useSetAlbumListItemDataById, useSetQueueFavorite } from '/@/renderer/store';
import isElectron from 'is-electron';
import { useFavoriteEvent } from '/@/renderer/store/event.store';

const remote = isElectron() ? window.electron.remote : null;

Expand All @@ -20,6 +21,7 @@ export const useDeleteFavorite = (args: MutationHookArgs) => {
const queryClient = useQueryClient();
const setAlbumListData = useSetAlbumListItemDataById();
const setQueueFavorite = useSetQueueFavorite();
const setFavoriteEvent = useFavoriteEvent();

return useMutation<
FavoriteResponse,
Expand Down Expand Up @@ -47,6 +49,7 @@ export const useDeleteFavorite = (args: MutationHookArgs) => {
if (variables.query.type === LibraryItem.SONG) {
remote?.updateFavorite(false, serverId, variables.query.id);
setQueueFavorite(variables.query.id, false);
setFavoriteEvent(variables.query.id, false);
}

// We only need to set if we're already on the album detail page
Expand Down
19 changes: 16 additions & 3 deletions src/renderer/features/shared/mutations/set-rating-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { MutationHookArgs } from '/@/renderer/lib/react-query';
import { getServerById, useSetAlbumListItemDataById, useSetQueueRating } from '/@/renderer/store';
import isElectron from 'is-electron';
import { useRatingEvent } from '/@/renderer/store/event.store';

const remote = isElectron() ? window.electron.remote : null;

Expand All @@ -23,6 +24,7 @@ export const useSetRating = (args: MutationHookArgs) => {
const queryClient = useQueryClient();
const setAlbumListData = useSetAlbumListItemDataById();
const setQueueRating = useSetQueueRating();
const setRatingEvent = useRatingEvent();

return useMutation<
RatingResponse,
Expand All @@ -43,25 +45,36 @@ export const useSetRating = (args: MutationHookArgs) => {
break;
case LibraryItem.SONG:
setQueueRating([item.id], item.userRating);
setRatingEvent([item.id], item.userRating);
break;
}
}
},
onMutate: (variables) => {
const songIds: string[] = [];
for (const item of variables.query.item) {
switch (item.itemType) {
case LibraryItem.ALBUM:
setAlbumListData(item.id, { userRating: variables.query.rating });
break;
case LibraryItem.SONG:
setQueueRating([item.id], variables.query.rating);
songIds.push(item.id);

break;
}
}

if (songIds.length > 0) {
setQueueRating(songIds, variables.query.rating);
setRatingEvent(songIds, variables.query.rating);
}

if (remote) {
const ids = variables.query.item.map((item) => item.id);
remote.updateRating(variables.query.rating, variables.query.item[0].serverId, ids);
remote.updateRating(
variables.query.rating,
variables.query.item[0].serverId,
songIds,
);
}

return { previous: { items: variables.query.item } };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const SimilarSongsList = ({ count, fullScreen, song }: SimilarSongsListPr
<VirtualGridAutoSizerContainer>
<VirtualTable
ref={tableRef}
shouldUpdateSong
autoFitColumns={tableConfig.autoFit}
columnDefs={columnDefs}
context={{
Expand All @@ -69,7 +70,7 @@ export const SimilarSongsList = ({ count, fullScreen, song }: SimilarSongsListPr
song,
}}
deselectOnClickOutside={fullScreen}
getRowId={(data) => data.data.uniqueId}
getRowId={(data) => data.data.id}
rowBuffer={50}
rowData={songQuery.data ?? []}
rowHeight={tableConfig.rowHeight || 40}
Expand Down
Loading
Loading