Fix table ref for queue controls

This commit is contained in:
jeffvli
2022-12-10 14:56:46 -08:00
parent c0d5c88cf2
commit bcc32deda1
3 changed files with 10 additions and 12 deletions
@@ -15,8 +15,7 @@ export const DrawerPlayQueue = () => {
>
<PlayQueue type="sideQueue" />
<PlayQueueListControls
gridApi={queueRef.current?.grid.api}
gridColumnApi={queueRef.current?.grid?.columnApi}
tableRef={queueRef}
type="sideQueue"
/>
</Stack>
@@ -1,3 +1,4 @@
import type { MutableRefObject } from 'react';
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
import { Group } from '@mantine/core';
import {
@@ -15,17 +16,16 @@ import type { TableType } from '/@/types';
import { mpvPlayer } from '#preload';
interface PlayQueueListOptionsProps {
gridApi?: AgGridReactType<Song>['api'];
gridColumnApi?: AgGridReactType<Song>['columnApi'];
tableRef: MutableRefObject<{ grid: AgGridReactType<Song> } | null>;
type: TableType;
}
export const PlayQueueListControls = ({ type, gridApi }: PlayQueueListOptionsProps) => {
export const PlayQueueListControls = ({ type, tableRef }: PlayQueueListOptionsProps) => {
const { clearQueue, moveToBottomOfQueue, moveToTopOfQueue, shuffleQueue, removeFromQueue } =
useQueueControls();
const handleMoveToBottom = () => {
const selectedRows = gridApi?.getSelectedRows();
const selectedRows = tableRef?.current?.grid.api.getSelectedRows();
const uniqueIds = selectedRows?.map((row) => row.uniqueId);
if (!uniqueIds?.length) return;
@@ -34,7 +34,7 @@ export const PlayQueueListControls = ({ type, gridApi }: PlayQueueListOptionsPro
};
const handleMoveToTop = () => {
const selectedRows = gridApi?.getSelectedRows();
const selectedRows = tableRef?.current?.grid.api.getSelectedRows();
const uniqueIds = selectedRows?.map((row) => row.uniqueId);
if (!uniqueIds?.length) return;
@@ -43,7 +43,7 @@ export const PlayQueueListControls = ({ type, gridApi }: PlayQueueListOptionsPro
};
const handleRemoveSelected = () => {
const selectedRows = gridApi?.getSelectedRows();
const selectedRows = tableRef?.current?.grid.api.getSelectedRows();
const uniqueIds = selectedRows?.map((row) => row.uniqueId);
if (!uniqueIds?.length) return;
@@ -6,7 +6,7 @@ import { PlayQueueListControls } from './play-queue-list-controls';
import type { Song } from '/@/api/types';
export const SidebarPlayQueue = () => {
const queueRef = useRef<{ grid: AgGridReactType<Song> } | null>(null);
const tableRef = useRef<{ grid: AgGridReactType<Song> } | null>(null);
return (
<Stack
@@ -15,12 +15,11 @@ export const SidebarPlayQueue = () => {
sx={{ height: '100%' }}
>
<PlayQueue
ref={queueRef}
ref={tableRef}
type="sideQueue"
/>
<PlayQueueListControls
gridApi={queueRef.current?.grid.api}
gridColumnApi={queueRef.current?.grid.columnApi}
tableRef={tableRef}
type="sideQueue"
/>
</Stack>