From 771d61d046d67947b423c0b4f07fe7f26c8e2772 Mon Sep 17 00:00:00 2001 From: Phil Gengler Date: Wed, 18 Aug 2021 20:11:08 -0400 Subject: [PATCH] Convert to be a Glimmer component --- app/components/admin-addon-review-form.hbs | 24 ++++------ app/components/admin-addon-review-form.js | 53 ++++++++++------------ 2 files changed, 35 insertions(+), 42 deletions(-) diff --git a/app/components/admin-addon-review-form.hbs b/app/components/admin-addon-review-form.hbs index 1fb4ba2d..955415cd 100644 --- a/app/components/admin-addon-review-form.hbs +++ b/app/components/admin-addon-review-form.hbs @@ -1,22 +1,18 @@
Review this addon
-
+
    {{#each this.questions as |question|}}
  1. {{question.text}}
    - - {{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"}} + +
  2. {{/each}} diff --git a/app/components/admin-addon-review-form.js b/app/components/admin-addon-review-form.js index dec3cb87..e0a29a30 100644 --- a/app/components/admin-addon-review-form.js +++ b/app/components/admin-addon-review-form.js @@ -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; + } }