Skip to content

Commit

Permalink
Get rid of TODO_OVERRIDE_LEGAL_KEYS and instead rely directly on the …
Browse files Browse the repository at this point in the history
…formal zod type checker.

Part of #670.
  • Loading branch information
jkomoros committed Nov 13, 2023
1 parent b17e5b1 commit 749eee4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
7 changes: 0 additions & 7 deletions src/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1680,13 +1680,6 @@ export const TODO_ALL_INFOS = Object.fromEntries(Object.entries(CARD_FILTER_CONF
//TODO_INFOS are appropriate to pass into tag-list.tagInfos as options to enable or disable.
export const TODO_AUTO_INFOS = Object.fromEntries(Object.entries(TODO_ALL_INFOS).filter(entry => CARD_FILTER_CONFIGS[entry[0]][2].autoApply));

//TODO_CONFIG_KEYS is all of the keys into CARD_FILTER_CONFIG that represent the
//set of items that count as a TODO.
const TODO_CONFIG_KEYS = Object.fromEntries(Object.entries(CARD_FILTER_CONFIGS).filter(entry => entry[1][2].isTODO).map(entry => [entry[0], true]));

//TODO_OVERRIDE_LEGAL_KEYS reflects the only keys that are legal to set in card.auto_todo_overrides
export const TODO_OVERRIDE_LEGAL_KEYS = Object.fromEntries(Object.entries(TODO_CONFIG_KEYS).filter(entry => CARD_FILTER_CONFIGS[entry[0]][2].autoApply));

const TODO_DIFFICULTY_MAP = Object.fromEntries(Object.entries(CARD_FILTER_CONFIGS).map(entry => [entry[0], entry[1][3]]));
const MAX_TOTAL_TODO_DIFFICULTY = Object.entries(TODO_DIFFICULTY_MAP).map(entry => entry[1]).reduce((prev, curr) => prev + curr, 0.0);

Expand Down
11 changes: 4 additions & 7 deletions src/reducers/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ import {
PERMISSION_EDIT_CARD
} from '../permissions.js';

import {
TODO_OVERRIDE_LEGAL_KEYS
} from '../filters.js';

import {
applyCardDiff,
generateCardDiff,
Expand All @@ -80,7 +76,8 @@ import {
EditorContentTab,
EditorState,
EditorTab,
ImageInfoStringProperty
ImageInfoStringProperty,
autoTODOType
} from '../types.js';

const DEFAULT_TAB : EditorTab = 'config';
Expand Down Expand Up @@ -228,7 +225,7 @@ const app = (state : EditorState = INITIAL_STATE, action : SomeAction) : EditorS
case EDITING_AUTO_TODO_OVERRIDE_ENABLED:
if (!state.card) return state;
//Only allow legal keys to be set
if (!TODO_OVERRIDE_LEGAL_KEYS[action.todo]) {
if (!autoTODOType.safeParse(action.todo).success) {
console.warn('Rejecting illegal todo override key: ' + action.todo);
return state;
}
Expand All @@ -239,7 +236,7 @@ const app = (state : EditorState = INITIAL_STATE, action : SomeAction) : EditorS
case EDITING_AUTO_TODO_OVERRIDE_DISABLED:
if (!state.card) return state;
//Only allow legal keys to be set
if (!TODO_OVERRIDE_LEGAL_KEYS[action.todo]) {
if (!autoTODOType.safeParse(action.todo).success) {
console.warn('Rejecting illegal todo override key: ' + action.todo);
return state;
}
Expand Down

0 comments on commit 749eee4

Please sign in to comment.