-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
128 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { persistentAtom } from "@nanostores/persistent"; | ||
|
||
export const chosenExams = persistentAtom<Record<string, boolean>>( | ||
"aikido-exam-chosen", | ||
{}, | ||
{ | ||
encode: JSON.stringify, | ||
decode: JSON.parse, | ||
}, | ||
); | ||
|
||
export function chooseExam(name: string, choose: boolean) { | ||
chosenExams.set({ ...chosenExams.get(), [name]: choose }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,8 @@ | ||
import { atom } from "nanostores"; | ||
import { DojoLazyData, Dojo } from "./baseTypes"; | ||
import aifd from "./aikido-foederation"; | ||
import darmstadt from "./aikido-dojo-darmstadt"; | ||
|
||
export const currentDojoLazyData = atom<DojoLazyData>({ exams: {} }); | ||
|
||
export const currentDojo = atom<Pick<Dojo, "name" | "logo">>({ name: "loading dojos" }); | ||
import { Dojo } from "./baseTypes"; | ||
|
||
export const dojos: Record<string, Dojo> = { | ||
"aikido-foederation-deutschland": aifd, | ||
"aikido-dojo-darmstadt": darmstadt, | ||
}; | ||
|
||
export async function initCurrentDojo(): Promise<void> { | ||
const searchParams = new URLSearchParams(window.location.search); | ||
const dojoId = searchParams.get("dojo") ?? "aikido-foederation-deutschland"; | ||
currentDojo.set(dojos[dojoId]); | ||
const dojoRules = await dojos[dojoId].lazyData(); | ||
currentDojoLazyData.set(dojoRules.default); | ||
} | ||
|
||
export async function selectDojo(dojo: string): Promise<void> { | ||
window.history.pushState(null, "", "?dojo=" + encodeURIComponent(dojo)); | ||
await initCurrentDojo(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useStore } from "@nanostores/react"; | ||
import { DojoLazyData } from "../exam-tables/baseTypes"; | ||
import { atom } from "nanostores"; | ||
import { dojos } from "../exam-tables"; | ||
import { useMemo } from "react"; | ||
|
||
type ShortDojo = { | ||
id: string; | ||
name: string; | ||
logo?: string; | ||
}; | ||
|
||
const searchParams = new URLSearchParams(window.location.search); | ||
const currentDojo = atom<string>(searchParams.get("dojo") ?? "aikido-foederation-deutschland"); | ||
const currentDojoLazyData = atom<DojoLazyData>({ exams: {} }); | ||
|
||
export function useSelectedDojo(): { | ||
selectedDojo: ShortDojo; | ||
selectedDojoLazyData: DojoLazyData; | ||
selectDojo: (id: string) => void; | ||
} { | ||
const currentId = useStore(currentDojo); | ||
const lazyData = useStore(currentDojoLazyData); | ||
const selectedDojo = useMemo(() => { | ||
return { | ||
id: currentId, | ||
logo: dojos[currentId].logo, | ||
name: dojos[currentId].name, | ||
}; | ||
}, [currentId]); | ||
return { | ||
selectedDojo, | ||
selectedDojoLazyData: lazyData, | ||
selectDojo: currentDojo.set.bind(currentDojo), | ||
}; | ||
} | ||
|
||
currentDojo.subscribe((value) => | ||
window.history.pushState(null, "", "?dojo=" + encodeURIComponent(value) + document.location.hash), | ||
); | ||
|
||
currentDojo.subscribe(async (value) => { | ||
const dojoRules = await dojos[value].lazyData(); | ||
currentDojoLazyData.set(dojoRules.default); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { persistentAtom } from "@nanostores/persistent"; | ||
import { TechniqueList } from "../model/TechniqueList"; | ||
import { useStore } from "@nanostores/react"; | ||
|
||
const techniqueList = persistentAtom<TechniqueList>("aikido-exam-techniques", new TechniqueList(), { | ||
encode: (techniqueList) => { | ||
return JSON.stringify(techniqueList.toJson()); | ||
}, | ||
decode: (string) => { | ||
return TechniqueList.fromJson(JSON.parse(string)); | ||
}, | ||
}); | ||
|
||
export function useTechniqueList(): [techniques: TechniqueList, setTechniques: (techniques: TechniqueList) => void] { | ||
return [useStore(techniqueList), techniqueList.set.bind(techniqueList)]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters