1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-16 16:56:46 +01:00

chore(web): move BaseModal to callback pattern (#8696)

* chore(web): move BaseModal to callback to close

* chore: add question mark
This commit is contained in:
Ben 2024-04-11 09:01:16 +00:00 committed by GitHub
parent 8c9a092561
commit 37eea2d353
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 37 additions and 45 deletions

View file

@ -442,7 +442,7 @@
{#if showShareByURLModal} {#if showShareByURLModal}
<CreateSharedLinkModal <CreateSharedLinkModal
albumId={albumToShare.id} albumId={albumToShare.id}
on:close={() => closeShareModal()} onClose={() => closeShareModal()}
on:created={() => albumToShare && handleSharedLinkCreated(albumToShare)} on:created={() => albumToShare && handleSharedLinkCreated(albumToShare)}
/> />
{:else} {:else}
@ -450,7 +450,7 @@
album={albumToShare} album={albumToShare}
on:select={({ detail: users }) => handleAddUsers(users)} on:select={({ detail: users }) => handleAddUsers(users)}
on:share={() => (showShareByURLModal = true)} on:share={() => (showShareByURLModal = true)}
on:close={() => closeShareModal()} onClose={() => closeShareModal()}
/> />
{/if} {/if}
{/if} {/if}

View file

@ -13,10 +13,10 @@
import UserAvatar from '../shared-components/user-avatar.svelte'; import UserAvatar from '../shared-components/user-avatar.svelte';
export let album: AlbumResponseDto; export let album: AlbumResponseDto;
export let onClose: () => void;
const dispatch = createEventDispatcher<{ const dispatch = createEventDispatcher<{
remove: string; remove: string;
close: void;
}>(); }>();
let currentUser: UserResponseDto; let currentUser: UserResponseDto;
@ -66,7 +66,7 @@
</script> </script>
{#if !selectedRemoveUser} {#if !selectedRemoveUser}
<BaseModal id="share-info-modal" title="Options" on:close> <BaseModal id="share-info-modal" title="Options" {onClose}>
<section class="immich-scrollbar max-h-[400px] overflow-y-auto pb-4"> <section class="immich-scrollbar max-h-[400px] overflow-y-auto pb-4">
<div class="flex w-full place-items-center justify-between gap-4 p-5"> <div class="flex w-full place-items-center justify-between gap-4 p-5">
<div class="flex place-items-center gap-4"> <div class="flex place-items-center gap-4">
@ -134,7 +134,7 @@
<ConfirmDialogue <ConfirmDialogue
id="remove-user-modal" id="remove-user-modal"
title="Remove user?" title="Remove user?"
prompt="Are you sure you want to remove {selectedRemoveUser.name}" prompt="Are you sure you want to remove {selectedRemoveUser.name}?"
confirmText="Remove" confirmText="Remove"
onConfirm={handleRemoveUser} onConfirm={handleRemoveUser}
onClose={() => (selectedRemoveUser = null)} onClose={() => (selectedRemoveUser = null)}

View file

@ -16,13 +16,13 @@
import UserAvatar from '../shared-components/user-avatar.svelte'; import UserAvatar from '../shared-components/user-avatar.svelte';
export let album: AlbumResponseDto; export let album: AlbumResponseDto;
export let onClose: () => void;
let users: UserResponseDto[] = []; let users: UserResponseDto[] = [];
let selectedUsers: UserResponseDto[] = []; let selectedUsers: UserResponseDto[] = [];
const dispatch = createEventDispatcher<{ const dispatch = createEventDispatcher<{
select: UserResponseDto[]; select: UserResponseDto[];
share: void; share: void;
close: void;
}>(); }>();
let sharedLinks: SharedLinkResponseDto[] = []; let sharedLinks: SharedLinkResponseDto[] = [];
onMount(async () => { onMount(async () => {
@ -54,7 +54,7 @@
}; };
</script> </script>
<BaseModal id="user-selection-modal" title="Invite to album" showLogo on:close> <BaseModal id="user-selection-modal" title="Invite to album" showLogo {onClose}>
{#if selectedUsers.length > 0} {#if selectedUsers.length > 0}
<div class="mb-2 flex flex-wrap place-items-center gap-4 overflow-x-auto px-5 py-2 sticky"> <div class="mb-2 flex flex-wrap place-items-center gap-4 overflow-x-auto px-5 py-2 sticky">
<p class="font-medium">To</p> <p class="font-medium">To</p>

View file

@ -756,7 +756,7 @@
shared={addToSharedAlbum} shared={addToSharedAlbum}
on:newAlbum={({ detail }) => handleAddToNewAlbum(detail)} on:newAlbum={({ detail }) => handleAddToNewAlbum(detail)}
on:album={({ detail }) => handleAddToAlbum(detail)} on:album={({ detail }) => handleAddToAlbum(detail)}
on:close={() => (isShowAlbumPicker = false)} onClose={() => (isShowAlbumPicker = false)}
/> />
{/if} {/if}
@ -770,11 +770,11 @@
{/if} {/if}
{#if isShowProfileImageCrop} {#if isShowProfileImageCrop}
<ProfileImageCropper {asset} on:close={() => (isShowProfileImageCrop = false)} /> <ProfileImageCropper {asset} onClose={() => (isShowProfileImageCrop = false)} />
{/if} {/if}
{#if isShowShareModal} {#if isShowShareModal}
<CreateSharedLinkModal assetIds={[asset.id]} on:close={() => (isShowShareModal = false)} /> <CreateSharedLinkModal assetIds={[asset.id]} onClose={() => (isShowShareModal = false)} />
{/if} {/if}
</section> </section>
</FocusTrap> </FocusTrap>

View file

@ -46,6 +46,6 @@
{shared} {shared}
on:newAlbum={({ detail }) => handleAddToNewAlbum(detail)} on:newAlbum={({ detail }) => handleAddToNewAlbum(detail)}
on:album={({ detail }) => handleAddToAlbum(detail)} on:album={({ detail }) => handleAddToAlbum(detail)}
on:close={handleHideAlbumPicker} onClose={handleHideAlbumPicker}
/> />
{/if} {/if}

View file

@ -11,5 +11,5 @@
<CircleIconButton title="Share" icon={mdiShareVariantOutline} on:click={() => (showModal = true)} /> <CircleIconButton title="Share" icon={mdiShareVariantOutline} on:click={() => (showModal = true)} />
{#if showModal} {#if showModal}
<CreateSharedLinkModal assetIds={[...getAssets()].map(({ id }) => id)} on:close={() => (showModal = false)} /> <CreateSharedLinkModal assetIds={[...getAssets()].map(({ id }) => id)} onClose={() => (showModal = false)} />
{/if} {/if}

View file

@ -16,10 +16,10 @@
const dispatch = createEventDispatcher<{ const dispatch = createEventDispatcher<{
newAlbum: string; newAlbum: string;
album: AlbumResponseDto; album: AlbumResponseDto;
close: void;
}>(); }>();
export let shared: boolean; export let shared: boolean;
export let onClose: () => void;
onMount(async () => { onMount(async () => {
albums = await getAllAlbums({ shared: shared || undefined }); albums = await getAllAlbums({ shared: shared || undefined });
@ -52,7 +52,7 @@
}; };
</script> </script>
<BaseModal id="album-selection-modal" title={getTitle()} on:close> <BaseModal id="album-selection-modal" title={getTitle()} {onClose}>
<div class="mb-2 flex max-h-[400px] flex-col"> <div class="mb-2 flex max-h-[400px] flex-col">
{#if loading} {#if loading}
{#each { length: 3 } as _} {#each { length: 3 } as _}

View file

@ -1,20 +1,18 @@
<script lang="ts"> <script lang="ts">
import { fade } from 'svelte/transition'; import { fade } from 'svelte/transition';
import { quintOut } from 'svelte/easing'; import { quintOut } from 'svelte/easing';
import { createEventDispatcher, onMount, onDestroy } from 'svelte'; import { onMount, onDestroy } from 'svelte';
import { browser } from '$app/environment'; import { browser } from '$app/environment';
import { clickOutside } from '$lib/utils/click-outside'; import { clickOutside } from '$lib/utils/click-outside';
import FocusTrap from '$lib/components/shared-components/focus-trap.svelte'; import FocusTrap from '$lib/components/shared-components/focus-trap.svelte';
import ModalHeader from '$lib/components/shared-components/modal-header.svelte'; import ModalHeader from '$lib/components/shared-components/modal-header.svelte';
const dispatch = createEventDispatcher<{
close: void;
}>();
/** /**
* Unique identifier for the modal. * Unique identifier for the modal.
*/ */
export let id: string; export let id: string;
export let title: string; export let title: string;
export let onClose: () => void;
export let zIndex = 9999; export let zIndex = 9999;
/** /**
* If true, the logo will be displayed next to the modal title. * If true, the logo will be displayed next to the modal title.
@ -57,14 +55,14 @@
> >
<div <div
use:clickOutside={{ use:clickOutside={{
onOutclick: () => dispatch('close'), onOutclick: onClose,
onEscape: () => dispatch('close'), onEscape: onClose,
}} }}
class="min-h-[200px] w-[450px] overflow-y-auto rounded-3xl bg-immich-bg shadow-md dark:bg-immich-dark-gray dark:text-immich-dark-fg immich-scrollbar scroll-pb-20" class="min-h-[200px] w-[450px] overflow-y-auto rounded-3xl bg-immich-bg shadow-md dark:bg-immich-dark-gray dark:text-immich-dark-fg immich-scrollbar scroll-pb-20"
style="max-height: min(95vh, 800px);" style="max-height: min(95vh, 800px);"
tabindex="-1" tabindex="-1"
> >
<ModalHeader id={titleId} {title} {showLogo} {icon} on:close /> <ModalHeader id={titleId} {title} {showLogo} {icon} {onClose} />
<div> <div>
<slot /> <slot />

View file

@ -15,6 +15,7 @@
import SettingInputField, { SettingInputFieldType } from '../settings/setting-input-field.svelte'; import SettingInputField, { SettingInputFieldType } from '../settings/setting-input-field.svelte';
import SettingSwitch from '../settings/setting-switch.svelte'; import SettingSwitch from '../settings/setting-switch.svelte';
export let onClose: () => void;
export let albumId: string | undefined = undefined; export let albumId: string | undefined = undefined;
export let assetIds: string[] = []; export let assetIds: string[] = [];
export let editingLink: SharedLinkResponseDto | undefined = undefined; export let editingLink: SharedLinkResponseDto | undefined = undefined;
@ -30,8 +31,6 @@
let enablePassword = false; let enablePassword = false;
const dispatch = createEventDispatcher<{ const dispatch = createEventDispatcher<{
close: void;
escape: void;
created: void; created: void;
}>(); }>();
@ -146,7 +145,7 @@
message: 'Edited', message: 'Edited',
}); });
dispatch('close'); onClose();
} catch (error) { } catch (error) {
handleError(error, 'Failed to edit shared link'); handleError(error, 'Failed to edit shared link');
} }
@ -160,7 +159,7 @@
}; };
</script> </script>
<BaseModal id="create-shared-link-modal" title={getTitle()} icon={mdiLink} on:close> <BaseModal id="create-shared-link-modal" title={getTitle()} icon={mdiLink} {onClose}>
<section class="mx-6 mb-6"> <section class="mx-6 mb-6">
{#if shareType === SharedLinkType.Album} {#if shareType === SharedLinkType.Album}
{#if !editingLink} {#if !editingLink}

View file

@ -55,7 +55,7 @@
aria-modal="true" aria-modal="true"
aria-labelledby={titleId} aria-labelledby={titleId}
> >
<ModalHeader id={titleId} {title} {showLogo} {icon} on:close={() => onClose?.()} /> <ModalHeader id={titleId} {title} {showLogo} {icon} {onClose} />
<div class="p-5 pt-0"> <div class="p-5 pt-0">
<slot /> <slot />
</div> </div>

View file

@ -2,18 +2,14 @@
import ImmichLogo from '$lib/components/shared-components/immich-logo.svelte'; import ImmichLogo from '$lib/components/shared-components/immich-logo.svelte';
import Icon from '$lib/components/elements/icon.svelte'; import Icon from '$lib/components/elements/icon.svelte';
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte'; import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
import { createEventDispatcher } from 'svelte';
import { mdiClose } from '@mdi/js'; import { mdiClose } from '@mdi/js';
const dispatch = createEventDispatcher<{
close: void;
}>();
/** /**
* Unique identifier for the header text. * Unique identifier for the header text.
*/ */
export let id: string; export let id: string;
export let title: string; export let title: string;
export let onClose: () => void;
/** /**
* If true, the logo will be displayed next to the modal title. * If true, the logo will be displayed next to the modal title.
*/ */
@ -36,5 +32,5 @@
</h1> </h1>
</div> </div>
<CircleIconButton on:click={() => dispatch('close')} icon={mdiClose} size={'20'} title="Close" /> <CircleIconButton on:click={onClose} icon={mdiClose} size={'20'} title="Close" />
</div> </div>

View file

@ -3,17 +3,15 @@
import { handleError } from '$lib/utils/handle-error'; import { handleError } from '$lib/utils/handle-error';
import { createProfileImage, type AssetResponseDto } from '@immich/sdk'; import { createProfileImage, type AssetResponseDto } from '@immich/sdk';
import domtoimage from 'dom-to-image'; import domtoimage from 'dom-to-image';
import { createEventDispatcher, onMount } from 'svelte'; import { onMount } from 'svelte';
import PhotoViewer from '../asset-viewer/photo-viewer.svelte'; import PhotoViewer from '../asset-viewer/photo-viewer.svelte';
import Button from '../elements/buttons/button.svelte'; import Button from '../elements/buttons/button.svelte';
import BaseModal from './base-modal.svelte'; import BaseModal from './base-modal.svelte';
import { NotificationType, notificationController } from './notification/notification'; import { NotificationType, notificationController } from './notification/notification';
export let asset: AssetResponseDto; export let asset: AssetResponseDto;
export let onClose: () => void;
const dispatch = createEventDispatcher<{
close: void;
}>();
let imgElement: HTMLDivElement; let imgElement: HTMLDivElement;
onMount(() => { onMount(() => {
@ -67,11 +65,11 @@
} catch (error) { } catch (error) {
handleError(error, 'Error setting profile picture.'); handleError(error, 'Error setting profile picture.');
} }
dispatch('close'); onClose();
}; };
</script> </script>
<BaseModal id="profile-image-cropper" title="Set profile picture" on:close> <BaseModal id="profile-image-cropper" title="Set profile picture" {onClose}>
<div class="flex place-items-center items-center justify-center"> <div class="flex place-items-center items-center justify-center">
<div <div
class="relative flex aspect-square w-1/2 overflow-hidden rounded-full border-4 border-immich-primary bg-immich-dark-primary dark:border-immich-dark-primary dark:bg-immich-primary" class="relative flex aspect-square w-1/2 overflow-hidden rounded-full border-4 border-immich-primary bg-immich-dark-primary dark:border-immich-dark-primary dark:bg-immich-primary"

View file

@ -6,11 +6,12 @@
import UserAvatar from '../shared-components/user-avatar.svelte'; import UserAvatar from '../shared-components/user-avatar.svelte';
export let user: UserResponseDto; export let user: UserResponseDto;
export let onClose: () => void;
let availableUsers: UserResponseDto[] = []; let availableUsers: UserResponseDto[] = [];
let selectedUsers: UserResponseDto[] = []; let selectedUsers: UserResponseDto[] = [];
const dispatch = createEventDispatcher<{ close: void; 'add-users': UserResponseDto[] }>(); const dispatch = createEventDispatcher<{ 'add-users': UserResponseDto[] }>();
onMount(async () => { onMount(async () => {
// TODO: update endpoint to have a query param for deleted users // TODO: update endpoint to have a query param for deleted users
@ -32,7 +33,7 @@
}; };
</script> </script>
<BaseModal id="partner-selection-modal" title="Add partner" showLogo on:close> <BaseModal id="partner-selection-modal" title="Add partner" showLogo {onClose}>
<div class="immich-scrollbar max-h-[300px] overflow-y-auto"> <div class="immich-scrollbar max-h-[300px] overflow-y-auto">
{#if availableUsers.length > 0} {#if availableUsers.length > 0}
{#each availableUsers as user} {#each availableUsers as user}

View file

@ -182,7 +182,7 @@
{#if createPartnerFlag} {#if createPartnerFlag}
<PartnerSelectionModal <PartnerSelectionModal
{user} {user}
on:close={() => (createPartnerFlag = false)} onClose={() => (createPartnerFlag = false)}
on:add-users={(event) => handleCreatePartners(event.detail)} on:add-users={(event) => handleCreatePartners(event.detail)}
/> />
{/if} {/if}

View file

@ -665,17 +665,17 @@
{album} {album}
on:select={({ detail: users }) => handleAddUsers(users)} on:select={({ detail: users }) => handleAddUsers(users)}
on:share={() => (viewMode = ViewMode.LINK_SHARING)} on:share={() => (viewMode = ViewMode.LINK_SHARING)}
on:close={() => (viewMode = ViewMode.VIEW)} onClose={() => (viewMode = ViewMode.VIEW)}
/> />
{/if} {/if}
{#if viewMode === ViewMode.LINK_SHARING} {#if viewMode === ViewMode.LINK_SHARING}
<CreateSharedLinkModal albumId={album.id} on:close={() => (viewMode = ViewMode.VIEW)} /> <CreateSharedLinkModal albumId={album.id} onClose={() => (viewMode = ViewMode.VIEW)} />
{/if} {/if}
{#if viewMode === ViewMode.VIEW_USERS} {#if viewMode === ViewMode.VIEW_USERS}
<ShareInfoModal <ShareInfoModal
on:close={() => (viewMode = ViewMode.VIEW)} onClose={() => (viewMode = ViewMode.VIEW)}
{album} {album}
on:remove={({ detail: userId }) => handleRemoveUser(userId)} on:remove={({ detail: userId }) => handleRemoveUser(userId)}
/> />

View file

@ -83,7 +83,7 @@
</section> </section>
{#if editSharedLink} {#if editSharedLink}
<CreateSharedLinkModal editingLink={editSharedLink} on:close={handleEditDone} /> <CreateSharedLinkModal editingLink={editSharedLink} onClose={handleEditDone} />
{/if} {/if}
{#if deleteLinkId} {#if deleteLinkId}