Skip to content

Commit

Permalink
refactor create/meta controller to component (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
jelhan authored Dec 17, 2023
1 parent 26ab849 commit e3935e5
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 87 deletions.
6 changes: 3 additions & 3 deletions app/components/create-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ 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<CreateOptionsIndexSignature> {
export default class CreateIndexComponent extends Component<CreateIndexSignature> {
@service declare router: RouterService;

@action
submit() {
this.router.transitionTo('create.meta');
}

constructor(owner: unknown, args: CreateOptionsIndexSignature['Args']) {
constructor(owner: unknown, args: CreateIndexSignature['Args']) {
super(owner, args);

registerDestructor(this, () => {
Expand Down
45 changes: 45 additions & 0 deletions app/components/create-meta.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<div class="cr-form-wrapper box">
<BsForm
@formLayout="horizontal"
@model={{@formData}}
@onInvalid={{(scroll-first-invalid-element-into-view-port)}}
@onSubmit={{this.submit}}
novalidate
as |form|
>
<form.element
@controlType="text"
@label={{t "create.meta.input.title.label"}}
@property="title"
class="title"
data-test-form-element="title"
as |el|
>
<el.control
placeholder={{t "create.meta.input.title.placeholder"}}
{{autofocus}}
/>
</form.element>
<form.element
@controlType="textarea"
@label={{t "create.meta.input.description.label"}}
@property="description"
class="description"
data-test-form-element="description"
as |el|
>
<el.control
placeholder={{t "create.meta.input.description.placeholder"}}
/>
</form.element>

<div class="row cr-steps-bottom-nav">
<div class="col-6 col-md-8 order-12">
<NextButton />
</div>
<div class="col-6 col-md-4 order-1 text-right">
<BackButton @onClick={{this.previousPage}} />
</div>
</div>
</BsForm>
</div>
44 changes: 44 additions & 0 deletions app/components/create-meta.ts
Original file line number Diff line number Diff line change
@@ -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<CreateMetaSignature> {
@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;
}
}
39 changes: 0 additions & 39 deletions app/controllers/create/meta.ts

This file was deleted.

46 changes: 1 addition & 45 deletions app/templates/create/meta.hbs
Original file line number Diff line number Diff line change
@@ -1,45 +1 @@
<div class="cr-form-wrapper box">
<BsForm
@formLayout="horizontal"
@model={{@model.formData}}
@onInvalid={{(scroll-first-invalid-element-into-view-port)}}
@onSubmit={{this.submit}}
novalidate
as |form|
>
<form.element
@controlType="text"
@label={{t "create.meta.input.title.label"}}
@property="title"
class="title"
data-test-form-element="title"
as |el|
>
<el.control
placeholder={{t "create.meta.input.title.placeholder"}}
{{autofocus}}
/>
</form.element>
<form.element
@controlType="textarea"
@label={{t "create.meta.input.description.label"}}
@property="description"
class="description"
data-test-form-element="description"
as |el|
>
<el.control
placeholder={{t "create.meta.input.description.placeholder"}}
/>
</form.element>

<div class="row cr-steps-bottom-nav">
<div class="col-6 col-md-8 order-12">
<NextButton />
</div>
<div class="col-6 col-md-4 order-1 text-right">
<BackButton @onClick={{this.previousPage}} />
</div>
</div>
</BsForm>
</div>
<CreateMeta @formData={{@model.formData}} @poll={{@model.poll}} />

0 comments on commit e3935e5

Please sign in to comment.