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 5 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
@@ -1,5 +1,5 @@
import { MutableRefObject, useMemo, useRef } from 'react';
import { ColDef, RowDoubleClickedEvent } from '@ag-grid-community/core';
import { MutableRefObject, useCallback, useMemo, useRef } from 'react';
import { ColDef, GetRowIdParams, RowDoubleClickedEvent } from '@ag-grid-community/core';
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
import { Box, Group } from '@mantine/core';
import { closeAllModals, openModal } from '@mantine/modals';
Expand All @@ -9,7 +9,7 @@ import { generatePath, useNavigate, useParams } from 'react-router';
import { Link } from 'react-router-dom';
import styled from 'styled-components';
import { useListStoreByKey } from '../../../store/list.store';
import { LibraryItem, QueueSong } from '/@/renderer/api/types';
import { LibraryItem, QueueSong, ServerType } from '/@/renderer/api/types';
import { Button, ConfirmModal, DropdownMenu, MotionGroup, toast } from '/@/renderer/components';
import { getColumnDefs, VirtualTable } from '/@/renderer/components/virtual-table';
import { useCurrentSongRowStyles } from '/@/renderer/components/virtual-table/hooks/use-current-song-row-styles';
Expand All @@ -28,6 +28,7 @@ import { AppRoute } from '/@/renderer/router/routes';
import { useCurrentServer } from '/@/renderer/store';
import { usePlayButtonBehavior } from '/@/renderer/store/settings.store';
import { Play } from '/@/renderer/types';
import { useScanUpdate } from '/@/renderer/features/playlists/hooks/use-scan-update';

const ContentContainer = styled.div`
position: relative;
Expand Down Expand Up @@ -156,6 +157,18 @@ export const PlaylistDetailContent = ({ tableRef }: PlaylistDetailContentProps)

const loadMoreRef = useRef<HTMLButtonElement | null>(null);

// Duplicates are only present if on Navidrome
const getId = useCallback(
(data: GetRowIdParams<any>): string => {
return server?.type === ServerType.JELLYFIN
? data.data.id
: `${data.data.id}-${data.data.pageIndex}`;
},
[server?.type],
);

jeffvli marked this conversation as resolved.
Show resolved Hide resolved
useScanUpdate(server, tableRef);

return (
<ContentContainer>
<Group
Expand Down Expand Up @@ -221,14 +234,12 @@ export const PlaylistDetailContent = ({ tableRef }: PlaylistDetailContentProps)
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={getId}
rowClassRules={rowClassRules}
rowData={playlistSongData}
rowHeight={60}
rowSelection="multiple"
shouldUpdateSong={server?.type === ServerType.JELLYFIN}
onCellContextMenu={handleContextMenu}
jeffvli marked this conversation as resolved.
Show resolved Hide resolved
onRowDoubleClicked={handleRowDoubleClick}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {
BodyScrollEvent,
ColDef,
GetRowIdParams,
GridReadyEvent,
IDatasource,
PaginationChangedEvent,
Expand All @@ -19,6 +20,7 @@ import {
LibraryItem,
PlaylistSongListQuery,
QueueSong,
ServerType,
Song,
SongListSort,
SortOrder,
Expand Down Expand Up @@ -47,6 +49,7 @@ import { usePlayButtonBehavior } from '/@/renderer/store/settings.store';
import { ListDisplayType } from '/@/renderer/types';
import { useAppFocus } from '/@/renderer/hooks';
import { toast } from '/@/renderer/components';
import { useScanUpdate } from '/@/renderer/features/playlists/hooks/use-scan-update';

interface PlaylistDetailContentProps {
tableRef: MutableRefObject<AgGridReactType | null>;
Expand Down Expand Up @@ -270,6 +273,16 @@ export const PlaylistDetailSongListContent = ({ tableRef }: PlaylistDetailConten

const { rowClassRules } = useCurrentSongRowStyles({ tableRef });

// Duplicates are only present if on Navidrome
const getId = useCallback(
(data: GetRowIdParams<Song>): string => {
return server?.type === ServerType.JELLYFIN ? data.data.id : data.data.uniqueId;
},
[server?.type],
);

useScanUpdate(server, tableRef);

return (
<>
<VirtualGridAutoSizerContainer>
Expand All @@ -287,7 +300,7 @@ export const PlaylistDetailSongListContent = ({ tableRef }: PlaylistDetailConten
onCellContextMenu: handleContextMenu,
status,
}}
getRowId={(data) => data.data.uniqueId}
getRowId={getId}
infiniteInitialRowCount={checkPlaylistList.data?.totalRecordCount || 100}
pagination={isPaginationEnabled}
paginationAutoPageSize={isPaginationEnabled}
Expand All @@ -298,6 +311,7 @@ export const PlaylistDetailSongListContent = ({ tableRef }: PlaylistDetailConten
}
rowHeight={page.table.rowHeight || 40}
rowModelType="infinite"
shouldUpdateSong={server?.type === ServerType.JELLYFIN}
onBodyScrollEnd={handleScroll}
onCellContextMenu={handleContextMenu}
onColumnMoved={handleColumnChange}
Expand Down
Loading
Loading