Use global value to check for current Shop product

Also add other stores types to hint on expected values
This commit is contained in:
2022-06-22 23:20:52 +02:00
parent 255b00ab66
commit 6d4224abea
4 changed files with 21 additions and 10 deletions

View File

@@ -1,9 +1,9 @@
<script lang="ts"> <script lang="ts">
import { goto } from '$app/navigation' import { goto } from '$app/navigation'
import { getContext } from 'svelte' import { getContext } from 'svelte'
import { shopCurrentProductSlug } from '$utils/stores/shop'
export let isOver: boolean = false export let isOver: boolean = false
export let currentProductSlug: string = undefined
const { shopLocations } = getContext('shop') const { shopLocations } = getContext('shop')
@@ -29,7 +29,7 @@
</svg> </svg>
<select on:change={quickLocationChange}> <select on:change={quickLocationChange}>
{#each shopLocations as { name, slug }} {#each shopLocations as { name, slug }}
<option value={slug} selected={slug === currentProductSlug}>{name}</option> <option value={slug} selected={slug === $shopCurrentProductSlug}>{name}</option>
{/each} {/each}
</select> </select>
</dd> </dd>

View File

@@ -127,6 +127,6 @@
class:is-visible={scrolledPastIntro} class:is-visible={scrolledPastIntro}
class:is-overlaid={$cartOpen} class:is-overlaid={$cartOpen}
> >
<ShopLocationSwitcher currentProductSlug={product && product.location.slug} /> <ShopLocationSwitcher />
<ButtonCart /> <ButtonCart />
</nav> </nav>

View File

@@ -1,5 +1,6 @@
<script lang="ts"> <script lang="ts">
import { getContext } from 'svelte' import { getContext } from 'svelte'
import { shopCurrentProductSlug } from '$utils/stores/shop'
// Components // Components
import PageTransition from '$components/PageTransition.svelte' import PageTransition from '$components/PageTransition.svelte'
import Metas from '$components/Metas.svelte' import Metas from '$components/Metas.svelte'
@@ -11,6 +12,9 @@
export let shopProduct: any export let shopProduct: any
const { posters } = getContext('shop') const { posters } = getContext('shop')
// Update current random product slug
$shopCurrentProductSlug = product.location.slug
</script> </script>
<Metas <Metas

View File

@@ -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
*/ */
/** Cart open state */ /** Cart open state */
export const cartOpen = writable(false) export const cartOpen: Writable<boolean> = writable(false)
/** Cart open state */ /** Cart open state */
export const cartId = writable(null) export const cartId: Writable<string> = writable(null)
// Write to localStorage when changing cartId // Write to localStorage when changing cartId
if (typeof localStorage !== 'undefined') { if (typeof localStorage !== 'undefined') {
@@ -20,17 +26,18 @@ if (typeof localStorage !== 'undefined') {
} }
/** Raw Cart data */ /** Raw Cart data */
export const cartData = writable(null) export const cartData: Writable<any> = writable(null)
/** Cart data is being updated */ /** Cart data is being updated */
export const cartIsUpdating = writable(false) export const cartIsUpdating: Writable<boolean> = writable(false)
/** Amount of products present in cart */ /** 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 return $cart && $cart.item_quantity > 0 ? $cart.item_quantity : 0
}) })
/** /**
* Notifications * Notifications
*/ */
export const cartNotifications = writable([]) export const cartNotifications: Writable<any[]> = writable([])