Move Shop store into separate file
This commit is contained in:
43
src/utils/stores/shop.ts
Normal file
43
src/utils/stores/shop.ts
Normal 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([])
|
||||
Reference in New Issue
Block a user