forked from SymfonyCasts/symfony-ux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreloadcontroller-bootstrap-controller.diff
40 lines (38 loc) · 1.15 KB
/
reloadcontroller-bootstrap-controller.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
diff --git a/assets/controllers/reload-content_controller.js b/assets/controllers/reload-content_controller.js
new file mode 100644
index 0000000..8c13edf
--- /dev/null
+++ b/assets/controllers/reload-content_controller.js
@@ -0,0 +1,18 @@
+import { Controller } from 'stimulus';
+
+export default class extends Controller {
+ static values = {
+ cartRefreshUrl: String,
+ }
+
+ connect() {
+ console.log('🔁');
+ }
+
+ async removeItem(event) {
+ event.currentTarget.classList.add('removing');
+
+ const response = await fetch(this.cartRefreshUrlValue);
+ this.element.innerHTML = await response.text();
+ }
+}
diff --git a/templates/product_admin/index.html.twig b/templates/product_admin/index.html.twig
index 0727b11..18fe40f 100644
--- a/templates/product_admin/index.html.twig
+++ b/templates/product_admin/index.html.twig
@@ -3,7 +3,10 @@
{% block title %}Product index{% endblock %}
{% block body %}
-<div class="container-fluid mt-4">
+<div
+ class="container-fluid mt-4"
+ {{ stimulus_controller('reload-content') }}
+>
<div class="d-flex flex-row">
<h1 class="me-3">Product index</h1>