Skip to content

Commit

Permalink
Shorten some code.
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoknjas committed Nov 26, 2024
1 parent e8881c4 commit d2f48bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
19 changes: 7 additions & 12 deletions ui/analyse/src/study/chapterNewForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,25 +320,20 @@ export function view(ctrl: StudyChapterNewForm): VNode {
attrs: { disabled: gameOrPgn },
hook: {
insert: vnode => {
// Reselect the default value programmatically:
const selectEl = vnode.elm as HTMLSelectElement;
selectEl.value = gameOrPgn ? 'standard' : currentChapter.setup.variant.key;
const waitForEditor = () => {
if (ctrl.editor) {
selectEl.dispatchEvent(new Event('change'));
} else {
setTimeout(waitForEditor, 1);
}
};
waitForEditor();
const triggerChange = () =>
ctrl.editor
? selectEl.dispatchEvent(new Event('change'))
: setTimeout(triggerChange, 1);
triggerChange();
},
},
on: {
change: e => {
change: e =>
ctrl.editor?.setRules(
lichessRules((e.target as HTMLSelectElement).value as VariantKey),
);
},
),
},
},
gameOrPgn
Expand Down
8 changes: 2 additions & 6 deletions ui/editor/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Rules } from 'chessops/types';

export type CastlingToggle = 'K' | 'Q' | 'k' | 'q';

export const CASTLING_TOGGLES: CastlingToggle[] = ['K', 'Q', 'k', 'q'];

export type CastlingToggles<T> = {
[side in CastlingToggle]: T;
};
export type Redraw = () => void;
export type Selected = 'pointer' | 'trash' | [Color, Role];

export interface EditorState {
fen: string;
Expand All @@ -15,10 +15,6 @@ export interface EditorState {
enPassantOptions: string[];
}

export type Redraw = () => void;

export type Selected = 'pointer' | 'trash' | [Color, Role];

export interface LichessEditor {
getFen(): FEN;
setOrientation(o: Color): void;
Expand Down

0 comments on commit d2f48bd

Please sign in to comment.