From 1df7abfbb906f2e364b5eb5fefc5f9de5dd60026 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 18 Oct 2020 10:11:34 +0900 Subject: [PATCH] Improve waiting dialog --- src/client/components/page/page.post.vue | 12 ++--- .../{icon-dialog.vue => waiting-dialog.vue} | 50 +++++++++++++----- src/client/os.ts | 42 ++++++++++----- src/client/pages/follow.vue | 52 ++++--------------- src/client/pages/instance/emojis.vue | 19 ++----- src/client/pages/settings/import-export.vue | 20 +------ src/client/pages/test.vue | 15 ++++++ src/client/scripts/search.ts | 31 ++++------- 8 files changed, 110 insertions(+), 131 deletions(-) rename src/client/components/{icon-dialog.vue => waiting-dialog.vue} (53%) diff --git a/src/client/components/page/page.post.vue b/src/client/components/page/page.post.vue index e2b712667a..ac8be4a397 100644 --- a/src/client/components/page/page.post.vue +++ b/src/client/components/page/page.post.vue @@ -44,14 +44,7 @@ export default defineComponent({ }, methods: { upload() { - return new Promise((ok) => { - const dialog = os.dialog({ - type: 'waiting', - text: this.$t('uploading') + '...', - showOkButton: false, - showCancelButton: false, - cancelableByBgClick: false - }); + const promise = new Promise((ok) => { const canvas = this.hpml.canvases[this.value.canvasId]; canvas.toBlob(blob => { const data = new FormData(); @@ -67,11 +60,12 @@ export default defineComponent({ }) .then(response => response.json()) .then(f => { - dialog.close(); ok(f); }) }); }); + os.promiseDialog(promise); + return promise; }, async post() { this.posting = true; diff --git a/src/client/components/icon-dialog.vue b/src/client/components/waiting-dialog.vue similarity index 53% rename from src/client/components/icon-dialog.vue rename to src/client/components/waiting-dialog.vue index e8eae3342f..7e8ebeaec0 100644 --- a/src/client/components/icon-dialog.vue +++ b/src/client/components/waiting-dialog.vue @@ -1,8 +1,9 @@ @@ -18,12 +19,18 @@ export default defineComponent({ }, props: { - type: { - required: true + success: { + type: Boolean, + required: true, }, showing: { - required: true - } + type: Boolean, + required: true, + }, + text: { + type: String, + required: false, + }, }, emits: ['done', 'closed'], @@ -57,17 +64,32 @@ export default defineComponent({ text-align: center; background: var(--panel); border-radius: var(--radius); - width: initial; - font-size: 32px; + width: 250px; - &.success { - color: var(--accent); + &.iconOnly { + padding: 0; + width: 96px; + height: 96px; + + > .icon { + height: 100%; + } } - &.waiting { - > .icon { + > .icon { + font-size: 32px; + + &.success { + color: var(--accent); + } + + &.waiting { opacity: 0.7; } } + + > .text { + margin-top: 16px; + } } diff --git a/src/client/os.ts b/src/client/os.ts index 03bae65539..688bc136df 100644 --- a/src/client/os.ts +++ b/src/client/os.ts @@ -62,17 +62,34 @@ export function api(endpoint: string, data: Record = {}, token?: st return promise; } -export function apiWithDialog(endpoint: string, data: Record = {}, token?: string | null | undefined, onSuccess?: (res: any) => void, onFailure?: (e: Error) => void) { - const showing = ref(true); - const state = ref('waiting'); - +export function apiWithDialog( + endpoint: string, + data: Record = {}, + token?: string | null | undefined, + onSuccess?: (res: any) => void, + onFailure?: (e: Error) => void, +) { const promise = api(endpoint, data, token); + promiseDialog(promise, onSuccess, onFailure); + + return promise; +} + +export function promiseDialog>( + promise: T, + onSuccess?: (res: any) => void, + onFailure?: (e: Error) => void, + text?: string, +): T { + const showing = ref(true); + const success = ref(false); + promise.then(res => { if (onSuccess) { showing.value = false; onSuccess(res); } else { - state.value = 'success'; + success.value = true; setTimeout(() => { showing.value = false; }, 1000); @@ -89,9 +106,10 @@ export function apiWithDialog(endpoint: string, data: Record = {}, } }); - popup(defineAsyncComponent(() => import('@/components/icon-dialog.vue')), { - type: state, - showing: showing + popup(defineAsyncComponent(() => import('@/components/waiting-dialog.vue')), { + success: success, + showing: showing, + text: text, }, {}, 'closed'); return promise; @@ -161,8 +179,8 @@ export function success() { setTimeout(() => { showing.value = false; }, 1000); - popup(defineAsyncComponent(() => import('@/components/icon-dialog.vue')), { - type: 'success', + popup(defineAsyncComponent(() => import('@/components/waiting-dialog.vue')), { + success: true, showing: showing }, { done: () => resolve(), @@ -173,8 +191,8 @@ export function success() { export function waiting() { return new Promise((resolve, reject) => { const showing = ref(true); - popup(defineAsyncComponent(() => import('@/components/icon-dialog.vue')), { - type: 'waiting', + popup(defineAsyncComponent(() => import('@/components/waiting-dialog.vue')), { + success: false, showing: showing }, { done: () => resolve(), diff --git a/src/client/pages/follow.vue b/src/client/pages/follow.vue index 13e0a62a0d..b1ab7f9f6b 100644 --- a/src/client/pages/follow.vue +++ b/src/client/pages/follow.vue @@ -6,26 +6,20 @@