From 7067876dc1a1397f8a6232c4b9a5a572eeb27e3b Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Tue, 25 Oct 2022 22:44:38 -0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20`os.yesno`=20for=20ye?= =?UTF-8?q?s/no=20questions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- packages/client/src/components/MkDialog.vue | 12 ++++++++++-- packages/client/src/os.ts | 18 ++++++++++++++++++ packages/client/src/pages/settings/profile.vue | 4 ++-- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 21d24a330..015306f40 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "calckey", - "version": "12.119.0-calc.4.2", + "version": "12.119.0-calc.4.3", "codename": "aqua", "repository": { "type": "git", diff --git a/packages/client/src/components/MkDialog.vue b/packages/client/src/components/MkDialog.vue index 155473cd7..e7867292a 100644 --- a/packages/client/src/components/MkDialog.vue +++ b/packages/client/src/components/MkDialog.vue @@ -28,8 +28,14 @@
- {{ (showCancelButton || input || select) ? i18n.ts.ok : i18n.ts.gotIt }} - {{ i18n.ts.cancel }} +
+ {{ (showCancelButton || input || select) ? i18n.ts.ok : i18n.ts.gotIt }} + {{ i18n.ts.cancel }} +
+
+ {{ (showCancelButton || input || select) ? i18n.ts.ok : i18n.ts.yes }} + {{ i18n.ts.no }} +
{{ action.text }} @@ -81,11 +87,13 @@ const props = withDefaults(defineProps<{ }[]; showOkButton?: boolean; showCancelButton?: boolean; + isYesNo?: boolean; cancelableByBgClick?: boolean; }>(), { type: 'info', showOkButton: true, showCancelButton: false, + isYesNo: false, cancelableByBgClick: true, }); diff --git a/packages/client/src/os.ts b/packages/client/src/os.ts index 6759a94e5..9cccab228 100644 --- a/packages/client/src/os.ts +++ b/packages/client/src/os.ts @@ -238,6 +238,24 @@ export function confirm(props: { }); } +export function yesno(props: { + type: 'error' | 'info' | 'success' | 'warning' | 'waiting' | 'question'; + title?: string | null; + text?: string | null; +}): Promise<{ canceled: boolean }> { + return new Promise((resolve, reject) => { + popup(defineAsyncComponent(() => import('@/components/MkDialog.vue')), { + ...props, + showCancelButton: true, + isYesNo: true, + }, { + done: result => { + resolve(result ? result : { canceled: true }); + }, + }, 'closed'); + }); +} + export function inputText(props: { type?: 'text' | 'email' | 'password' | 'url'; title?: string | null; diff --git a/packages/client/src/pages/settings/profile.vue b/packages/client/src/pages/settings/profile.vue index aaf60c8d5..db3c0fd72 100644 --- a/packages/client/src/pages/settings/profile.vue +++ b/packages/client/src/pages/settings/profile.vue @@ -130,7 +130,7 @@ function changeAvatar(ev) { selectFile(ev.currentTarget ?? ev.target, i18n.ts.avatar).then(async (file) => { let originalOrCropped = file; - const { canceled } = await os.confirm({ + const { canceled } = await os.yesno({ type: 'question', text: i18n.t('cropImageAsk'), }); @@ -153,7 +153,7 @@ function changeBanner(ev) { selectFile(ev.currentTarget ?? ev.target, i18n.ts.banner).then(async (file) => { let originalOrCropped = file; - const { canceled } = await os.confirm({ + const { canceled } = await os.yesno({ type: 'question', text: i18n.t('cropImageAsk'), });