From 1df7abfbb906f2e364b5eb5fefc5f9de5dd60026 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 18 Oct 2020 10:11:34 +0900 Subject: Improve waiting dialog --- src/client/components/icon-dialog.vue | 73 ---------------------- src/client/components/page/page.post.vue | 12 +--- src/client/components/waiting-dialog.vue | 95 +++++++++++++++++++++++++++++ src/client/os.ts | 40 ++++++++---- 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 +++------- 9 files changed, 168 insertions(+), 189 deletions(-) delete mode 100644 src/client/components/icon-dialog.vue create mode 100644 src/client/components/waiting-dialog.vue (limited to 'src') diff --git a/src/client/components/icon-dialog.vue b/src/client/components/icon-dialog.vue deleted file mode 100644 index e8eae3342f..0000000000 --- a/src/client/components/icon-dialog.vue +++ /dev/null @@ -1,73 +0,0 @@ - - - - - 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/waiting-dialog.vue b/src/client/components/waiting-dialog.vue new file mode 100644 index 0000000000..7e8ebeaec0 --- /dev/null +++ b/src/client/components/waiting-dialog.vue @@ -0,0 +1,95 @@ + + + + + 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) { +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 state = ref('waiting'); + const success = ref(false); - const promise = api(endpoint, data, token); 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 @@