diff --git a/app/components/toast.hbs b/app/components/toast.hbs
index 5888e94..b33c041 100644
--- a/app/components/toast.hbs
+++ b/app/components/toast.hbs
@@ -1,25 +1,22 @@
-{{#in-element this.toasts.destinationElement}}
-
-
-
-
-
-
- {{@text}}
-
-
-
+
+
+
-{{/in-element}}
+
+
+ {{@text}}
+
+
+
+
diff --git a/app/components/toast.js b/app/components/toast.js
index 08ffc1d..375ab55 100644
--- a/app/components/toast.js
+++ b/app/components/toast.js
@@ -1,6 +1,19 @@
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
+import { registerDestructor } from '@ember/destroyable';
+import { action } from '@ember/object';
export default class ToastComponent extends Component {
@service toasts;
+
+ constructor(owner, args) {
+ super(owner, args);
+
+ // registerDestructor(this, this.destroy);
+ }
+
+ @action
+ destroyFromPlate() {
+ this.args?.willDestroy();
+ }
}
diff --git a/app/components/toasts-container.hbs b/app/components/toasts-container.hbs
new file mode 100644
index 0000000..50c7cc6
--- /dev/null
+++ b/app/components/toasts-container.hbs
@@ -0,0 +1,7 @@
+{{#in-element this.toasts.destinationElement}}
+
+ {{#each this.toasts.plate as |Item|}}
+
+ {{/each}}
+
+{{/in-element}}
diff --git a/app/components/toasts-container.js b/app/components/toasts-container.js
new file mode 100644
index 0000000..8c53aaf
--- /dev/null
+++ b/app/components/toasts-container.js
@@ -0,0 +1,6 @@
+import Component from '@glimmer/component';
+import { inject as service } from '@ember/service';
+
+export default class ToastsContainerComponent extends Component {
+ @service toasts;
+}
diff --git a/app/controllers/admin/indexes/item/edit.js b/app/controllers/admin/indexes/item/edit.js
index c4bde3e..8afec84 100644
--- a/app/controllers/admin/indexes/item/edit.js
+++ b/app/controllers/admin/indexes/item/edit.js
@@ -10,12 +10,12 @@ export default class AdminIndexesItemEditController extends Controller {
save(event) {
event.preventDefault();
- const formData = new FormData(event.currentTarget);
- const data = Object.fromEntries(formData.entries());
+ // const formData = new FormData(event.currentTarget);
+ // const data = Object.fromEntries(formData.entries());
- this.model.save(data);
+ // this.model.save(data);
- this.toasts.add('Hello World!');
+ this.toasts.successToast({ text: 'Hello World!' });
}
@action
diff --git a/app/services/toasts.js b/app/services/toasts.js
index ec73718..0499ba9 100644
--- a/app/services/toasts.js
+++ b/app/services/toasts.js
@@ -1,6 +1,53 @@
import Service from '@ember/service';
import { tracked } from '@glimmer/tracking';
+import Toast from '../components/toast';
+import { hbs } from 'ember-template-imports';
+import { fn } from '@ember/helper';
+// const toast = hbs`
+// {{component Toast text="hel"}}
+// `;
+
+// import { RenderingTestCase, moduleFor, strip } from 'internal-test-helpers';
+
+// import { precompileJSON } from '@glimmer/compiler';
+// import { getTemplateLocals } from '@glimmer/syntax';
+// import { createTemplateFactory } from '@ember/template-factory';
+
+// // import { Helper } from '../../index';
+// import { setComponentTemplate } from '@glimmer/manager';
+// import { templateOnlyComponent } from '@glimmer/runtime';
+
+// function precompileTemplate(source, { moduleName, scope = {} }) {
+// let locals = getTemplateLocals(source);
+
+// let options = {
+// strictMode: true,
+// moduleName,
+// locals,
+// isProduction: false,
+// meta: { moduleName },
+// };
+
+// // Copied from @glimmer/compiler/lib/compiler#precompile
+// let [block, usedLocals] = precompileJSON(source, options);
+// let usedScope = usedLocals.map((key) => scope[key]);
+
+// let blockJSON = JSON.stringify(block);
+// let templateJSONObject = {
+// id: moduleName,
+// block: blockJSON,
+// moduleName: moduleName ?? '(unknown template module)',
+// scope: () => usedScope,
+// isStrictMode: true,
+// };
+
+// let factory = createTemplateFactory(templateJSONObject);
+
+// return factory;
+// }
+
+// console.log(toast);
export default class ToastsService extends Service {
@tracked plate = [];
@@ -12,7 +59,17 @@ export default class ToastsService extends Service {
document.body.appendChild(this.destinationElement);
}
- add() {
+ successToast({ text }) {
+ const removeFromPlate = (toast) => {
+ this.plate = this.plate.filter((item) => item !== toast);
+ };
+ const toast = hbs`
`;
+ console.log('successToast', toast);
+ this.addToPlate(toast);
+ }
+
+ addToPlate(toast) {
+ this.plate = this.plate.concat(toast);
}
}
diff --git a/app/templates/admin/indexes/item/edit.hbs b/app/templates/admin/indexes/item/edit.hbs
index 2e044ef..4588e83 100644
--- a/app/templates/admin/indexes/item/edit.hbs
+++ b/app/templates/admin/indexes/item/edit.hbs
@@ -18,4 +18,4 @@
-
+{{!--
--}}
diff --git a/app/templates/application.hbs b/app/templates/application.hbs
index c24cd68..7fa6fb9 100644
--- a/app/templates/application.hbs
+++ b/app/templates/application.hbs
@@ -1 +1,3 @@
{{outlet}}
+
+
diff --git a/tests/integration/components/toasts-container-test.js b/tests/integration/components/toasts-container-test.js
new file mode 100644
index 0000000..fbf3bb9
--- /dev/null
+++ b/tests/integration/components/toasts-container-test.js
@@ -0,0 +1,26 @@
+import { module, test } from 'qunit';
+import { setupRenderingTest } from 'meiliadmin/tests/helpers';
+import { render } from '@ember/test-helpers';
+import { hbs } from 'ember-cli-htmlbars';
+
+module('Integration | Component | toasts-container', function (hooks) {
+ setupRenderingTest(hooks);
+
+ test('it renders', async function (assert) {
+ // Set any properties with this.set('myProperty', 'value');
+ // Handle any actions with this.set('myAction', function(val) { ... });
+
+ await render(hbs`
`);
+
+ assert.dom(this.element).hasText('');
+
+ // Template block usage:
+ await render(hbs`
+
+ template block text
+
+ `);
+
+ assert.dom(this.element).hasText('template block text');
+ });
+});