Use Destructuring variables to avoid repetitions

- Easier to read and write
- Also fixes fullscreen when leaving the viewer, my bad
This commit is contained in:
2020-03-31 10:35:51 +02:00
parent 2dc51a167a
commit 5ac5d6803f
5 changed files with 46 additions and 42 deletions

View File

@@ -1,16 +1,19 @@
<script>
// Props
export let location
// Variables
const { name, slug, country } = location
</script>
<div class="location">
<a href="/location/{location.country.slug}/{location.slug}" rel="prefetch" sapper-noscroll>
<img src={location.country.flag.full_url} alt="Flag of {location.country.name}">
<a href="/location/{country.slug}/{slug}" rel="prefetch" sapper-noscroll>
<img src={country.flag.full_url} alt="Flag of {country.name}">
<div class="anim-mask mask-city">
<h3 class="location__city">{location.name}</h3>
<h3 class="location__city">{name}</h3>
</div>
<div class="anim-mask mask-country">
<p class="location__country style-caps">{location.country.name}</p>
<p class="location__country style-caps">{country.name}</p>
</div>
</a>
</div>

View File

@@ -17,8 +17,9 @@
const defaultHeight = Math.ceil(defaultWidth / 1.5)
// Reactive variables for location informations
const location = photo.location
const imgAlt = `${photo.name}, ${location.region}, ${location.country.name}`
const { name, date, location } = photo
const { private_hash } = photo.image
const imgAlt = `${name}, ${location.region}, ${location.country.name}`
const photoHref = `/viewer/${location.country.slug}/${location.slug}/${photo.slug}`
// Photo index
@@ -37,8 +38,8 @@
<div class="photo__location wrap">
<div class="wrapper">
<h2 class="title-location">
<span>{photo.name.split(', ')[0]},</span>
<span>{photo.name.split(', ')[1]}</span>
<span>{name.split(', ')[0]},</span>
<span>{name.split(', ')[1]}</span>
</h2>
<p class="style-caps">{location.region}, {location.country.name}</p>
</div>
@@ -49,28 +50,28 @@
<a href={photoHref} sapper-noscroll>
<picture class="photo__picture">
{#if layout === 'list'}
<source media="(min-width: 992px)" data-srcset={getThumbnail(photo.image.private_hash, 1300)}>
<source media="(min-width: 768px)" data-srcset={getThumbnail(photo.image.private_hash, 992)}>
<source media="(min-width: 500px)" data-srcset={getThumbnail(photo.image.private_hash, 650)}>
<source media="(min-width: 300px)" data-srcset={getThumbnail(photo.image.private_hash, 400)}>
<source media="(min-width: 992px)" srcset={getThumbnail(private_hash, 1300)}>
<source media="(min-width: 768px)" srcset={getThumbnail(private_hash, 992)}>
<source media="(min-width: 500px)" srcset={getThumbnail(private_hash, 650)}>
<source media="(min-width: 300px)" srcset={getThumbnail(private_hash, 400)}>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/+HRfwAJmQPS6gISLwAAAABJRU5ErkJggg=="
data-src="{getThumbnail(photo.image.private_hash, 900)}"
data-src="{getThumbnail(private_hash, 900)}"
alt={imgAlt}
width={defaultWidth} height={defaultHeight}
class="lazyload"
>
{:else}
<source media="(min-width: 992px)" srcset={getThumbnail(photo.image.private_hash, 1300)}>
<source media="(min-width: 768px)" srcset={getThumbnail(photo.image.private_hash, 992)}>
<source media="(min-width: 500px)" srcset={getThumbnail(photo.image.private_hash, 650)}>
<source media="(min-width: 300px)" srcset={getThumbnail(photo.image.private_hash, 400)}>
<img src="{getThumbnail(photo.image.private_hash, 900)}" alt={imgAlt} width={defaultWidth} height={defaultHeight}>
<source media="(min-width: 992px)" srcset={getThumbnail(private_hash, 1300)}>
<source media="(min-width: 768px)" srcset={getThumbnail(private_hash, 992)}>
<source media="(min-width: 500px)" srcset={getThumbnail(private_hash, 650)}>
<source media="(min-width: 300px)" srcset={getThumbnail(private_hash, 400)}>
<img src="{getThumbnail(private_hash, 900)}" alt={imgAlt} width={defaultWidth} height={defaultHeight}>
{/if}
</picture>
</a>
<time class="photo__date" datetime={formatDate(photo.date, 'DATETIME')}>
{formatDate(photo.date, 'FULL')}
<time class="photo__date" datetime={formatDate(date, 'DATETIME')}>
{formatDate(date, 'FULL')}
</time>
<div class="photo__number">
<span>{photoIndex}</span>

View File

@@ -8,7 +8,7 @@
export let type = ''
export let radius = 32
// Location variables
// Variables
let location
let locationName
let locationOf