Use global value to check for current Shop product
Also add other stores types to hint on expected values
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import { getContext } from 'svelte'
|
||||
import { shopCurrentProductSlug } from '$utils/stores/shop'
|
||||
|
||||
export let isOver: boolean = false
|
||||
export let currentProductSlug: string = undefined
|
||||
|
||||
const { shopLocations } = getContext('shop')
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
</svg>
|
||||
<select on:change={quickLocationChange}>
|
||||
{#each shopLocations as { name, slug }}
|
||||
<option value={slug} selected={slug === currentProductSlug}>{name}</option>
|
||||
<option value={slug} selected={slug === $shopCurrentProductSlug}>{name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</dd>
|
||||
|
||||
@@ -127,6 +127,6 @@
|
||||
class:is-visible={scrolledPastIntro}
|
||||
class:is-overlaid={$cartOpen}
|
||||
>
|
||||
<ShopLocationSwitcher currentProductSlug={product && product.location.slug} />
|
||||
<ShopLocationSwitcher />
|
||||
<ButtonCart />
|
||||
</nav>
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { getContext } from 'svelte'
|
||||
import { shopCurrentProductSlug } from '$utils/stores/shop'
|
||||
// Components
|
||||
import PageTransition from '$components/PageTransition.svelte'
|
||||
import Metas from '$components/Metas.svelte'
|
||||
@@ -11,6 +12,9 @@
|
||||
export let shopProduct: any
|
||||
|
||||
const { posters } = getContext('shop')
|
||||
|
||||
// Update current random product slug
|
||||
$shopCurrentProductSlug = product.location.slug
|
||||
</script>
|
||||
|
||||
<Metas
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
import { writable, derived } from 'svelte/store'
|
||||
import { writable, derived, type Writable, type Readable } from 'svelte/store'
|
||||
|
||||
|
||||
/**
|
||||
* Shop
|
||||
*/
|
||||
export const shopCurrentProductSlug: Writable<string> = writable(null)
|
||||
|
||||
|
||||
/**
|
||||
* Cart
|
||||
*/
|
||||
/** Cart open state */
|
||||
export const cartOpen = writable(false)
|
||||
export const cartOpen: Writable<boolean> = writable(false)
|
||||
|
||||
/** Cart open state */
|
||||
export const cartId = writable(null)
|
||||
export const cartId: Writable<string> = writable(null)
|
||||
|
||||
// Write to localStorage when changing cartId
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
@@ -20,17 +26,18 @@ if (typeof localStorage !== 'undefined') {
|
||||
}
|
||||
|
||||
/** Raw Cart data */
|
||||
export const cartData = writable(null)
|
||||
export const cartData: Writable<any> = writable(null)
|
||||
|
||||
/** Cart data is being updated */
|
||||
export const cartIsUpdating = writable(false)
|
||||
export const cartIsUpdating: Writable<boolean> = writable(false)
|
||||
|
||||
/** Amount of products present in cart */
|
||||
export const cartAmount = derived(cartData, ($cart) => {
|
||||
export const cartAmount: Readable<number> = derived(cartData, ($cart) => {
|
||||
return $cart && $cart.item_quantity > 0 ? $cart.item_quantity : 0
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* Notifications
|
||||
*/
|
||||
export const cartNotifications = writable([])
|
||||
export const cartNotifications: Writable<any[]> = writable([])
|
||||
Reference in New Issue
Block a user