Skip to content

Commit

Permalink
EditorTab is now a zod type.
Browse files Browse the repository at this point in the history
Part of #673.
  • Loading branch information
jkomoros committed Nov 12, 2023
1 parent 6dff980 commit bf2e581
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
18 changes: 10 additions & 8 deletions src/components/card-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ import {
TEXT_FIELD_TITLE,
REFERENCE_TYPE_ACK,
REFERENCE_TYPE_CONCEPT,
TAB_CONTENT,
TAB_CONFIG,
TEXT_FIELD_TYPES_EDITABLE
} from '../type_constants.js';

Expand Down Expand Up @@ -148,7 +146,8 @@ import {
State,
ReferenceType,
CardFieldTypeEditable,
editorContentTab
editorContentTab,
editorTab
} from '../types.js';

import {
Expand All @@ -163,7 +162,10 @@ import {
ARROW_UP_ICON,
ARROW_RIGHT_ICON
} from './my-icons';
import { titleForEditingCardWithAI } from '../actions/ai.js';

import {
titleForEditingCardWithAI
} from '../actions/ai.js';

@customElement('card-editor')
class CardEditor extends connect(store)(LitElement) {
Expand Down Expand Up @@ -449,7 +451,7 @@ class CardEditor extends connect(store)(LitElement) {
<div class='container ${this._cardModificationPending ? 'modification-pending' : ''} ${this._minimized ? 'minimized' : 'not-minimized'}'>
<div class='scrim'></div>
<div class='inputs'>
<div ?hidden=${this._selectedTab !== TAB_CONTENT} class='flex body'>
<div ?hidden=${this._selectedTab !== 'content'} class='flex body'>
<div class='tabs' @click=${this._handleEditorTabClicked}>
<label data-name='${editorContentTab('content')}' ?data-selected=${this._selectedEditorTab == 'content'} ?data-empty=${!hasContent} ?data-modified=${contentModified}>Content</label>
<label data-name='${editorContentTab('notes')}' ?data-selected=${this._selectedEditorTab == 'notes'} ?data-empty=${!hasNotes} ?data-modified=${notesModified}>Notes</label>
Expand All @@ -471,7 +473,7 @@ class CardEditor extends connect(store)(LitElement) {
<textarea ?hidden=${this._selectedEditorTab !== 'notes'} @input='${this._handleNotesUpdated}' .value=${this._card.notes}></textarea>
<textarea ?hidden=${this._selectedEditorTab !== 'todo'} @input='${this._handleTodoUpdated}' .value=${this._card.todo}></textarea>
</div>
<div ?hidden=${this._selectedTab !== TAB_CONFIG}>
<div ?hidden=${this._selectedTab !== 'config'}>
<div class='row'>
<div>
<label>Section ${help('Cards are in 0 or 1 sections, which determines the default order they show up in. Cards that are orphaned will not show up in any default collection.')}</label>
Expand Down Expand Up @@ -754,8 +756,8 @@ class CardEditor extends connect(store)(LitElement) {
</div>
` :
html`<div class='tabs main' @click=${this._handleTabClicked}>
<label data-name='${TAB_CONFIG}' ?data-selected=${this._selectedTab == TAB_CONFIG}>Configuration</label>
<label data-name='${TAB_CONTENT}' ?data-selected=${this._selectedTab == TAB_CONTENT}>Content</label>
<label data-name='${editorTab('config')}' ?data-selected=${this._selectedTab == 'config'}>Configuration</label>
<label data-name='${editorTab('content')}' ?data-selected=${this._selectedTab == 'content'}>Content</label>
</div>`}
<div class='flex'>
</div>
Expand Down
7 changes: 2 additions & 5 deletions src/reducers/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ import {
SomeAction,
} from '../actions.js';

import {
TAB_CONFIG
} from '../type_constants.js';

import {
SET_PENDING_SLUG
} from '../actions.js';
Expand Down Expand Up @@ -83,10 +79,11 @@ import {
import {
EditorContentTab,
EditorState,
EditorTab,
ImageInfoStringProperty
} from '../types.js';

const DEFAULT_TAB = TAB_CONFIG;
const DEFAULT_TAB : EditorTab = 'config';
const DEFAULT_EDITOR_TAB : EditorContentTab = 'content';

const INITIAL_STATE : EditorState = {
Expand Down
9 changes: 0 additions & 9 deletions src/type_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,6 @@ export const REFERENCE_TYPE_TYPES = {
[REFERENCE_TYPE_CITATION_PERSON]: true
};

export const TAB_CONTENT = 'content';
export const TAB_CONFIG = 'config';

//Drives EditorTab type
export const EDITOR_TAB_TYPES = {
[TAB_CONTENT]: true,
[TAB_CONFIG]: true
};

export const CARDS_COLLECTION = 'cards';
export const CARD_UPDATES_COLLECTION = 'updates';
export const SECTION_UPDATES_COLLECTION = 'updates';
Expand Down
10 changes: 8 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
TEXT_FIELD_TYPES,
REFERENCE_TYPE_TYPES,
TEXT_FIELD_TYPES_EDITABLE,
EDITOR_TAB_TYPES,
FIND_CARD_TO_LINK,
FIND_CARD_TO_PERMISSION,
FIND_CARD_TO_REFERENCE,
Expand Down Expand Up @@ -395,7 +394,13 @@ export type ConfigurableFilterConfigurationMap = {
};

//TODO: this name is confusing, in the state this is just called tab
export type EditorTab = keyof(typeof EDITOR_TAB_TYPES);

const editorTabSchema = z.enum([
'content',
'config'
]);

export type EditorTab = z.infer<typeof editorTabSchema>;

const editorContentTabSchema = z.enum([
'content',
Expand Down Expand Up @@ -1330,4 +1335,5 @@ export type State = {
//will be used in a generic string context and want type-checking to verify it
//is part of the enum.
export const setName = (input : SetName) => input;
export const editorTab = (input : EditorTab) => input;
export const editorContentTab = (input : EditorContentTab) => input;

0 comments on commit bf2e581

Please sign in to comment.