Move Shop store into separate file

This commit is contained in:
2021-11-07 22:38:23 +01:00
parent f7457b5f8d
commit 3198fd8545
8 changed files with 51 additions and 41 deletions

43
src/utils/stores/shop.ts Normal file
View File

@@ -0,0 +1,43 @@
import { writable, derived } from 'svelte/store'
/**
* Shop
*/
export const shopLocations = writable([])
/**
* Cart
*/
/** Cart open state */
export const cartOpen = writable(false)
/** Cart open state */
export const cartId = writable(null)
// Write to localStorage when changing cartId
if (typeof localStorage !== 'undefined') {
if (localStorage.getItem('cartId')) {
// console.log('existant', localStorage.getItem('cartId'))
cartId.set(localStorage.getItem('cartId'))
}
cartId.subscribe(value => localStorage.setItem('cartId', value))
}
/** Raw Cart data */
export const cartData = writable(null)
/** Cart data is being updated */
export const cartIsUpdating = writable(false)
/** Amount of products present in cart */
export const cartAmount = derived(cartData, ($cart) => {
return $cart && $cart.item_quantity > 0 ? $cart.item_quantity : 0
})
/**
* Notifications
*/
export const cartNotifications = writable([])