From 48e4ea5231cc59de4b5a2a3e9daa6c8898d332e6 Mon Sep 17 00:00:00 2001 From: Manuel Taberna Date: Tue, 20 Jun 2023 16:36:38 +0200 Subject: [PATCH] feat(web): add zoom toggle icon (#2873) * feat(web): add zoom toggle icon * update zoom-image dependency * fix lint issues * remove variable testing line * Simplify code using ternary conditional Co-authored-by: Thomas <9749173+uhthomas@users.noreply.github.com> * fix typo --------- Co-authored-by: Thomas <9749173+uhthomas@users.noreply.github.com> --- web/src/app.d.ts | 1 + .../asset-viewer/asset-viewer-nav-bar.svelte | 18 +++++++++++++++++ .../asset-viewer/asset-viewer.svelte | 1 + .../asset-viewer/photo-viewer.svelte | 20 +++++++++++++++++-- .../buttons/circle-icon-button.svelte | 4 +++- web/src/lib/stores/zoom-image.store.ts | 4 ++++ 6 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 web/src/lib/stores/zoom-image.store.ts diff --git a/web/src/app.d.ts b/web/src/app.d.ts index a568cc816b..e6bff3ed83 100644 --- a/web/src/app.d.ts +++ b/web/src/app.d.ts @@ -29,5 +29,6 @@ declare namespace svelteHTML { // eslint-disable-next-line @typescript-eslint/no-unused-vars interface HTMLAttributes { 'on:copyImage'?: () => void; + 'on:zoomImage'?: () => void; } } diff --git a/web/src/lib/components/asset-viewer/asset-viewer-nav-bar.svelte b/web/src/lib/components/asset-viewer/asset-viewer-nav-bar.svelte index 302e6e3618..241ce2258c 100644 --- a/web/src/lib/components/asset-viewer/asset-viewer-nav-bar.svelte +++ b/web/src/lib/components/asset-viewer/asset-viewer-nav-bar.svelte @@ -11,14 +11,18 @@ import Heart from 'svelte-material-icons/Heart.svelte'; import HeartOutline from 'svelte-material-icons/HeartOutline.svelte'; import InformationOutline from 'svelte-material-icons/InformationOutline.svelte'; + import MagnifyPlusOutline from 'svelte-material-icons/MagnifyPlusOutline.svelte'; + import MagnifyMinusOutline from 'svelte-material-icons/MagnifyMinusOutline.svelte'; import MotionPauseOutline from 'svelte-material-icons/MotionPauseOutline.svelte'; import MotionPlayOutline from 'svelte-material-icons/MotionPlayOutline.svelte'; import CircleIconButton from '../elements/buttons/circle-icon-button.svelte'; import ContextMenu from '../shared-components/context-menu/context-menu.svelte'; import MenuOption from '../shared-components/context-menu/menu-option.svelte'; + import { photoZoomState } from '$lib/stores/zoom-image.store'; export let asset: AssetResponseDto; export let showCopyButton: boolean; + export let showZoomButton: boolean; export let showMotionPlayButton: boolean; export let isMotionPhotoPlaying = false; export let showDownloadButton: boolean; @@ -65,6 +69,20 @@ /> {/if} {/if} + {#if showZoomButton} + 1 + ? MagnifyMinusOutline + : MagnifyPlusOutline} + title="Zoom Image" + on:click={() => { + const zoomImage = new CustomEvent('zoomImage'); + window.dispatchEvent(zoomImage); + }} + /> + {/if} {#if showCopyButton} { + setZoomImageWheelState({ + currentZoom: $zoomImageWheelState.currentZoom === 1 ? 2 : 1 + }); + }; + + const { + createZoomImage: createZoomImageWheel, + zoomImageState: zoomImageWheelState, + setZoomImageState: setZoomImageWheelState + } = useZoomImageWheel(); + + zoomImageWheelState.subscribe((state) => { + photoZoomState.set(state); + }); + $: if (imgElement) { createZoomImageWheel(imgElement, { wheelZoomRatio: 0.06 @@ -81,7 +97,7 @@ } - +