|
|
|
@ -4,6 +4,9 @@ import Router from 'next/router'
|
|
|
|
|
import {FormController, IntegerInput, Button} from '~/components/form'
|
|
|
|
|
import isNum from 'validator/lib/isNumeric'
|
|
|
|
|
import {DateTime} from 'luxon'
|
|
|
|
|
import {Icon} from '@rmwc/icon'
|
|
|
|
|
|
|
|
|
|
import Modal from '~/components/modal'
|
|
|
|
|
|
|
|
|
|
import useCart, {useSetCart} from '~/hooks/useCart'
|
|
|
|
|
import styles from './style.module.css'
|
|
|
|
@ -24,13 +27,13 @@ Item.getInitialProps = async function({ctx: {axios, query: {slug}}}){
|
|
|
|
|
return {item}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Modal with full image size on clicking preview
|
|
|
|
|
export default function Item({item}){
|
|
|
|
|
const cart = useCart()
|
|
|
|
|
const setCart = useSetCart()
|
|
|
|
|
// Pick first one with featured flag or 0
|
|
|
|
|
const featuredIndex = item.images.reduce((p, im, i) => ((p !== undefined) ? p : (im.featured ? i : undefined)), undefined) || 0
|
|
|
|
|
const [selectedIndex, setSelected] = useState(featuredIndex);
|
|
|
|
|
const [imageModalVisible, setImageModalVisible] = useState(false);
|
|
|
|
|
|
|
|
|
|
const numInCart = cart?.items?.find(i => i.item.uuid === item.uuid)?.count || 0
|
|
|
|
|
|
|
|
|
@ -57,8 +60,8 @@ export default function Item({item}){
|
|
|
|
|
<div className={styles.imageContainer}>
|
|
|
|
|
<div className={styles.card}>
|
|
|
|
|
<picture>
|
|
|
|
|
<source srcset={`/api/images/${item.images[selectedIndex].uuid}/thumb.webp`} type="image/webp"/>
|
|
|
|
|
<img src={`/api/images/${item.images[selectedIndex].uuid}/thumb.png`} />
|
|
|
|
|
<source srcSet={`/api/images/${item.images[selectedIndex].uuid}/thumb.webp`} type="image/webp"/>
|
|
|
|
|
<img src={`/api/images/${item.images[selectedIndex].uuid}/thumb.png`} onClick={() => setImageModalVisible(true)} />
|
|
|
|
|
</picture>
|
|
|
|
|
</div>
|
|
|
|
|
{item.images && item.images.length > 1 &&
|
|
|
|
@ -75,6 +78,22 @@ export default function Item({item}){
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
<Modal title={`${item.name} (Image ${selectedIndex + 1})`} visible={imageModalVisible} onDeactivate={() => setImageModalVisible(false)}>
|
|
|
|
|
<div className={styles.imageCarousel}>
|
|
|
|
|
<button onClick={() => setSelected(index => (index - 1 < 0) ? item.images.length - 1 : index - 1)}>
|
|
|
|
|
<Icon icon="chevron_left" />
|
|
|
|
|
</button>
|
|
|
|
|
<div className={styles.fullImage}>
|
|
|
|
|
<picture>
|
|
|
|
|
<source srcSet={`/api/images/${item.images[selectedIndex].uuid}/large.webp`} type="image/webp"/>
|
|
|
|
|
<img src={`/api/images/${item.images[selectedIndex].uuid}/large.png`} onClick={() => setImageModalVisible(true)} />
|
|
|
|
|
</picture>
|
|
|
|
|
</div>
|
|
|
|
|
<button onClick={() => setSelected(index => (index + 1) % item.images.length)}>
|
|
|
|
|
<Icon icon="chevron_right" />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</Modal>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<div className={styles.controls}>
|
|
|
|
|