enhance(client): 迷惑になる可能性のある投稿を行う前に警告を表示

Resolve #9862
This commit is contained in:
syuilo
2023-02-11 13:54:27 +09:00
parent 0138c3b00e
commit 73a1372940
5 changed files with 68 additions and 1 deletions

View File

@@ -186,6 +186,38 @@ export function confirm(props: {
});
}
// TODO: const T extends ... にしたい
// https://zenn.dev/general_link/articles/813e47b7a0eef7#const-type-parameters
export function actions<T extends {
value: string;
text: string;
primary?: boolean,
}[]>(props: {
type: 'error' | 'info' | 'success' | 'warning' | 'waiting' | 'question';
title?: string | null;
text?: string | null;
actions: T;
}): Promise<{ canceled: true; result: undefined; } | {
canceled: false; result: T[number]['value'];
}> {
return new Promise((resolve, reject) => {
popup(MkDialog, {
...props,
actions: props.actions.map(a => ({
text: a.text,
primary: a.primary,
callback: () => {
resolve({ canceled: false, result: a.value });
},
})),
}, {
done: result => {
resolve(result ? result : { canceled: true });
},
}, 'closed');
});
}
export function inputText(props: {
type?: 'text' | 'email' | 'password' | 'url';
title?: string | null;