mirror of
https://github.com/immich-app/immich.git
synced 2025-11-24 23:40:45 +09:00
refactor: dialog controller (#18235)
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { dialogController } from './dialog';
|
||||
import ConfirmDialog from '$lib/components/shared-components/dialog/confirm-dialog.svelte';
|
||||
const { dialog } = dialogController;
|
||||
</script>
|
||||
|
||||
{#if $dialog}
|
||||
<ConfirmDialog {...$dialog} />
|
||||
{/if}
|
||||
@@ -1,42 +0,0 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
type DialogActions = {
|
||||
onClose: (confirmed: boolean) => void;
|
||||
};
|
||||
|
||||
type DialogOptions = {
|
||||
title?: string;
|
||||
prompt?: string;
|
||||
confirmText?: string;
|
||||
cancelText?: string;
|
||||
hideCancelButton?: boolean;
|
||||
disable?: boolean;
|
||||
width?: 'wide' | 'narrow' | undefined;
|
||||
};
|
||||
|
||||
export type Dialog = DialogOptions & DialogActions;
|
||||
|
||||
function createDialogWrapper() {
|
||||
const dialog = writable<Dialog | undefined>();
|
||||
|
||||
async function show(options: DialogOptions) {
|
||||
return new Promise<boolean>((resolve) => {
|
||||
const newDialog: Dialog = {
|
||||
...options,
|
||||
onClose: (confirmed) => {
|
||||
dialog.set(undefined);
|
||||
resolve(confirmed);
|
||||
},
|
||||
};
|
||||
|
||||
dialog.set(newDialog);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
dialog,
|
||||
show,
|
||||
};
|
||||
}
|
||||
|
||||
export const dialogController = createDialogWrapper();
|
||||
Reference in New Issue
Block a user