From 21e92aef516ca6ec3e267f4adfe8c452776a44ee Mon Sep 17 00:00:00 2001 From: kouloumos Date: Tue, 23 Apr 2024 16:17:24 +0300 Subject: [PATCH] refactor: state of transcript claim `claimState` is currently passed through 5 nested components in order to calculate the loading state. That code wasn't working and after I fixed it with my previous commits, the logic is now redundant. This commit removes the redundant logic and simplifies the related state parameter. --- src/components/tables/BaseTable.tsx | 8 -------- src/components/tables/QueueTable.tsx | 17 +++++++---------- src/components/tables/TableItems.tsx | 5 ----- src/components/tables/types.ts | 3 --- 4 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/components/tables/BaseTable.tsx b/src/components/tables/BaseTable.tsx index 11659aac..5c8953ac 100644 --- a/src/components/tables/BaseTable.tsx +++ b/src/components/tables/BaseTable.tsx @@ -23,9 +23,6 @@ type Props = { refetch?: ( options?: (RefetchOptions & RefetchQueryFilters) | undefined ) => Promise>; - actionState?: { - rowId: number; - }; tableStructure: TableStructure[]; tableHeader?: string; tableHeaderComponent?: React.ReactNode; @@ -40,7 +37,6 @@ const BaseTable = ({ emptyView, isLoading, refetch, - actionState, tableStructure, tableHeader, tableHeaderComponent, @@ -90,7 +86,6 @@ const BaseTable = ({ }-data-row-${idx}`} row={dataRow} ts={tableStructure} - actionState={actionState} /> )) ) : ( @@ -105,12 +100,10 @@ const BaseTable = ({ const TableRow = ({ row, ts, - actionState, showControls, }: { row: T; ts: TableStructure[]; - actionState: Props["actionState"]; showControls: boolean; }) => { return ( @@ -121,7 +114,6 @@ const TableRow = ({ key={tableItem.name} tableItem={tableItem} row={row} - actionState={actionState} /> ))} diff --git a/src/components/tables/QueueTable.tsx b/src/components/tables/QueueTable.tsx index 05c81be9..7f7dd0aa 100644 --- a/src/components/tables/QueueTable.tsx +++ b/src/components/tables/QueueTable.tsx @@ -110,9 +110,7 @@ const QueueTable = () => { const retriedClaim = useRef(0); - const [claimState, setClaimState] = useState({ - rowId: -1, - }); + const [selectedTranscriptId, setSelectedTranscriptId] = useState(-1); const { data: multipleStatusData } = useUserMultipleReviews({ userId: session?.user?.id, multipleStatus: ["pending", "active", "inactive"], @@ -156,7 +154,7 @@ const QueueTable = () => { return; } if (session?.user?.id) { - setClaimState((prev) => ({ ...prev, rowId: transcriptId })); + setSelectedTranscriptId(transcriptId); // Fork repo const forkResult = await axios.post("/api/github/fork"); @@ -200,7 +198,7 @@ const QueueTable = () => { throw new Error("failed to claim transcript"); } - setClaimState((prev) => ({ ...prev, rowId: -1 })); + setSelectedTranscriptId(-1); if (data instanceof Error) { await retryLoginAndClaim(transcriptId); return; @@ -217,7 +215,7 @@ const QueueTable = () => { onError: (err) => { const error = err as Error; - setClaimState((prev) => ({ ...prev, rowId: -1 })); + setSelectedTranscriptId(-1); toast({ status: "error", title: error?.message, @@ -347,8 +345,8 @@ const QueueTable = () => { modifier: (data) => data.id, component: (data) => (