-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added loading icon in gallery when opening images
- Loading branch information
Showing
3 changed files
with
56 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,70 @@ | ||
<script> | ||
import { onMount } from 'svelte'; | ||
import { fade } from "svelte/transition"; | ||
import { tag } from "../assets/ToggleStore.js"; | ||
export let image; | ||
export let thumbnail; | ||
let enabled = true; | ||
let expanded = false; | ||
function toggleExpansion() { | ||
expanded = !expanded; | ||
import { onMount } from 'svelte'; | ||
import { fade } from "svelte/transition"; | ||
import { tag } from "../assets/ToggleStore.js"; | ||
export let image; | ||
export let thumbnail; | ||
let enabled = true; | ||
let expanded = false; | ||
let loaded = false; // Variable para controlar el estado de carga | ||
function toggleExpansion() { | ||
expanded = !expanded; | ||
if (expanded && !loaded) { | ||
loadImage(); | ||
} | ||
onMount(() => { | ||
tag.subscribe(value => { | ||
enabled = false; | ||
// wait 1 frame for the DOM to update then update enabled with the correct value | ||
requestAnimationFrame(() => { | ||
enabled = value == "All" || image.tags.includes(value.toLowerCase()); | ||
}); | ||
} | ||
onMount(() => { | ||
tag.subscribe(value => { | ||
enabled = false; | ||
requestAnimationFrame(() => { | ||
enabled = value == "All" || image.tags.includes(value.toLowerCase()); | ||
}); | ||
}); | ||
}); | ||
function escape(event) { | ||
if (event.key === 'Escape') { | ||
expanded = false; | ||
} | ||
function escape(event) { | ||
if (event.key === 'Escape') { | ||
expanded = false; | ||
} | ||
</script> | ||
|
||
<svelte:window on:keydown="{escape}" /> | ||
} | ||
function loadImage() { | ||
console.log("Loading image") | ||
const img = new Image(); | ||
img.src = image.src; | ||
img.onload = () => { | ||
loaded = true; | ||
}; | ||
} | ||
</script> | ||
|
||
<svelte:window on:keydown="{escape}" /> | ||
|
||
{#if enabled} | ||
{#if enabled} | ||
<li class="lg:h-[25vh] h-[20vw] flex-grow m-2" in:fade="{{duration: 400}}"> | ||
<img | ||
class="max-h-full min-w-full object-cover align-bottom rounded-xl" | ||
src="{thumbnail.src}" | ||
alt="{thumbnail.title}" | ||
loading="lazy" | ||
on:click="{toggleExpansion}" | ||
on:keydown | ||
on:click={toggleExpansion} /> | ||
/> | ||
|
||
{#if expanded} | ||
<div class="fixed top-0 left-0 right-0 bottom-0 flex items-center justify-center bg-black bg-opacity-75 z-10" transition:fade="{{ duration: 125 }}" on:click={toggleExpansion} on:keydown> | ||
<img class="max-w-[90vw] max-h-[90vh]" src="{image.src}" alt="{image.alt}" loading="lazy"> | ||
<div class="fixed top-0 left-0 right-0 bottom-0 flex items-center justify-center bg-black bg-opacity-75 z-10 backdrop-blur-sm" transition:fade="{{ duration: 125 }}" on:click="{toggleExpansion}" on:keydown> | ||
{#if !loaded} | ||
<div class="fixed top-0 left-0 right-0 bottom-0 z-10 flex flex-col items-center justify-center text-white animate-pulse" transition:fade> | ||
<img class="loading-image" alt="loading nahi"/> | ||
<span class="paragraph">Loading...</span> | ||
</div> | ||
{:else} | ||
<img class="max-w-[90vw] max-h-[90vh] z-50" in:fade src="{image.src}" alt="{image.alt}" loading="lazy"> | ||
{/if} | ||
</div> | ||
{/if} | ||
</li> | ||
{/if} | ||
</li> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters