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" /> <PlayQueue type="sideQueue" />
<PlayQueueListControls <PlayQueueListControls
gridApi={queueRef.current?.grid.api} tableRef={queueRef}
gridColumnApi={queueRef.current?.grid?.columnApi}
type="sideQueue" type="sideQueue"
/> />
</Stack> </Stack>
@@ -1,3 +1,4 @@
import type { MutableRefObject } from 'react';
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 { Group } from '@mantine/core'; import { Group } from '@mantine/core';
import { import {
@@ -15,17 +16,16 @@ import type { TableType } from '/@/types';
import { mpvPlayer } from '#preload'; import { mpvPlayer } from '#preload';
interface PlayQueueListOptionsProps { interface PlayQueueListOptionsProps {
gridApi?: AgGridReactType<Song>['api']; tableRef: MutableRefObject<{ grid: AgGridReactType<Song> } | null>;
gridColumnApi?: AgGridReactType<Song>['columnApi'];
type: TableType; type: TableType;
} }
export const PlayQueueListControls = ({ type, gridApi }: PlayQueueListOptionsProps) => { export const PlayQueueListControls = ({ type, tableRef }: PlayQueueListOptionsProps) => {
const { clearQueue, moveToBottomOfQueue, moveToTopOfQueue, shuffleQueue, removeFromQueue } = const { clearQueue, moveToBottomOfQueue, moveToTopOfQueue, shuffleQueue, removeFromQueue } =
useQueueControls(); useQueueControls();
const handleMoveToBottom = () => { const handleMoveToBottom = () => {
const selectedRows = gridApi?.getSelectedRows(); const selectedRows = tableRef?.current?.grid.api.getSelectedRows();
const uniqueIds = selectedRows?.map((row) => row.uniqueId); const uniqueIds = selectedRows?.map((row) => row.uniqueId);
if (!uniqueIds?.length) return; if (!uniqueIds?.length) return;
@@ -34,7 +34,7 @@ export const PlayQueueListControls = ({ type, gridApi }: PlayQueueListOptionsPro
}; };
const handleMoveToTop = () => { const handleMoveToTop = () => {
const selectedRows = gridApi?.getSelectedRows(); const selectedRows = tableRef?.current?.grid.api.getSelectedRows();
const uniqueIds = selectedRows?.map((row) => row.uniqueId); const uniqueIds = selectedRows?.map((row) => row.uniqueId);
if (!uniqueIds?.length) return; if (!uniqueIds?.length) return;
@@ -43,7 +43,7 @@ export const PlayQueueListControls = ({ type, gridApi }: PlayQueueListOptionsPro
}; };
const handleRemoveSelected = () => { const handleRemoveSelected = () => {
const selectedRows = gridApi?.getSelectedRows(); const selectedRows = tableRef?.current?.grid.api.getSelectedRows();
const uniqueIds = selectedRows?.map((row) => row.uniqueId); const uniqueIds = selectedRows?.map((row) => row.uniqueId);
if (!uniqueIds?.length) return; if (!uniqueIds?.length) return;
@@ -6,7 +6,7 @@ import { PlayQueueListControls } from './play-queue-list-controls';
import type { Song } from '/@/api/types'; import type { Song } from '/@/api/types';
export const SidebarPlayQueue = () => { export const SidebarPlayQueue = () => {
const queueRef = useRef<{ grid: AgGridReactType<Song> } | null>(null); const tableRef = useRef<{ grid: AgGridReactType<Song> } | null>(null);
return ( return (
<Stack <Stack
@@ -15,12 +15,11 @@ export const SidebarPlayQueue = () => {
sx={{ height: '100%' }} sx={{ height: '100%' }}
> >
<PlayQueue <PlayQueue
ref={queueRef} ref={tableRef}
type="sideQueue" type="sideQueue"
/> />
<PlayQueueListControls <PlayQueueListControls
gridApi={queueRef.current?.grid.api} tableRef={tableRef}
gridColumnApi={queueRef.current?.grid.columnApi}
type="sideQueue" type="sideQueue"
/> />
</Stack> </Stack>