From 9b61272de563a769f9a59cbceba9685b5f617b64 Mon Sep 17 00:00:00 2001 From: Andrew Casal Date: Fri, 6 Sep 2024 23:05:02 -0400 Subject: [PATCH 1/5] Add shift capability to annul queue --- .../PaginatedTable/PaginatedTable.tsx | 50 ++++++------------- src/views/User/GameHistoryTable.tsx | 25 +++++++--- 2 files changed, 34 insertions(+), 41 deletions(-) diff --git a/src/components/PaginatedTable/PaginatedTable.tsx b/src/components/PaginatedTable/PaginatedTable.tsx index e56a531661..e9ac2a2d8d 100644 --- a/src/components/PaginatedTable/PaginatedTable.tsx +++ b/src/components/PaginatedTable/PaginatedTable.tsx @@ -55,6 +55,7 @@ interface PaginatedTableProperties { onRowClick?: ( row: GroomedEntryT, ev: React.MouseEvent | React.TouchEvent | React.PointerEvent, + rows: GroomedEntryT[], ) => any; debug?: boolean; pageSizeOptions?: Array; @@ -63,7 +64,7 @@ interface PaginatedTableProperties { hidePageControls?: boolean; /** If provided, the table will listen for this push event and refresh its data accordingly */ uiPushProps?: { event: string; channel: string }; - annulQueue?: any[]; + highlightedRows?: any[]; } export interface PaginatedTableRef { @@ -355,40 +356,19 @@ function _PaginatedTable( {column_render(column, row)} )); - if (props.annulQueue) { - if (props.onRowClick) { - return ( - - props.onRowClick && props.onRowClick(row, ev) - } - > - {cols} - - ); - } else { - return {cols}; - } - } else { - if (props.onRowClick) { - return ( - - props.onRowClick && props.onRowClick(row, ev) - } - > - {cols} - - ); - } else { - return {cols}; - } - } + return ( + + props.onRowClick && props.onRowClick(row, ev, rows) + } + > + {cols} + + ); })} {blank_rows} diff --git a/src/views/User/GameHistoryTable.tsx b/src/views/User/GameHistoryTable.tsx index 7c6f9fa2d3..47c0780fb4 100644 --- a/src/views/User/GameHistoryTable.tsx +++ b/src/views/User/GameHistoryTable.tsx @@ -34,7 +34,6 @@ import { TimeControl } from "src/components/TimeControl"; import { Speed } from "src/lib/types"; import { usePreference } from "preferences"; import { openAnnulQueueModal, AnnulQueueModal } from "AnnulQueueModal"; -import { useUser } from "hooks"; import { GameNameForList } from "GobanLineSummary"; interface GameHistoryProps { @@ -85,8 +84,6 @@ export function GameHistoryTable(props: GameHistoryProps) { const [annulQueue, setAnnulQueue] = React.useState([]); const [isAnnulQueueModalOpen, setIsAnnulQueueModalOpen] = React.useState(false); - const user = useUser(); - function getBoardSize(size_filter: string): number | undefined { switch (size_filter) { case "9x9": @@ -102,9 +99,25 @@ export function GameHistoryTable(props: GameHistoryProps) { function handleRowClick( row: GroomedGame, ev: React.MouseEvent | React.TouchEvent | React.PointerEvent, + rows: GroomedGame[], ) { if (selectModeActive) { - toggleQueued(row); + if (ev.shiftKey) { + if (annulQueue.at(-1)) { + window.getSelection()?.removeAllRanges(); + const indexes = [ + rows.findIndex(r => r.id === annulQueue.at(-1).id), + rows.findIndex(r => r.id === row.id), + ] + const minIndex = Math.min(...indexes); + const maxIndex = Math.max(...indexes); + setAnnulQueue( + rows.slice(minIndex, maxIndex +1).filter(r => !r.annulled) + ); + } + } else { + toggleQueued(row); + } } else { openUrlIfALinkWasNotClicked(ev, row.href); } @@ -233,7 +246,7 @@ export function GameHistoryTable(props: GameHistoryProps) { />
- {user.is_moderator ? ( + {true ? (
{annulQueue.length > 0 ? (
- {true ? ( + {user.is_moderator ? (
{annulQueue.length > 0 ? (