Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor create/meta controller to component #814

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}} />