mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 19:05:59 +01:00
chore(client/ts): port widgets/dialogs/confirm
This commit is contained in:
@@ -17,6 +17,7 @@ import { t, initLocale } from "../services/i18n.js";
|
||||
import NoteDetailWidget from "../widgets/note_detail.js";
|
||||
import { ResolveOptions } from "../widgets/dialogs/delete_notes.js";
|
||||
import { PromptDialogOptions } from "../widgets/dialogs/prompt.js";
|
||||
import { ConfirmWithMessageOptions } from "../widgets/dialogs/confirm.js";
|
||||
|
||||
interface Layout {
|
||||
getRootWidget: (appContext: AppContext) => RootWidget;
|
||||
@@ -34,7 +35,6 @@ export type TriggerData = {
|
||||
noteId?: string;
|
||||
noteIds?: string[];
|
||||
messages?: unknown[];
|
||||
callback?: () => void;
|
||||
} | {
|
||||
ntxId: string;
|
||||
notePath: string;
|
||||
@@ -50,7 +50,9 @@ export type TriggerData = {
|
||||
branchIdsToDelete: string[];
|
||||
callback: (value: ResolveOptions) => void;
|
||||
forceDeleteAllClones: boolean;
|
||||
} | PromptDialogOptions; // For "showPromptDialog"
|
||||
}
|
||||
| PromptDialogOptions // For "showPromptDialog"
|
||||
| ConfirmWithMessageOptions // For "showConfirmDialog"
|
||||
|
||||
class AppContext extends Component {
|
||||
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
import appContext from "../components/app_context.js";
|
||||
import { ConfirmDialogOptions, ConfirmWithMessageOptions } from "../widgets/dialogs/confirm.js";
|
||||
import { PromptDialogOptions } from "../widgets/dialogs/prompt.js";
|
||||
|
||||
async function info(message) {
|
||||
async function info(message: string) {
|
||||
return new Promise(res =>
|
||||
appContext.triggerCommand("showInfoDialog", {message, callback: res}));
|
||||
}
|
||||
|
||||
async function confirm(message) {
|
||||
async function confirm(message: string) {
|
||||
return new Promise(res =>
|
||||
appContext.triggerCommand("showConfirmDialog", {
|
||||
appContext.triggerCommand("showConfirmDialog", <ConfirmWithMessageOptions>{
|
||||
message,
|
||||
callback: x => res(x.confirmed)
|
||||
callback: (x: false | ConfirmDialogOptions) => res(x && x.confirmed)
|
||||
}));
|
||||
}
|
||||
|
||||
async function confirmDeleteNoteBoxWithNote(title) {
|
||||
async function confirmDeleteNoteBoxWithNote(title: string) {
|
||||
return new Promise(res =>
|
||||
appContext.triggerCommand("showConfirmDeleteNoteBoxWithNoteDialog", {title, callback: res}));
|
||||
}
|
||||
|
||||
async function prompt(props) {
|
||||
async function prompt(props: PromptDialogOptions) {
|
||||
return new Promise(res =>
|
||||
appContext.triggerCommand("showPromptDialog", {...props, callback: res}));
|
||||
}
|
||||
@@ -27,12 +27,16 @@ const TPL = `
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
export type ConfirmDialogCallback = (val: false | {
|
||||
type ConfirmDialogCallback = (val: false | ConfirmDialogOptions) => void;
|
||||
|
||||
export interface ConfirmDialogOptions {
|
||||
confirmed: boolean;
|
||||
isDeleteNoteChecked: boolean
|
||||
}) => void;
|
||||
}
|
||||
|
||||
interface ConfirmWithMessageOptions {
|
||||
// For "showConfirmDialog"
|
||||
|
||||
export interface ConfirmWithMessageOptions {
|
||||
message: string | HTMLElement | JQuery<HTMLElement>;
|
||||
callback: ConfirmDialogCallback;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user