|
|
|
@ -8,15 +8,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let isLoading = $state(true);
|
|
|
|
let isLoading = $state(true);
|
|
|
|
|
|
|
|
let imageUrl = $state(''); // La imagen que realmente se muestra
|
|
|
|
|
|
|
|
let hasError = $state(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Usamos el nombre del archivo como key. Svelte detectará el cambio automáticamente.
|
|
|
|
|
|
|
|
// No hace falta un contador manual si usamos el string del archivo.
|
|
|
|
|
|
|
|
let transitionKey = $state('');
|
|
|
|
|
|
|
|
|
|
|
|
$effect(() => {
|
|
|
|
$effect(() => {
|
|
|
|
// Las runas se leen automáticamente aquí
|
|
|
|
const targetImg = appState.currentFileName;
|
|
|
|
const currentImage = appState.currentFileName;
|
|
|
|
|
|
|
|
isLoading = false;
|
|
|
|
// Si ya estamos mostrando esta imagen, no hacemos nada (evita bucles)
|
|
|
|
|
|
|
|
if (imageUrl === targetImg) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isLoading = true;
|
|
|
|
|
|
|
|
hasError = false;
|
|
|
|
|
|
|
|
|
|
|
|
const img = new Image();
|
|
|
|
const img = new Image();
|
|
|
|
img.src = currentImage;
|
|
|
|
|
|
|
|
|
|
|
|
img.onload = () => {
|
|
|
|
|
|
|
|
imageUrl = targetImg; // Cambiamos la URL visible solo cuando ya cargó
|
|
|
|
|
|
|
|
transitionKey = targetImg; // Disparamos la transición
|
|
|
|
|
|
|
|
isLoading = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
img.onerror = () => {
|
|
|
|
|
|
|
|
console.error(`Error cargando: ${targetImg}`);
|
|
|
|
|
|
|
|
isLoading = false;
|
|
|
|
|
|
|
|
hasError = true;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
img.src = targetImg;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
@ -29,20 +51,35 @@
|
|
|
|
<!-- IMAGEN CENTRAL -->
|
|
|
|
<!-- IMAGEN CENTRAL -->
|
|
|
|
<div class="sticky top-1 z-10 flex-1 p-3 h-full bg-white shadow-lg lg:static flex lg:items-start justify-center overflow-hidden">
|
|
|
|
<div class="sticky top-1 z-10 flex-1 p-3 h-full bg-white shadow-lg lg:static flex lg:items-start justify-center overflow-hidden">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="relative w-full grid grid-cols-1 grid-rows-1 items-center justify-items-center">
|
|
|
|
|
|
|
|
|
|
|
|
{#if isLoading}
|
|
|
|
{#if isLoading}
|
|
|
|
<div class="absolute inset-0 flex items-center justify-center bg-gray-100">
|
|
|
|
<div
|
|
|
|
<svg class="animate-spin h-8 w-8 text-gray-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
|
|
|
class="col-start-1 row-start-1 z-20 flex items-center justify-center p-10 bg-white/50 backdrop-blur-sm rounded-xl"
|
|
|
|
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
|
|
|
transition:fade={{ duration: 200 }}
|
|
|
|
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v8H4z"></path>
|
|
|
|
>
|
|
|
|
</svg>
|
|
|
|
<div class="animate-spin rounded-full h-12 w-12 border-b-2 border-gray-900"></div>
|
|
|
|
|
|
|
|
<p class="ml-4 text-gray-600 font-medium">{ dataConfig.texts.loading_view || 'Cargando...' }</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
{/if}
|
|
|
|
<img
|
|
|
|
|
|
|
|
src={appState.currentFileName}
|
|
|
|
{#if hasError}
|
|
|
|
alt={`${dataConfig.texts?.['cview_alt_img'] ?? ''} ${appState.currentView?.name ?? ''}`}
|
|
|
|
<div class="col-start-1 row-start-1 z-20 text-center p-10 bg-red-50 rounded-lg">
|
|
|
|
class="w-full h-auto max-h-[90vh] object-contain"
|
|
|
|
<p class="text-red-600 text-lg mb-2">{ dataConfig.texts.errorLoadingImage || 'Error' }</p>
|
|
|
|
onload={ () => isLoading=false }
|
|
|
|
</div>
|
|
|
|
/>
|
|
|
|
{:else if imageUrl}
|
|
|
|
|
|
|
|
{#key transitionKey}
|
|
|
|
|
|
|
|
<img
|
|
|
|
|
|
|
|
src={imageUrl}
|
|
|
|
|
|
|
|
alt="Vista estancia"
|
|
|
|
|
|
|
|
class="col-start-1 row-start-1 w-full h-auto max-h-[90vh] object-contain shadow-sm"
|
|
|
|
|
|
|
|
transition:fade={{ duration: 500 }}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
{/key}
|
|
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|