Skip to content

Commit 40c9177

Browse files
authored
Merge pull request #1518 from w3bdesign/develop
Refactor cart loading and error state handling
2 parents 0d1d899 + 11050f4 commit 40c9177

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

components/Cart/CartContents.vue

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* @module CartContents
3333
* @returns {Object} The Vue.js component object.
3434
*/
35-
import { computed, ref, onMounted } from "vue";
35+
import { computed } from "vue";
3636
import { useCart } from "@/store/useCart";
3737
3838
const props = defineProps({
@@ -43,9 +43,10 @@ const props = defineProps({
4343
});
4444
4545
const cart = useCart();
46-
const isLoading = ref(true);
47-
const error = ref(null);
4846
47+
// Use the store's reactive state directly
48+
const isLoading = computed(() => cart.loading);
49+
const error = computed(() => cart.error);
4950
const cartItems = computed(() => cart.cart);
5051
5152
/**
@@ -59,16 +60,6 @@ const handleRemoveProduct = async (key) => {
5960
} catch (error) {}
6061
};
6162
62-
onMounted(async () => {
63-
try {
64-
await cart.refetch();
65-
} catch (err) {
66-
error.value = err;
67-
} finally {
68-
isLoading.value = false;
69-
}
70-
});
71-
7263
/**
7364
* Handles updating the quantity of a cart item.
7465
*

components/Layout/LayoutCart.vue

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,15 @@
4848
</template>
4949

5050
<script setup>
51-
import { ref, computed, onMounted } from "vue";
51+
import { computed } from "vue";
5252
import { useCart } from "@/store/useCart";
5353
import { formatPrice } from "@/utils/functions";
5454
5555
const cart = useCart();
56-
const isLoading = ref(true);
57-
const error = ref(null);
5856
57+
// Use the store's reactive state directly
58+
const isLoading = computed(() => cart.loading);
59+
const error = computed(() => cart.error);
5960
const cartLength = computed(() => cart.cartQuantity);
6061
const cartSubtotal = computed(() => cart.cartSubtotal);
61-
62-
onMounted(async () => {
63-
try {
64-
await cart.refetch();
65-
} catch (err) {
66-
error.value = err;
67-
} finally {
68-
isLoading.value = false;
69-
}
70-
});
7162
</script>

0 commit comments

Comments
 (0)