From 0f5c09b079e7df55cbb24ab931ba9954e45b7d0e Mon Sep 17 00:00:00 2001 From: PhilippMDoerner Date: Thu, 12 Dec 2024 13:02:05 +0100 Subject: [PATCH] Type improvements --- .../pages/graph-page/graph-page.component.ts | 11 +++++------ src/design/molecules/_models/search-preferences.ts | 14 ++++++++++++-- src/design/molecules/index.ts | 2 +- .../sidebar-legend/sidebar-legend.component.ts | 8 ++++---- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/app/campaign/pages/graph-page/graph-page.component.ts b/src/app/campaign/pages/graph-page/graph-page.component.ts index 38054a77f..41c476600 100644 --- a/src/app/campaign/pages/graph-page/graph-page.component.ts +++ b/src/app/campaign/pages/graph-page/graph-page.component.ts @@ -32,6 +32,10 @@ import { DEFAULT_SEARCH_PREFERENCES, SidebarOption, } from 'src/design/molecules'; +import { + CategoryLabel, + GRAPH_CATEGORIES, +} from 'src/design/molecules/_models/search-preferences'; import { GraphMenuService } from 'src/design/organisms/graph/graph-menu.service'; import { GraphService } from 'src/design/organisms/graph/graph.service'; import { filterNil } from 'src/utils/rxjs-operators'; @@ -132,12 +136,7 @@ export class GraphPageComponent { }), ); - private AVAILABLE_NODE_TYPES = new Set([ - 'Character', - 'Item', - 'Organization', - 'Location', - ]); + private AVAILABLE_NODE_TYPES = new Set(GRAPH_CATEGORIES); private nodeTypeOptions = DEFAULT_SEARCH_PREFERENCES.filter((option) => this.AVAILABLE_NODE_TYPES.has(option.label), ); diff --git a/src/design/molecules/_models/search-preferences.ts b/src/design/molecules/_models/search-preferences.ts index 40a8246f3..c04f91bea 100644 --- a/src/design/molecules/_models/search-preferences.ts +++ b/src/design/molecules/_models/search-preferences.ts @@ -1,4 +1,4 @@ -export interface CategoryOption { +export interface ArticleCategory { label: string; active: boolean; color: string; @@ -17,4 +17,14 @@ export const DEFAULT_SEARCH_PREFERENCES = [ { label: 'SessionAudio', active: false, color: '--sessionaudio-color' }, { label: 'Rules', active: false, color: '--rules-color' }, { label: 'Spell', active: false, color: '--spell-color' }, -] as const satisfies CategoryOption[]; +] as const satisfies ArticleCategory[]; + +export type CategoryLabel = + (typeof DEFAULT_SEARCH_PREFERENCES)[number]['label']; + +export const GRAPH_CATEGORIES = [ + 'Character', + 'Item', + 'Organization', + 'Location', +] as const satisfies CategoryLabel[]; diff --git a/src/design/molecules/index.ts b/src/design/molecules/index.ts index 14ad14a1c..e42da4002 100644 --- a/src/design/molecules/index.ts +++ b/src/design/molecules/index.ts @@ -2,7 +2,7 @@ export { BadgeListEntry, BadgeListSelectOptions } from './_models/badge-list'; export { ListEntry } from './_models/list'; export { DEFAULT_SEARCH_PREFERENCES, - CategoryOption as SidebarOption, + ArticleCategory as SidebarOption, } from './_models/search-preferences'; export { ToggleState } from './_models/toggle'; export { ArticleFooterComponent } from './article-footer/article-footer.component'; diff --git a/src/design/molecules/sidebar-legend/sidebar-legend.component.ts b/src/design/molecules/sidebar-legend/sidebar-legend.component.ts index 9eb3cad68..5019821c0 100644 --- a/src/design/molecules/sidebar-legend/sidebar-legend.component.ts +++ b/src/design/molecules/sidebar-legend/sidebar-legend.component.ts @@ -7,7 +7,7 @@ import { } from '@angular/core'; import { SelectableEntryComponent } from '../../atoms/selectable-entry/selectable-entry.component'; import { - CategoryOption, + ArticleCategory, DEFAULT_SEARCH_PREFERENCES, } from '../_models/search-preferences'; @@ -21,10 +21,10 @@ import { }) export class SidebarLegendComponent { interactable = input(false); - sidebarEntries = input(DEFAULT_SEARCH_PREFERENCES); + sidebarEntries = input(DEFAULT_SEARCH_PREFERENCES); - @Output() sidebarChange: EventEmitter = new EventEmitter< - CategoryOption[] + @Output() sidebarChange: EventEmitter = new EventEmitter< + ArticleCategory[] >(); constructor() {}