Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion next-frontend/src/app/(wca)/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Link from "next/link";

import { iconMap } from "@/components/icons/iconMap";
import { route } from "nextjs-routes";
import AttemptResultField from "./AttemptResultField";
import AttemptResultField from "../../../components/live/AttemptResultField";
import {
ColorSemanticTokenDoc,
ColorTokenDoc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ function stringToInt(numeric: string) {
}

function inputToAttemptResult(input: string) {
if (input === "") return SKIPPED_VALUE;
if (input === "DNF") return DNF_VALUE;
if (input === "DNS") return DNS_VALUE;
const specialValue = REVERSE_SPECIAL_VALUES[input];

if (specialValue) return specialValue;

const num = stringToInt(input);

Expand All @@ -54,28 +54,27 @@ function inputToAttemptResult(input: string) {
);
}

function attemptResultToInput(number: number) {
if (number === SKIPPED_VALUE) return "";
if (number === DNF_VALUE) return "DNF";
if (number === DNS_VALUE) return "DNS";
const SPECIAL_VALUES: Partial<Record<number, string>> = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it Partial? You could declare type SpecialValue = SKIPPED_VALUE | DNF_VALUE | DNS_VALUE or something, and roll with that.

But anyways, isn't Record inherently partial? If I declare a Record<string, something>, then I don't have to map every single string in existence...

[SKIPPED_VALUE]: "",
[DNF_VALUE]: "DNF",
[DNS_VALUE]: "DNS",
};

const REVERSE_SPECIAL_VALUES: Partial<Record<string, number>> =
Object.fromEntries(
Object.entries(SPECIAL_VALUES).map(([k, v]) => [v, Number(k)]),
) as Partial<Record<string, number>>;
Comment on lines +64 to +66
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a Lodash helper for this?


return centisecondsToClockFormat(number);
function attemptResultToInput(number: number) {
return SPECIAL_VALUES[number] ?? centisecondsToClockFormat(number);
}

function inputToNumber(input: string): number {
if (input === "") return SKIPPED_VALUE;
if (input === "DNF") return DNF_VALUE;
if (input === "DNS") return DNS_VALUE;

return stringToInt(input);
return REVERSE_SPECIAL_VALUES[input] ?? stringToInt(input);
}

function numberToInput(number: number) {
if (number === SKIPPED_VALUE) return "";
if (number === DNF_VALUE) return "DNF";
if (number === DNS_VALUE) return "DNS";

return number.toString();
return SPECIAL_VALUES[number] ?? number.toString();
}

function reformatTimeInput(input: string) {
Expand Down Expand Up @@ -158,9 +157,7 @@ export function FmMovesField({

return (
<Field.Root invalid={!isValid}>
<Field.Label>PointsField (isAverage: {isAverage.toString()})</Field.Label>
<Input placeholder={placeholder} spellCheck={false} {...binding} />
<Field.HelperText>{value}</Field.HelperText>
</Field.Root>
);
}
Expand Down
2 changes: 1 addition & 1 deletion next-frontend/src/components/live/AttemptsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
useListCollection,
VStack,
} from "@chakra-ui/react";
import AttemptResultField from "@/app/(wca)/dashboard/AttemptResultField";
import AttemptResultField from "@/components/live/AttemptResultField";
import _ from "lodash";
import { useResultsAdmin } from "@/providers/LiveResultAdminProvider";
import { useLiveResults } from "@/providers/LiveResultProvider";
Expand Down