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
8 changes: 2 additions & 6 deletions frontend/src/ts/collections/results.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ResultMinified } from "@monkeytype/schemas/results";
import { Difficulty, Mode, Mode2 } from "@monkeytype/schemas/shared";
import { ResultFilters } from "@monkeytype/schemas/users";
import { quoteDescToGroup } from "@monkeytype/schemas/quotes";
import { queryCollectionOptions } from "@tanstack/query-db-collection";
import {
avg,
Expand Down Expand Up @@ -497,12 +498,7 @@ export function createResultsQueryState(
numbers: boolFilter(filters.numbers),
timestamp: timestampFilter(filters.date),
quoteLength: [
...valueFilter(filters.quoteLength, {
short: 0,
medium: 1,
long: 2,
thicc: 3,
}),
...valueFilter(filters.quoteLength, quoteDescToGroup),
-1, // fallback value for results without quoteLength, set in the collection
],
tags: valueFilter(filters.tags),
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/ts/components/modals/MobileTestConfigModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
} from "@monkeytype/schemas/configs";
import type { Mode } from "@monkeytype/schemas/shared";

import { quoteGroupToDesc } from "@monkeytype/schemas/quotes";
import { For, JSXElement, Show } from "solid-js";

import { setConfig, setQuoteLengthAll } from "../../config/setters";
Expand All @@ -26,13 +27,13 @@ const quoteLengths: {
loginRequired?: boolean;
}[] = [
{ value: "all", label: "all" },
{ value: "0", label: "short" },
{ value: "1", label: "medium" },
{ value: "2", label: "long" },
{ value: "3", label: "thicc" },
...Object.entries(quoteGroupToDesc).map(([group, desc]) => ({
value: group,
label: desc,
})),
{ value: "-3", label: "favorite", loginRequired: true },
{ value: "-2", label: "search" },
] as const;
];

