From 73a1372940050d2c8a240e2a22c080ee2175e013 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 11 Feb 2023 13:54:27 +0900 Subject: enhance(client): 迷惑になる可能性のある投稿を行う前に警告を表示 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolve #9862 --- packages/frontend/src/os.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'packages/frontend/src/os.ts') diff --git a/packages/frontend/src/os.ts b/packages/frontend/src/os.ts index 4997030669..639f4eaf17 100644 --- a/packages/frontend/src/os.ts +++ b/packages/frontend/src/os.ts @@ -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(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; -- cgit v1.2.3-freya