Skip to content

Commit

Permalink
typed CourtAppealRound
Browse files Browse the repository at this point in the history
  • Loading branch information
yornaath committed Dec 12, 2023
1 parent 5a83bed commit f86f762
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
15 changes: 7 additions & 8 deletions components/court/CourtStageTimer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CourtStage, getCourtStage } from "lib/state/court/get-stage";
import moment from "moment";
import { useMemo } from "react";
import InfoPopover from "components/ui/InfoPopover";
import { CourtAppealRound } from "lib/state/court/types";

export const CourtStageTimer = ({
market: initialMarket,
Expand Down Expand Up @@ -49,7 +50,9 @@ export const CourtStageTimer = ({
? 100
: ((stage.totalTime - stage.remainingBlocks) / stage.totalTime) * 100;

const round = courtCase?.appeals.length;
const round = courtCase
? (courtCase.appeals.length as CourtAppealRound)
: undefined;

return (
<>
Expand All @@ -69,14 +72,10 @@ export const CourtStageTimer = ({
)}
{round && (
<div
className={`flex items-center gap-1 rounded-full px-2 py-1 text-xs ${
roundCopy[round as 1 | 2 | 3].className
}`}
className={`flex items-center gap-1 rounded-full px-2 py-1 text-xs ${roundCopy[round].className}`}
>
Round {round}{" "}
<InfoPopover>
{roundCopy[round as 1 | 2 | 3].description}
</InfoPopover>
<InfoPopover>{roundCopy[round].description}</InfoPopover>
</div>
)}
</div>
Expand All @@ -100,7 +99,7 @@ export const CourtStageTimer = ({
};

export const roundCopy: Record<
1 | 2 | 3,
CourtAppealRound,
{ description: string; className: string }
> = {
"1": {
Expand Down
8 changes: 6 additions & 2 deletions lib/state/court/CourtCaseJurorCompositeId.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCourtCase } from "lib/hooks/queries/court/useCourtCase";
import Opaque, { create } from "ts-opaque";
import { CourtAppealRound } from "./types";

export type CourtCaseJurorCompositeId = Opaque<
string,
Expand All @@ -18,8 +19,11 @@ export const courtCaseJurorCompositeId = (params: {
}) => {
const { data: courtCase } = useCourtCase(params.caseId);

const round = courtCase?.appeals.length;
const roundIdentifier = round ? `-round[${round}]` : "";
const round = courtCase
? (courtCase.appeals.length as CourtAppealRound)
: undefined;

const roundIdentifier = round ? `-appeal-round[${round}]` : "";

return create<CourtCaseJurorCompositeId>(
`${params.marketId}-${params.caseId}${roundIdentifier}-${params.juror}`,
Expand Down
1 change: 1 addition & 0 deletions lib/state/court/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type CourtAppealRound = 1 | 2 | 3;

0 comments on commit f86f762

Please sign in to comment.