mirror of
https://github.com/immich-app/immich.git
synced 2025-07-07 10:14:08 -04:00
chore: more flexible modal manager types (#19123)
* fix: required argument in onClose modal function * chore: more flexible modal manager types
This commit is contained in:
parent
5179c5badf
commit
22eef5f3c5
@ -36,7 +36,7 @@
|
|||||||
const handleSave = async (skipConfirm: boolean) => {
|
const handleSave = async (skipConfirm: boolean) => {
|
||||||
const allMethodsDisabled = !config.oauth.enabled && !config.passwordLogin.enabled;
|
const allMethodsDisabled = !config.oauth.enabled && !config.passwordLogin.enabled;
|
||||||
if (allMethodsDisabled && !skipConfirm) {
|
if (allMethodsDisabled && !skipConfirm) {
|
||||||
const isConfirmed = await modalManager.show(AuthDisableLoginConfirmModal, {});
|
const isConfirmed = await modalManager.show(AuthDisableLoginConfirmModal);
|
||||||
if (!isConfirmed) {
|
if (!isConfirmed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@
|
|||||||
if (document.fullscreenElement) {
|
if (document.fullscreenElement) {
|
||||||
await document.exitFullscreen();
|
await document.exitFullscreen();
|
||||||
}
|
}
|
||||||
await modalManager.show(SlideshowSettingsModal, {});
|
await modalManager.show(SlideshowSettingsModal);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
const { clearSelect, getOwnedAssets } = getAssetControlContext();
|
const { clearSelect, getOwnedAssets } = getAssetControlContext();
|
||||||
|
|
||||||
const handleUpdateDescription = async () => {
|
const handleUpdateDescription = async () => {
|
||||||
const description = await modalManager.show(AssetUpdateDecriptionConfirmModal, {});
|
const description = await modalManager.show(AssetUpdateDecriptionConfirmModal);
|
||||||
if (description) {
|
if (description) {
|
||||||
const ids = getSelectedAssets(getOwnedAssets(), $user);
|
const ids = getSelectedAssets(getOwnedAssets(), $user);
|
||||||
|
|
||||||
|
@ -703,7 +703,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
isShortcutModalOpen = true;
|
isShortcutModalOpen = true;
|
||||||
await modalManager.show(ShortcutsModal, {});
|
await modalManager.show(ShortcutsModal);
|
||||||
isShortcutModalOpen = false;
|
isShortcutModalOpen = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,11 +5,10 @@
|
|||||||
import Thumbnail from '$lib/components/assets/thumbnail/thumbnail.svelte';
|
import Thumbnail from '$lib/components/assets/thumbnail/thumbnail.svelte';
|
||||||
import { AppRoute, AssetAction } from '$lib/constants';
|
import { AppRoute, AssetAction } from '$lib/constants';
|
||||||
import { modalManager } from '$lib/managers/modal-manager.svelte';
|
import { modalManager } from '$lib/managers/modal-manager.svelte';
|
||||||
|
import type { TimelineAsset, Viewport } from '$lib/managers/timeline-manager/types';
|
||||||
import ShortcutsModal from '$lib/modals/ShortcutsModal.svelte';
|
import ShortcutsModal from '$lib/modals/ShortcutsModal.svelte';
|
||||||
import type { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
|
import type { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
|
||||||
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
|
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
|
||||||
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
|
|
||||||
import type { Viewport } from '$lib/managers/timeline-manager/types';
|
|
||||||
import { showDeleteModal } from '$lib/stores/preferences.store';
|
import { showDeleteModal } from '$lib/stores/preferences.store';
|
||||||
import { featureFlags } from '$lib/stores/server-config.store';
|
import { featureFlags } from '$lib/stores/server-config.store';
|
||||||
import { handlePromiseError } from '$lib/utils';
|
import { handlePromiseError } from '$lib/utils';
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
shape="round"
|
shape="round"
|
||||||
onclick={async () => {
|
onclick={async () => {
|
||||||
onClose();
|
onClose();
|
||||||
await modalManager.show(AvatarEditModal, {});
|
await modalManager.show(AvatarEditModal);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
const { isPurchased } = purchaseStore;
|
const { isPurchased } = purchaseStore;
|
||||||
|
|
||||||
const openPurchaseModal = async () => {
|
const openPurchaseModal = async () => {
|
||||||
await modalManager.show(PurchaseModal, {});
|
await modalManager.show(PurchaseModal);
|
||||||
showMessage = false;
|
showMessage = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,15 +6,21 @@ type OnCloseData<T> = T extends { onClose: (data?: infer R) => void }
|
|||||||
: T extends { onClose: (data: infer R) => void }
|
: T extends { onClose: (data: infer R) => void }
|
||||||
? R
|
? R
|
||||||
: never;
|
: never;
|
||||||
type ExtendsEmptyObject<T> = keyof T extends never ? Record<string, never> : T;
|
type ExtendsEmptyObject<T> = keyof T extends never ? never : T;
|
||||||
type StripValueIfOptional<T> = T extends undefined ? undefined : T;
|
type StripValueIfOptional<T> = T extends undefined ? undefined : T;
|
||||||
|
|
||||||
|
// if the modal does not expect any props, makes the props param optional but also allows passing `{}` and `undefined`
|
||||||
|
type OptionalParamIfEmpty<T> = ExtendsEmptyObject<T> extends never ? [] | [Record<string, never> | undefined] : [T];
|
||||||
|
|
||||||
class ModalManager {
|
class ModalManager {
|
||||||
show<T extends object>(Component: Component<T>, props: ExtendsEmptyObject<Omit<T, 'onClose'>>) {
|
show<T extends object>(Component: Component<T>, ...props: OptionalParamIfEmpty<Omit<T, 'onClose'>>) {
|
||||||
return this.open(Component, props).onClose;
|
return this.open(Component, ...props).onClose;
|
||||||
}
|
}
|
||||||
|
|
||||||
open<T extends object, K = OnCloseData<T>>(Component: Component<T>, props: ExtendsEmptyObject<Omit<T, 'onClose'>>) {
|
open<T extends object, K = OnCloseData<T>>(
|
||||||
|
Component: Component<T>,
|
||||||
|
...props: OptionalParamIfEmpty<Omit<T, 'onClose'>>
|
||||||
|
) {
|
||||||
let modal: object = {};
|
let modal: object = {};
|
||||||
let onClose: (...args: [StripValueIfOptional<K>]) => Promise<void>;
|
let onClose: (...args: [StripValueIfOptional<K>]) => Promise<void>;
|
||||||
|
|
||||||
@ -27,7 +33,7 @@ class ModalManager {
|
|||||||
modal = mount(Component, {
|
modal = mount(Component, {
|
||||||
target: document.body,
|
target: document.body,
|
||||||
props: {
|
props: {
|
||||||
...(props as T),
|
...((props?.[0] ?? {}) as T),
|
||||||
onClose,
|
onClose,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -200,7 +200,7 @@
|
|||||||
icon={mdiInformationOutline}
|
icon={mdiInformationOutline}
|
||||||
aria-label={$t('deduplication_info')}
|
aria-label={$t('deduplication_info')}
|
||||||
size="small"
|
size="small"
|
||||||
onclick={() => modalManager.show(DuplicatesInformationModal, {})}
|
onclick={() => modalManager.show(DuplicatesInformationModal)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onCreateNewLibraryClicked = async () => {
|
const onCreateNewLibraryClicked = async () => {
|
||||||
const result = await modalManager.show(LibraryUserPickerModal, {});
|
const result = await modalManager.show(LibraryUserPickerModal);
|
||||||
if (result) {
|
if (result) {
|
||||||
await handleCreate(result);
|
await handleCreate(result);
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleCreate = async () => {
|
const handleCreate = async () => {
|
||||||
await modalManager.show(UserCreateModal, {});
|
await modalManager.show(UserCreateModal);
|
||||||
await refresh();
|
await refresh();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user