From 749eee4d8e944eca3697d31ea9acf75f0ed8c364 Mon Sep 17 00:00:00 2001 From: Alex Komoroske Date: Sun, 12 Nov 2023 20:45:51 -0800 Subject: [PATCH] Get rid of TODO_OVERRIDE_LEGAL_KEYS and instead rely directly on the formal zod type checker. Part of #670. --- src/filters.ts | 7 ------- src/reducers/editor.ts | 11 ++++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/filters.ts b/src/filters.ts index 8b7c2aaf..2f8552d7 100644 --- a/src/filters.ts +++ b/src/filters.ts @@ -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); diff --git a/src/reducers/editor.ts b/src/reducers/editor.ts index a225508e..f64762ed 100644 --- a/src/reducers/editor.ts +++ b/src/reducers/editor.ts @@ -59,10 +59,6 @@ import { PERMISSION_EDIT_CARD } from '../permissions.js'; -import { - TODO_OVERRIDE_LEGAL_KEYS -} from '../filters.js'; - import { applyCardDiff, generateCardDiff, @@ -80,7 +76,8 @@ import { EditorContentTab, EditorState, EditorTab, - ImageInfoStringProperty + ImageInfoStringProperty, + autoTODOType } from '../types.js'; const DEFAULT_TAB : EditorTab = 'config'; @@ -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; } @@ -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; }