Skip to content

Commit

Permalink
Merge pull request #246 from seanmorley15/development
Browse files Browse the repository at this point in the history
Add larger image display on click
  • Loading branch information
seanmorley15 authored Aug 19, 2024
2 parents ad4c0b3 + 39fb4ad commit 45a9045
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
12 changes: 10 additions & 2 deletions frontend/src/lib/components/AdventureCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import CollectionLink from './CollectionLink.svelte';
import DotsHorizontal from '~icons/mdi/dots-horizontal';
import DeleteWarning from './DeleteWarning.svelte';
import ImageDisplayModal from './ImageDisplayModal.svelte';
export let type: string;
Expand All @@ -27,7 +28,7 @@
let isWarningModalOpen: boolean = false;
let keyword: string = '';
let image_url: string | null = null;
export let adventure: Adventure;
if (adventure.type == 'visited') {
Expand Down Expand Up @@ -155,6 +156,10 @@
/>
{/if}

{#if image_url}
<ImageDisplayModal image={image_url} on:close={() => (image_url = null)} {adventure} />
{/if}

<div
class="card w-full max-w-xs sm:max-w-sm md:max-w-md lg:max-w-md xl:max-w-md bg-primary-content shadow-xl text-base-content"
>
Expand All @@ -166,7 +171,10 @@
class="carousel-item w-full"
style="display: {i === currentSlide ? 'block' : 'none'}"
>
<img src={image.image} class="w-full h-48 object-cover" alt={adventure.name} />
<!-- svelte-ignore a11y-invalid-attribute -->
<a href="#" on:click={() => (image_url = image.image)}
><img src={image.image} class="w-full h-48 object-cover" alt={adventure.name} /></a
>
<div class="flex justify-center w-full py-2 gap-2">
{#each adventure.images as _, i}
<button
Expand Down
42 changes: 42 additions & 0 deletions frontend/src/lib/components/ImageDisplayModal.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
import { onMount } from 'svelte';
let modal: HTMLDialogElement;
import { appVersion, copyrightYear, versionChangelog } from '$lib/config';
import type { Adventure } from '$lib/types';
export let image: string;
export let adventure: Adventure;
onMount(() => {
modal = document.getElementById('my_modal_1') as HTMLDialogElement;
if (modal) {
modal.showModal();
}
});
function close() {
dispatch('close');
}
function handleKeydown(event: KeyboardEvent) {
if (event.key === 'Escape') {
dispatch('close');
}
}
</script>

<dialog id="my_modal_1" class="modal">
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
<div class="modal-box w-11/12 max-w-5xl" role="dialog" on:keydown={handleKeydown} tabindex="0">
<h3 class="font-bold mb-4 text-2xl">{adventure.name}</h3>

<div class="flex flex-col items-center">
<img src={image} alt={adventure.name} class="w-full h-full object-cover" />
</div>

<button class="btn mt-4 btn-primary" on:click={close}>Close</button>
</div>
</dialog>

0 comments on commit 45a9045

Please sign in to comment.