Optimize some components
All checks were successful
continuous-integration/drone/push Build is passing

- Use binding of this over `document.querySelector` calls
- Use else if over a chained else and if condition
This commit is contained in:
2020-03-29 19:49:01 +02:00
parent 02974aa00c
commit 59f287af2b
3 changed files with 12 additions and 12 deletions

View File

@@ -6,12 +6,14 @@
export let className = null export let className = null
// Variables // Variables
let counter
const numbers = [...Array(10).keys()]
// Reactive variables depending on currentIndex
$: actualIndex = currentIndex + 1 $: actualIndex = currentIndex + 1
$: amount = String(actualIndex).length $: amount = String(actualIndex).length
$: index = (actualIndex < 10) ? String(actualIndex).padStart(2, '0') : String(actualIndex) $: index = (actualIndex < 10) ? String(actualIndex).padStart(2, '0') : String(actualIndex)
$: digits = index.split('') $: digits = index.split('')
let counter
const numbers = [...Array(10).keys()]
/* /*

View File

@@ -2,6 +2,7 @@
import { onMount } from 'svelte' import { onMount } from 'svelte'
// Variables // Variables
let toggleEl
let toggleLayout let toggleLayout
let layoutSetting let layoutSetting
@@ -17,17 +18,16 @@
const layoutGridClass = 'photos--grid' const layoutGridClass = 'photos--grid'
const layoutListClass = 'photos--list' const layoutListClass = 'photos--list'
const grid = document.querySelector('.photos') const grid = document.querySelector('.photos')
const toggle = document.querySelector('.toggle') const pill = toggleEl.querySelector('.pill')
const pill = toggle.querySelector('.pill')
// Change active pill // Change active pill
const toggleAnimate = (elem, pill, toggle) => { const toggleAnimate = (elem, pill, toggle) => {
pill.style.width = Math.round(elem.getBoundingClientRect().width) + 'px' pill.style.width = Math.round(elem.getBoundingClientRect().width) + 'px'
pill.style.left = Math.round(elem.getBoundingClientRect().left - toggle.getBoundingClientRect().left) + 'px' pill.style.left = Math.round(elem.getBoundingClientRect().left - toggleEl.getBoundingClientRect().left) + 'px'
} }
// Init of first option // Init of first option
toggleAnimate(document.querySelector(`.toggle [data-layout="${layoutSetting}"]`), pill, toggle) toggleAnimate(toggleEl.querySelector(`[data-layout="${layoutSetting}"]`), pill, toggleEl)
// Toggle layout // Toggle layout
toggleLayout = event => { toggleLayout = event => {
@@ -48,10 +48,10 @@
} }
// Animate the active pill // Animate the active pill
toggleAnimate(clicked, pill, toggle) toggleAnimate(clicked, pill, toggleEl)
// Add/Remove active classes // Add/Remove active classes
document.querySelectorAll('.toggle button').forEach(button => button.classList.remove('active')) toggleEl.querySelectorAll('button').forEach(button => button.classList.remove('active'))
clicked.classList.add('active') clicked.classList.add('active')
// Remember this setting // Remember this setting
@@ -60,7 +60,7 @@
}) })
</script> </script>
<div class="toggle"> <div class="toggle" bind:this={toggleEl}>
<button data-layout="list" class:active={layoutSetting === 'list'} on:click={toggleLayout}> <button data-layout="list" class:active={layoutSetting === 'list'} on:click={toggleLayout}>
<svg xmlns="http://www.w3.org/2000/svg" width="19" height="17" viewBox="0 0 19 17"> <svg xmlns="http://www.w3.org/2000/svg" width="19" height="17" viewBox="0 0 19 17">
<g class="anim"> <g class="anim">

View File

@@ -54,12 +54,10 @@
</div> </div>
<p class="pagination__caption style-caps">See more photos</p> <p class="pagination__caption style-caps">See more photos</p>
{:else} {:else if $currentLocation}
{#if $currentLocation}
<div class="pagination__message"> <div class="pagination__message">
<h3>That's all folks!</h3> <h3>That's all folks!</h3>
<p class="pagination__caption style-caps">Come back later to check out <br>new photos of {$currentLocation.name}</p> <p class="pagination__caption style-caps">Come back later to check out <br>new photos of {$currentLocation.name}</p>
</div> </div>
{/if} {/if}
{/if}
</section> </section>