function MCButton(props: {
text: string;
Expand Down
12 changes: 1 addition & 11 deletions frontend/src/ts/components/modals/QuoteRateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ export function QuoteRateModal(): JSXElement {
const [rating, setRating] = createSignal(0);
const [hoverRating, setHoverRating] = createSignal(0);

const getLengthDesc = (): string => {
const quote = selectedQuote();
if (!quote) return "-";
if (quote.group === 0) return "short";
if (quote.group === 1) return "medium";
if (quote.group === 2) return "long";
if (quote.group === 3) return "thicc";
return "-";
};

const displayRating = (): number => hoverRating() || rating();

const handleBeforeShow = (): void => {
Expand Down Expand Up @@ -152,7 +142,7 @@ export function QuoteRateModal(): JSXElement {
</div>
<div class="text-xs text-sub">
<div class="text-sub opacity-50">length</div>
{getLengthDesc()}
{selectedQuote()?.groupDescription ?? "-"}
</div>
<div class="text-xs text-sub">
<div class="text-sub opacity-50">source</div>
Expand Down
9 changes: 1 addition & 8 deletions frontend/src/ts/components/modals/QuoteSearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ function exactSearch(quotes: Quote[], captured: RegExp[]): [Quote[], string[]] {
return [matches, Array.from(exactSearchQueryTerms)];
}

function getLengthDesc(quote: Quote): string {
if (quote.length < 101) return "short";
if (quote.length < 301) return "medium";
if (quote.length < 601) return "long";
return "thicc";
}

function Item(props: {
quote: Quote;
matchedTerms: string[];
Expand Down Expand Up @@ -146,7 +139,7 @@ function Item(props: {
</div>
<div class="text-xs text-sub">
<div class="opacity-50">length</div>
{getLengthDesc(props.quote)}
{props.quote.groupDescription}
</div>
<div class="col-span-2 flex sm:col-span-1">
<div class="grow text-xs text-sub">
Expand Down
20 changes: 8 additions & 12 deletions frontend/src/ts/components/pages/test/TestConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { quoteDescToGroup, QuoteLength } from "@monkeytype/schemas/quotes";
import { ComponentProps, For, JSXElement, Show } from "solid-js";

import { configMetadata } from "../../../config/metadata";
Expand Down Expand Up @@ -303,13 +304,6 @@ function Mode2Words(props: ComponentProps<"div">): JSXElement {
}

function Mode2Quote(props: ComponentProps<"div">): JSXElement {
const quoteLengths = [
{ text: "short", length: 0 },
{ text: "medium", length: 1 },
{ text: "long", length: 2 },
{ text: "thicc", length: 3 },
] as const;

return (
<div {...props}>
<TCButton
Expand All @@ -320,13 +314,15 @@ function Mode2Quote(props: ComponentProps<"div">): JSXElement {
restartTestEvent.dispatch();
}}
/>
<For each={quoteLengths}>
{({ text, length }) => (
<For each={Object.keys(quoteDescToGroup)}>
{(desc) => (
<TCButton
text={text}
active={areUnsortedArraysEqual(getConfig.quoteLength, [length])}
text={desc}
active={areUnsortedArraysEqual(getConfig.quoteLength, [
quoteDescToGroup[desc as QuoteLength],
])}
onClick={() => {
setConfig("quoteLength", [length]);
setConfig("quoteLength", [quoteDescToGroup[desc as QuoteLength]]);
restartTestEvent.dispatch();
}}
/>
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/ts/controllers/quotes-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import * as DB from "../db";
import Ape from "../ape";
import { tryCatch } from "@monkeytype/util/trycatch";
import { Language } from "@monkeytype/schemas/languages";
import { QuoteData } from "@monkeytype/schemas/quotes";
import {
QuoteData,
QuoteLength,
quoteGroupToDesc,
} from "@monkeytype/schemas/quotes";
import {
Quote as QuoteType,
QuoteWithTextSplit as QuoteWithTextSplitType,
Expand All @@ -28,6 +32,10 @@ const defaultQuoteCollection: QuoteCollection = {
groups: [],
};

function getLengthDesc(quote: Quote): QuoteLength | "-" {
return quoteGroupToDesc[quote.group] ?? "-";
}

class QuotesController {
private quoteCollection: QuoteCollection = defaultQuoteCollection;

Expand Down Expand Up @@ -77,6 +85,7 @@ class QuotesController {
id: quote.id,
language: data.language,
group: 0,
groupDescription: "-",
};

this.quoteCollection.quotes.push(monkeyTypeQuote);
Expand All @@ -90,6 +99,7 @@ class QuotesController {
this.quoteCollection.quotes.filter((quote) => {
if (quote.length >= lower && quote.length <= upper) {
quote.group = groupIndex;
quote.groupDescription = getLengthDesc(quote);
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/test/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ function updateTestType(randomQuote: Quote | null): void {
testType += ` ${Config.words}`;
} else if (Config.mode === "quote") {
if (randomQuote?.group !== undefined) {
testType += ` ${["short", "medium", "long", "thicc"][randomQuote.group]}`;
testType += ` ${randomQuote.groupDescription}`;
}
}
const ignoresLanguage = isFunboxActiveWithProperty("ignoresLanguage");
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/ts/types/quotes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Language } from "@monkeytype/schemas/languages";
import { QuoteDataQuote } from "@monkeytype/schemas/quotes";
import { QuoteDataQuote, QuoteLength } from "@monkeytype/schemas/quotes";
import { RequiredProperties } from "../utils/misc";

export type Quote = QuoteDataQuote & {
group: number;
groupDescription: QuoteLength | "-";
language: Language;
textSplit?: string[];
};
Expand Down
17 changes: 17 additions & 0 deletions packages/schemas/src/quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ export const QuoteIdSchema = z
.or(z.string().regex(/^\d+$/).transform(Number));
export type QuoteId = z.infer<typeof QuoteIdSchema>;

export const quoteDescToGroup = {
short: 0,
medium: 1,
long: 2,
thicc: 3,
} as const;

export const QuoteLengthSchema = z.enum(
Object.keys(quoteDescToGroup) as [keyof typeof quoteDescToGroup],
);

export type QuoteLength = z.infer<typeof QuoteLengthSchema>;

export const quoteGroupToDesc = Object.fromEntries(
Object.entries(quoteDescToGroup).map(([desc, group]) => [group, desc]),
) as unknown as Record<number, QuoteLength>;

export const ApproveQuoteSchema = z.object({
id: QuoteIdSchema,
text: z.string(),
Expand Down
7 changes: 0 additions & 7 deletions packages/schemas/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ export const DefaultTimeModeSchema = z.union([
z.literal("120"),
]);

export const QuoteLengthSchema = z.union([
z.literal("short"),
z.literal("medium"),
z.literal("long"),
z.literal("thicc"),
]);

// // Step 1: Define the schema for specific string values "10" and "25"
// const SpecificKeySchema = z.union([z.literal("10"), z.literal("25")]);

Expand Down
2 changes: 1 addition & 1 deletion packages/schemas/src/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
PersonalBestsSchema,
DefaultWordsModeSchema,
DefaultTimeModeSchema,
QuoteLengthSchema,
DifficultySchema,
PersonalBestSchema,
} from "./shared";
import { QuoteLengthSchema } from "./quotes";
import { CustomThemeColorsSchema, FunboxNameSchema } from "./configs";
import { doesNotContainDisallowedWords } from "./validation/validation";
import { ConnectionSchema } from "./connections";
Expand Down
Loading