From 31351ae0955a546f64449f3f9bc1941a7aa5490f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Sat, 30 Jul 2022 10:27:58 +0200 Subject: [PATCH] Create props for ShopModule content Allows to customize content if for a specific one for instance --- src/components/organisms/ShopModule.svelte | 53 ++++++++++++++-------- src/style/organisms/_shop.scss | 10 ++++ 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/components/organisms/ShopModule.svelte b/src/components/organisms/ShopModule.svelte index c301fa2..abf39f1 100644 --- a/src/components/organisms/ShopModule.svelte +++ b/src/components/organisms/ShopModule.svelte @@ -8,12 +8,6 @@ import Button from '$components/atoms/Button.svelte' import Image from '$components/atoms/Image.svelte' - interface Location { - slug: string - name: string - has_poster: boolean - } - const { locations, shop } = getContext('global') const locationsWithPoster = locations // Filter locations with posters only @@ -23,22 +17,43 @@ // Return name only .map((loc: Location) => loc.name) + export let images: any[] = shop.module_images + export let title: string = shop.module_title + export let text: string = shop.module_text + export let textBottom: string = undefined + export let buttonText: string = 'Shop' + export let url: string = '/shop' + export let enabled: boolean = true + + if (textBottom !== null && textBottom !== undefined) { + textBottom = `Posters available for ${locationsWithPoster.join(', ').replace(/,(?!.*,)/gmi, ' and')}.` + } + + interface Location { + slug: string + name: string + has_poster: boolean + } // Image rotation let imagesLoop: ReturnType let currentImageIndex = 0 const incrementCurrentImageIndex = () => { - currentImageIndex = currentImageIndex === shop.module_images.length - 1 ? 0 : currentImageIndex + 1 + currentImageIndex = currentImageIndex === images.length - 1 ? 0 : currentImageIndex + 1 imagesLoop = setTimeout(() => requestAnimationFrame(incrementCurrentImageIndex), 3000) } onMount(() => { - incrementCurrentImageIndex() + if (images.length > 1) { + incrementCurrentImageIndex() + } return () => { // Clear rotating words timeout - clearTimeout(imagesLoop) + if (imagesLoop) { + clearTimeout(imagesLoop) + } } }) @@ -46,9 +61,9 @@