From dc4db405d2991d3ec6a114f3b08d3fccd057d3ee Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Thu, 13 Feb 2025 17:52:16 +0100 Subject: frontend: Migrate to Svelte 5 --- frontend/src/lib/Update.svelte.ts | 94 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 frontend/src/lib/Update.svelte.ts (limited to 'frontend/src/lib/Update.svelte.ts') diff --git a/frontend/src/lib/Update.svelte.ts b/frontend/src/lib/Update.svelte.ts new file mode 100644 index 0000000..1d684d5 --- /dev/null +++ b/frontend/src/lib/Update.svelte.ts @@ -0,0 +1,94 @@ +import { + UpdateMode, + type UpdateComicInput, + type UpdateOptions, + type UpdateTagInput +} from '$gql/graphql'; +import type { Key } from './Utils'; + +interface AssociationUpdate { + ids?: number[] | string[] | null; + options?: UpdateOptions | null; +} + +type Input = Partial>; + +abstract class Entry { + key: K; + + constructor(key: K) { + this.key = key; + } + + abstract integrate(input: Input): void; + abstract hasInput(): boolean; +} + +class Association extends Entry { + ids = $state([]); + options = $state({ + mode: UpdateMode.Add + }); + + constructor(key: K) { + super(key); + } + + integrate(input: Input) { + if (this.hasInput()) { + input[this.key] = { ids: this.ids, options: this.options }; + } + } + + hasInput() { + return this.ids.length > 0; + } +} + +class Enum extends Entry { + value?: string = $state(undefined); + + constructor(key: K) { + super(key); + } + + integrate(input: Input): void { + if (this.hasInput()) { + input[this.key] = this.value; + } + } + + hasInput() { + return this.value !== undefined && this.value !== null; + } +} + +abstract class Controls { + input() { + const input = {} as I; + Object.values(this).forEach((v: Entry) => v.integrate(input)); + return input; + } + + pending() { + return Object.values(this).some((i: Entry) => i.hasInput()); + } +} + +export class UpdateTagsControls extends Controls { + namespaces = new Association('namespaces'); +} + +export class UpdateComicsControls extends Controls { + artists = new Association('artists'); + category = new Enum('category'); + censorship = new Enum('censorship'); + direction = new Enum('direction'); + layout = new Enum('layout'); + characters = new Association('characters'); + circles = new Association('circles'); + language = new Enum('language'); + rating = new Enum('rating'); + tags = new Association('tags'); + worlds = new Association('worlds'); +} -- cgit v1.2.3-2-gb3c3