Files
jellyfin-web/src/components/confirm/confirm.ts
T
nielsvanvelzen af10633a7d Backport pull request #7259 from jellyfin-web/release-10.11.z
Avoid native browser alerts

Original-merge: 907947c523079451aa09712059de0a60f91516df

Merged-by: thornbill <thornbill@users.noreply.github.com>

Backported-by: Joshua M. Boniface <joshua@boniface.me>
2025-11-02 21:59:38 -05:00

56 lines
1.2 KiB
TypeScript

import dialog from 'components/dialog/dialog';
import { appRouter } from 'components/router/appRouter';
import globalize from 'lib/globalize';
interface OptionItem {
id: string,
name: string,
type: 'cancel' | 'delete' | 'submit'
}
interface ConfirmOptions {
title?: string,
text: string
cancelText?: string,
confirmText?: string,
primary?: string
buttons?: OptionItem[]
}
async function confirm(options: string | ConfirmOptions, title: string = '') {
if (typeof options === 'string') {
options = {
title,
text: options
};
}
const items: OptionItem[] = [];
items.push({
name: options.cancelText || globalize.translate('ButtonCancel'),
id: 'cancel',
type: 'cancel'
});
items.push({
name: options.confirmText || globalize.translate('ButtonOk'),
id: 'ok',
type: options.primary === 'delete' ? 'delete' : 'submit'
});
options.buttons = items;
await appRouter.ready();
return dialog.show(options).then(result => {
if (result === 'ok') {
return Promise.resolve();
}
return Promise.reject(new Error('Confirm dialog rejected'));
});
}
export default confirm;