Created
June 14, 2022 20:29
-
-
Save ilyasakin/40fe98b6f8a18df8835743436b6dea63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
... | |
<Spinner :status="isMainLoaderActive" /> | |
... | |
</template> | |
<script setup lang="ts"> | |
// imports ... | |
import { loadingService } from '../services/_singletons.ts'; | |
const isMainLoaderActive = ref<boolean>(false); | |
const products = ref<IProduct[]>([]); | |
const cart = ref<ICartItem[]>([]); | |
watch( | |
() => loadingService.loadings, | |
(newValue: Set<string>) => { | |
const isThereMainLoader = Array.from(newValue).some((loading) => | |
loading.startsWith('main-loader'), | |
); | |
isMainLoaderActive.value = isThereMainLoader; | |
}, | |
{ deep: true }, | |
); | |
const getProducts = async () => { | |
loadingService.startLoading('main-loader:get-products'); | |
products.value = await productsService.getProducts(); | |
loadingService.stopLoading('main-loader:get-products'); | |
}; | |
const getCart = async () => { | |
loadingService.startLoading('main-loader:get-cart-items'); | |
cart.value = await cartService.getCartItems(); | |
loadingService.stopLoading('main-loader:get-cart-items'); | |
}; | |
getProducts(); | |
getCart(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment