forked from SymfonyCasts/symfony-ux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreloadcontroller-re-use-on-cart.diff
48 lines (48 loc) · 1.77 KB
/
reloadcontroller-re-use-on-cart.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
41
42
43
44
45
46
47
48
diff --git a/assets/controllers/cart-list_controller.js b/assets/controllers/cart-list_controller.js
deleted file mode 100644
index 0460715..0000000
--- a/assets/controllers/cart-list_controller.js
+++ /dev/null
@@ -1,14 +0,0 @@
-import { Controller } from 'stimulus';
-
-export default class extends Controller {
- static values = {
- cartRefreshUrl: String,
- }
-
- async removeItem(event) {
- event.currentTarget.classList.add('removing');
-
- const response = await fetch(this.cartRefreshUrlValue);
- this.element.innerHTML = await response.text();
- }
-}
diff --git a/templates/cart/_cartList.html.twig b/templates/cart/_cartList.html.twig
index 5da81fc..f512bec 100644
--- a/templates/cart/_cartList.html.twig
+++ b/templates/cart/_cartList.html.twig
@@ -14,7 +14,7 @@
{% for item in cart.items %}
<div
class="cart-item row p-3"
- data-action="submit-confirm:async:submitted->cart-list#removeItem"
+ data-action="submit-confirm:async:submitted->reload-content#refreshContent"
>
<div class="col-2">
{{ item.product.name }}
diff --git a/templates/cart/cart.html.twig b/templates/cart/cart.html.twig
index f33e620..2e24399 100644
--- a/templates/cart/cart.html.twig
+++ b/templates/cart/cart.html.twig
@@ -13,8 +13,8 @@
<h1>Shopping Cart</h1>
<div
class="component-light p-3"
- {{ stimulus_controller('cart-list', {
- cartRefreshUrl: path('_app_cart_list')
+ {{ stimulus_controller('reload-content', {
+ url: path('_app_cart_list')
}) }}
>
{{ include('cart/_cartList.html.twig') }}