From ef8e4255678d9bec7c0b28a967618e64fdbfe253 Mon Sep 17 00:00:00 2001 From: Jeldrik Hanschke Date: Sun, 17 Dec 2023 22:27:33 +0100 Subject: [PATCH] refactor create/meta controller to component --- app/components/create-index.ts | 6 ++--- app/components/create-meta.hbs | 45 +++++++++++++++++++++++++++++++++ app/components/create-meta.ts | 44 ++++++++++++++++++++++++++++++++ app/controllers/create/meta.ts | 39 ---------------------------- app/templates/create/meta.hbs | 46 +--------------------------------- 5 files changed, 93 insertions(+), 87 deletions(-) create mode 100644 app/components/create-meta.hbs create mode 100644 app/components/create-meta.ts delete mode 100644 app/controllers/create/meta.ts diff --git a/app/components/create-index.ts b/app/components/create-index.ts index 664ffa091..dfc856e36 100644 --- a/app/components/create-index.ts +++ b/app/components/create-index.ts @@ -5,14 +5,14 @@ import { registerDestructor } from '@ember/destroyable'; import type RouterService from '@ember/routing/router-service'; import type { CreateIndexRouteModel } from '../routes/create/index'; -export interface CreateOptionsIndexSignature { +export interface CreateIndexSignature { Args: { formData: CreateIndexRouteModel['formData']; poll: CreateIndexRouteModel['poll']; }; } -export default class CreateIndexComponent extends Component { +export default class CreateIndexComponent extends Component { @service declare router: RouterService; @action @@ -20,7 +20,7 @@ export default class CreateIndexComponent extends Component { diff --git a/app/components/create-meta.hbs b/app/components/create-meta.hbs new file mode 100644 index 000000000..d74aecd67 --- /dev/null +++ b/app/components/create-meta.hbs @@ -0,0 +1,45 @@ +
+ + + + + + + + +
+
+ +
+
+ +
+
+
+
\ No newline at end of file diff --git a/app/components/create-meta.ts b/app/components/create-meta.ts new file mode 100644 index 000000000..1bd43aac5 --- /dev/null +++ b/app/components/create-meta.ts @@ -0,0 +1,44 @@ +import Component from '@glimmer/component'; +import { inject as service } from '@ember/service'; +import { action } from '@ember/object'; +import { registerDestructor } from '@ember/destroyable'; +import type RouterService from '@ember/routing/router-service'; +import type { CreateMetaRouteModel } from '../routes/create/meta'; + +export interface CreateMetaSignature { + Args: { + formData: CreateMetaRouteModel['formData']; + poll: CreateMetaRouteModel['poll']; + }; +} + +export default class CreateMetaComponent extends Component { + @service declare router: RouterService; + + @action + previousPage() { + this.router.transitionTo('create.index'); + } + + @action + submit() { + this.router.transitionTo('create.options'); + } + + constructor(owner: unknown, args: CreateMetaSignature['Args']) { + super(owner, args); + + registerDestructor(this, () => { + const { poll, formData } = this.args; + + poll.title = formData.title; + poll.description = formData.description; + }); + } +} + +declare module '@glint/environment-ember-loose/registry' { + export default interface Registry { + CreateMeta: typeof CreateMetaComponent; + } +} diff --git a/app/controllers/create/meta.ts b/app/controllers/create/meta.ts deleted file mode 100644 index 5e76c6b90..000000000 --- a/app/controllers/create/meta.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { inject as service } from '@ember/service'; -import { action } from '@ember/object'; -import Controller from '@ember/controller'; -import type RouterService from '@ember/routing/router-service'; -import type Transition from '@ember/routing/transition'; -import type { CreateMetaRouteModel } from 'croodle/routes/create/meta'; - -export default class CreateMetaController extends Controller { - @service declare router: RouterService; - - declare model: CreateMetaRouteModel; - - @action - previousPage() { - this.router.transitionTo('create.index'); - } - - @action - submit() { - this.router.transitionTo('create.options'); - } - - @action - handleTransition(transition: Transition) { - if (transition.from?.name === 'create.meta') { - const { poll, formData } = this.model; - - poll.title = formData.title; - poll.description = formData.description; - } - } - - constructor() { - // eslint-disable-next-line prefer-rest-params - super(...arguments); - - this.router.on('routeWillChange', this.handleTransition); - } -} diff --git a/app/templates/create/meta.hbs b/app/templates/create/meta.hbs index 5c8483e2d..5ac5477da 100644 --- a/app/templates/create/meta.hbs +++ b/app/templates/create/meta.hbs @@ -1,45 +1 @@ -
- - - - - - - - -
-
- -
-
- -
-
-
-
\ No newline at end of file + \ No newline at end of file