Skip to content

Commit

Permalink
allow free exam labels
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp committed Aug 17, 2024
1 parent 3f57a2a commit 3d46080
Show file tree
Hide file tree
Showing 25 changed files with 232 additions and 45 deletions.
2 changes: 1 addition & 1 deletion scripts/merge-youtube-data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ for (const exam of Object.values(tables.exams)) {
metadata.youtube = findVideo(technique);
}
}
result[exam.labelKey] = exam;
result[exam.id] = exam;
}

console.log(JSON.stringify(result, 0, 2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,24 @@ describe("Chooser.test.tsx", async () => {
const dojo = createResolvedDojo({
details: createDojoDetails({
exams: [
createExam({ labelKey: "chooser.button.kyu5" }),
createExam({ labelKey: "chooser.button.kyu4" }),
createExam({ labelKey: "chooser.button.kyu3" }),
createExam({
label: {
type: "wellknown",
key: "kyu5",
},
}),
createExam({
label: {
type: "wellknown",
key: "kyu4",
},
}),
createExam({
label: {
type: "wellknown",
key: "kyu3",
},
}),
],
}),
});
Expand All @@ -30,7 +45,14 @@ describe("Chooser.test.tsx", async () => {
it("clicking an exam selects it", async () => {
const dojo = createResolvedDojo({
details: createDojoDetails({
exams: [createExam({ labelKey: "chooser.button.kyu5" })],
exams: [
createExam({
label: {
type: "wellknown",
key: "kyu5",
},
}),
],
}),
});
render(() => <TechniqueChooser dojo={dojo} />);
Expand All @@ -44,7 +66,14 @@ describe("Chooser.test.tsx", async () => {
it("clicking an selected exam deselects it", async () => {
const dojo = createResolvedDojo({
details: createDojoDetails({
exams: [createExam({ labelKey: "chooser.button.kyu5" })],
exams: [
createExam({
label: {
type: "wellknown",
key: "kyu5",
},
}),
],
}),
});
render(() => <TechniqueChooser dojo={dojo} />);
Expand All @@ -60,7 +89,10 @@ describe("Chooser.test.tsx", async () => {
details: createDojoDetails({
exams: [
createExam({
labelKey: "chooser.button.kyu5",
label: {
type: "wellknown",
key: "kyu5",
},
techniques: {
"suwari waza": {
"ai hanmi katate dori": {
Expand All @@ -86,7 +118,10 @@ describe("Chooser.test.tsx", async () => {
details: createDojoDetails({
exams: [
createExam({
labelKey: "chooser.button.kyu5",
label: {
type: "wellknown",
key: "kyu5",
},
techniques: {
"suwari waza": {
"ai hanmi katate dori": {
Expand All @@ -108,7 +143,10 @@ describe("Chooser.test.tsx", async () => {
details: createDojoDetails({
exams: [
createExam({
labelKey: "chooser.button.kyu5",
label: {
type: "wellknown",
key: "kyu5",
},
techniques: {
"hanmi handachi waza": {
"ai hanmi katate dori": {
Expand Down Expand Up @@ -138,7 +176,10 @@ describe("Chooser.test.tsx", async () => {
details: createDojoDetails({
exams: [
createExam({
labelKey: "chooser.button.kyu5",
label: {
type: "wellknown",
key: "kyu5",
},
techniques: {
"hanmi handachi waza": {
"ai hanmi katate dori": {
Expand All @@ -163,8 +204,20 @@ describe("Chooser.test.tsx", async () => {
const dojo = createResolvedDojo({
details: createDojoDetails({
exams: [
createExam({ id: "kyu5", labelKey: "chooser.button.kyu5" }),
createExam({ id: "kyu4", labelKey: "chooser.button.kyu4" }),
createExam({
id: "kyu5",
label: {
type: "wellknown",
key: "kyu5",
},
}),
createExam({
id: "kyu4",
label: {
type: "wellknown",
key: "kyu4",
},
}),
],
}),
});
Expand All @@ -186,8 +239,20 @@ describe("Chooser.test.tsx", async () => {
info: createDojoInfo({ id }),
details: createDojoDetails({
exams: [
createExam({ id: "kyu5", labelKey: "chooser.button.kyu5" }),
createExam({ id: "kyu4", labelKey: "chooser.button.kyu4" }),
createExam({
id: "kyu5",
label: {
type: "wellknown",
key: "kyu5",
},
}),
createExam({
id: "kyu4",
label: {
type: "wellknown",
key: "kyu4",
},
}),
],
}),
});
Expand All @@ -211,7 +276,15 @@ describe("Chooser.test.tsx", async () => {
it("renders filters", () => {
const dojo = createResolvedDojo({
details: createDojoDetails({
exams: [createExam({ id: "kyu5", labelKey: "chooser.button.kyu5" })],
exams: [
createExam({
id: "kyu5",
label: {
type: "wellknown",
key: "kyu5",
},
}),
],
}),
});
renderSolid(() => <TechniqueChooser dojo={dojo} />);
Expand All @@ -225,7 +298,10 @@ describe("Chooser.test.tsx", async () => {
exams: [
createExam({
id: "kyu5",
labelKey: "chooser.button.kyu5",
label: {
type: "wellknown",
key: "kyu5",
},
techniques: {
"suwari waza": { "ai hanmi katate dori": { ikkyo: { omote: {} } } },
"hanmi handachi waza": { "ai hanmi katate dori": { ikkyo: { omote: {} } } },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { type Component, createDeferred, createSignal } from "solid-js";
import type { ResolvedDojo } from "$core/model/Dojo.ts";
import { t } from "@/i18n";
import { t, tx } from "@/i18n";
import { l } from "astro-i18n";
import { ExamSheet } from "@/components/solid/organisms/TechniqueChooser/ExamSheet.tsx";
import {
ChooserControlButtons,
type Option,
} from "@/components/solid/organisms/TechniqueChooser/ChooserControlButtons.tsx";
import type { Exam } from "$core/model";
import type { Exam, ExamLabel, WellKnownExam } from "$core/model";
import { syncToStorage } from "@/components/solid/hooks/syncToStorage.ts";
import { isServer } from "solid-js/web";
import { ChooserControlContainer } from "@/components/solid/organisms/TechniqueChooser/ChooserControlContainer.tsx";
Expand All @@ -21,6 +21,7 @@ import { SimpleButton } from "@/components/solid/atoms/SimpleButton.tsx";
import { IconPrint, IconSpeak } from "@/icons";
import { createTechniqueStore } from "$core/store";
import { LinkButton } from "@/components/solid/atoms/LinkButton.tsx";
import type { TranslationSchema } from "@/i18n/TranslationSchema.ts";

export const TechniqueChooser: Component<{ dojo: ResolvedDojo }> = (props) => {
const [examSelection, setExamSelection] = syncToStorage(createSignal(new Set<string>()), {
Expand Down Expand Up @@ -115,5 +116,26 @@ export const TechniqueChooser: Component<{ dojo: ResolvedDojo }> = (props) => {
};

function examsToOptions(exams: Exam[]): Option[] {
return exams.map((exam) => ({ id: exam.id, label: t(exam.labelKey) }));
return exams.map((exam) => ({ id: exam.id, label: resoveExamLabel(exam.label) }));
}

const wellknownLabels: Record<WellKnownExam, keyof TranslationSchema> = {
kyu5: "chooser.button.kyu5",
kyu4: "chooser.button.kyu4",
kyu3: "chooser.button.kyu3",
kyu2: "chooser.button.kyu2",
kyu1: "chooser.button.kyu1",
dan1: "chooser.button.dan1",
dan2: "chooser.button.dan2",
dan3: "chooser.button.dan3",
dan4: "chooser.button.dan4",
};

function resoveExamLabel(label: ExamLabel): string {
switch (label.type) {
case "wellknown":
return t(wellknownLabels[label.key]);
case "free":
return tx(label.text);
}
}
21 changes: 18 additions & 3 deletions src/core/model/Dojo.test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,24 @@ export function createDojoInfo(partialInfo: Partial<DojoInfo> = {}): DojoInfo {

export function createExams() {
return [
createExam({ labelKey: "chooser.button.kyu5" }),
createExam({ labelKey: "chooser.button.kyu4" }),
createExam({ labelKey: "chooser.button.kyu3" }),
createExam({
label: {
type: "wellknown",
key: "kyu5",
},
}),
createExam({
label: {
type: "wellknown",
key: "kyu4",
},
}),
createExam({
label: {
type: "wellknown",
key: "kyu3",
},
}),
];
}

Expand Down
5 changes: 4 additions & 1 deletion src/core/model/Exam.test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { nanoid } from "nanoid";
export function createExam(exam: Partial<Exam>): Exam {
return {
id: nanoid(),
labelKey: "chooser.button.kyu5",
label: {
type: "wellknown",
key: "kyu5",
},
techniques: {},
...exam,
};
Expand Down
14 changes: 12 additions & 2 deletions src/core/model/Exam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ import type { TechniqueMetadata } from "./TechniqueMetadata";
import type { Defence } from "./Defence";
import type { Attack } from "./Attack";
import type { Execution } from "./Execution";
import type { TranslationSchema } from "./TranslationSchema";
import type { TranslatedText } from "$core/model/Dojo.ts";

export type Directions = Partial<Record<Direction, TechniqueMetadata>>;
export type Defences = Partial<Record<Defence, Directions>>;
export type Attacks = Partial<Record<Attack, Defences>>;
export type Table = Partial<Record<Execution, Attacks>>;
export type WellKnownExam = "kyu5" | "kyu4" | "kyu3" | "kyu2" | "kyu1" | "dan1" | "dan2" | "dan3" | "dan4";
export type ExamLabel =
| {
type: "wellknown";
key: WellKnownExam;
}
| {
type: "free";
text: TranslatedText;
};

export interface Exam {
id: string;
labelKey: keyof TranslationSchema;
label: ExamLabel;
techniques: Table;
}
10 changes: 8 additions & 2 deletions src/core/resolveExamTables/resolveExamTables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ describe("resolve-exam-tables", () => {
const actual = resolveExamTables([
{
id: "dan2",
labelKey: "chooser.button.dan2",
label: {
type: "wellknown",
key: "dan2",
},
techniques: {
"suwari waza": {
"ryote dori": {
Expand All @@ -23,7 +26,10 @@ describe("resolve-exam-tables", () => {
},
{
id: "dan3",
labelKey: "chooser.button.dan3",
label: {
type: "wellknown",
key: "dan3",
},
techniques: {
"tachi waza": {
"ai hanmi katate dori": {
Expand Down
7 changes: 6 additions & 1 deletion src/data/dojos/aikido-dojo-darmstadt/exams/additional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import type { Exam } from "$core/model";

export const additional: Exam = {
id: "additional",
labelKey: "chooser.button.additional",
label: {
type: "free",
text: {
en: "+X",
},
},
techniques: {
"tachi waza": {
"chudan tsuki": {
Expand Down
5 changes: 4 additions & 1 deletion src/data/dojos/aikido-dojo-darmstadt/exams/dan1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import type { Exam } from "$core/model";

export const dan1: Exam = {
id: "dan1",
labelKey: "chooser.button.dan1",
label: {
type: "wellknown",
key: "dan1",
},
techniques: {
"hanmi handachi waza": {
"gyuako hanmi katate dori": {
Expand Down
5 changes: 4 additions & 1 deletion src/data/dojos/aikido-dojo-darmstadt/exams/kyu1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import type { Exam } from "$core/model";

export const kyu1: Exam = {
id: "kyu1",
labelKey: "chooser.button.kyu1",
label: {
type: "wellknown",
key: "kyu1",
},
techniques: {
"suwari waza": {
"yokomen uchi": {
Expand Down
5 changes: 4 additions & 1 deletion src/data/dojos/aikido-dojo-darmstadt/exams/kyu2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import type { Exam } from "$core/model/Exam";

export const kyu2: Exam = {
id: "kyu2",
labelKey: "chooser.button.kyu2",
label: {
type: "wellknown",
key: "kyu2",
},
techniques: {
"suwari waza": {
"yokomen uchi": {
Expand Down
5 changes: 4 additions & 1 deletion src/data/dojos/aikido-dojo-darmstadt/exams/kyu3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import type { Exam } from "$core/model/Exam";

export const kyu3: Exam = {
id: "kyu3",
labelKey: "chooser.button.kyu3",
label: {
type: "wellknown",
key: "kyu3",
},
techniques: {
"suwari waza": {
"gyuako hanmi katate dori": {
Expand Down
Loading

0 comments on commit 3d46080

Please sign in to comment.