Skip to content

Commit

Permalink
Convert <AdminAddonReviewForm/> to be a Glimmer component
Browse files Browse the repository at this point in the history
  • Loading branch information
pgengler committed Aug 19, 2021
1 parent eab4cdd commit 771d61d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 42 deletions.
24 changes: 10 additions & 14 deletions app/components/admin-addon-review-form.hbs
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
<h5>Review this addon</h5>
<form class="review-form" {{on "submit" (prevent-default (perform this.saveReview))}}>
<form
class="review-form"
{{on "submit" (prevent-default (perform this.saveReview))}}
{{did-update this.reset @addon}}
>
<ol>
{{#each this.questions as |question|}}
<li class="test-review-question">
<div class="question">{{question.text}}</div>
<ExclusiveButtonGroup @selectedValue={{get this.reviewProperties question.fieldName}} @updateSelectedValue={{fn this.selectOption question.fieldName}} as |btn|>
{{component btn
value=1
label="Yes"}}
{{component btn
value=2
label="No"}}
{{component btn
value=3
label="N/A"}}
{{component btn
value=4
label="Unknown"}}
<ExclusiveButtonGroup @selectedValue={{get this.reviewProperties question.fieldName}} @updateSelectedValue={{fn this.selectOption question.fieldName}} as |Button|>
<Button @value={{1}} @label="Yes" />
<Button @value={{2}} @label="No" />
<Button @value={{3}} @label="N/A" />
<Button @value={{4}} @label="Unknown" />
</ExclusiveButtonGroup>
</li>
{{/each}}
Expand Down
53 changes: 25 additions & 28 deletions app/components/admin-addon-review-form.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,52 @@
/* eslint-disable ember/no-component-lifecycle-hooks */
import classic from 'ember-classic-decorator';
import { inject } from '@ember/service';
import Component from '@ember/component';
import { action } from '@ember/object';
import { task, timeout } from 'ember-concurrency';
import { questions } from '../models/review';
import { inject as service } from '@ember/service';
import Component from '@glimmer/component';
import { tracked } from 'tracked-built-ins';
import { dropTask, timeout } from 'ember-concurrency';
import { questions } from 'ember-observer/models/review';

@classic
export default class AdminAddonReviewForm extends Component {
addon = null;
reviewProperties = null;
@tracked reviewProperties = tracked({});

@tracked
recentlySaved = false;

questions = questions;

@inject()
@service
store;

didReceiveAttrs() {
super.didReceiveAttrs(...arguments);
this.reset();
}

@action
reset() {
this.set('reviewProperties', {});
this.reviewProperties = tracked({});
}

@action
selectOption(fieldName, value) {
this.set(`reviewProperties.${fieldName}`, value);
this.reviewProperties[fieldName] = value;
}

@(task(function* () {
@dropTask
*saveReview() {
let newReview = this.store.createRecord('review', this.reviewProperties);
newReview.set('review', this.reviewText);
newReview.set('version', this.get('addon.latestAddonVersion'));
newReview.set('version', this.args.addon.get('latestAddonVersion'));
try {
yield newReview.save();
this.addon.set('latestReview', newReview);
yield this.addon.save();
this.args.addon.set('latestReview', newReview);
yield this.args.addon.save();
this.reset();
this.complete.perform();
} catch (e) {
console.error(e); // eslint-disable-line no-console
window.alert('Failed to create review');
}
}).drop())
saveReview;
}

@(task(function* () {
this.set('recentlySaved', true);
@dropTask
*complete() {
this.recentlySaved = true;
yield timeout(2000);
this.set('recentlySaved', false);
}).drop())
complete;
this.recentlySaved = false;
}
}

0 comments on commit 771d61d

Please sign in to comment.