Move Shop store into separate file
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { cartNotifications } from './store'
|
||||
import { cartNotifications } from '$utils/stores/shop'
|
||||
|
||||
interface Notification {
|
||||
title: string
|
||||
@@ -8,6 +8,7 @@ interface Notification {
|
||||
id?: number
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a notification
|
||||
*/
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
import { writable, derived } from 'svelte/store'
|
||||
|
||||
|
||||
/**
|
||||
* Shop
|
||||
*/
|
||||
/** Open Cart state */
|
||||
export const cartOpen = writable(false)
|
||||
|
||||
/** Current Cart ID */
|
||||
export const cartId = writable(null)
|
||||
|
||||
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([])
|
||||
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