From 46c02807647bf61188267bfb05db0eeb53660be8 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 10 Dec 2021 01:22:22 +0900 Subject: [PATCH] refactor(client): :sparkles: --- packages/client/src/components/post-form.vue | 4 ++-- packages/client/src/pages/admin/emojis.vue | 4 ++-- packages/client/src/pages/channel-editor.vue | 2 +- packages/client/src/pages/gallery/edit.vue | 4 ++-- .../src/pages/messaging/messaging-room.form.vue | 2 +- packages/client/src/pages/page-editor/page-editor.vue | 2 +- packages/client/src/pages/room/room.vue | 2 +- packages/client/src/pages/settings/theme.vue | 2 +- packages/client/src/scripts/select-file.ts | 11 ++++++++++- packages/client/src/ui/chat/post-form.vue | 4 ++-- 10 files changed, 23 insertions(+), 14 deletions(-) diff --git a/packages/client/src/components/post-form.vue b/packages/client/src/components/post-form.vue index 9bad9a84f8..4265c575e2 100644 --- a/packages/client/src/components/post-form.vue +++ b/packages/client/src/components/post-form.vue @@ -74,7 +74,7 @@ import { formatTimeString } from '@/scripts/format-time-string'; import { Autocomplete } from '@/scripts/autocomplete'; import { noteVisibilities } from 'misskey-js'; import * as os from '@/os'; -import { selectFile } from '@/scripts/select-file'; +import { selectFiles } from '@/scripts/select-file'; import { defaultStore, notePostInterruptors, postFormActions } from '@/store'; import { throttle } from 'throttle-debounce'; import MkInfo from '@/components/ui/info.vue'; @@ -456,7 +456,7 @@ export default defineComponent({ }, chooseFileFrom(ev) { - selectFile(ev.currentTarget || ev.target, this.$ts.attachFile, true).then(files => { + selectFiles(ev.currentTarget || ev.target, this.$ts.attachFile).then(files => { for (const file of files) { this.files.push(file); } diff --git a/packages/client/src/pages/admin/emojis.vue b/packages/client/src/pages/admin/emojis.vue index 9c9b3b2d4f..a4ac5dcebf 100644 --- a/packages/client/src/pages/admin/emojis.vue +++ b/packages/client/src/pages/admin/emojis.vue @@ -53,7 +53,7 @@ import MkButton from '@/components/ui/button.vue'; import MkInput from '@/components/form/input.vue'; import MkPagination from '@/components/ui/pagination.vue'; import MkTab from '@/components/tab.vue'; -import { selectFile } from '@/scripts/select-file'; +import { selectFiles } from '@/scripts/select-file'; import * as os from '@/os'; import * as symbols from '@/symbols'; @@ -117,7 +117,7 @@ export default defineComponent({ methods: { async add(e) { - const files = await selectFile(e.currentTarget || e.target, null, true); + const files = await selectFiles(e.currentTarget || e.target, null); const promise = Promise.all(files.map(file => os.api('admin/emoji/add', { fileId: file.id, diff --git a/packages/client/src/pages/channel-editor.vue b/packages/client/src/pages/channel-editor.vue index 3843ea9795..67b839bc3d 100644 --- a/packages/client/src/pages/channel-editor.vue +++ b/packages/client/src/pages/channel-editor.vue @@ -112,7 +112,7 @@ export default defineComponent({ }, setBannerImage(e) { - selectFile(e.currentTarget || e.target, null, false).then(file => { + selectFile(e.currentTarget || e.target, null).then(file => { this.bannerId = file.id; }); }, diff --git a/packages/client/src/pages/gallery/edit.vue b/packages/client/src/pages/gallery/edit.vue index 08f31d0db2..caca6aed4b 100644 --- a/packages/client/src/pages/gallery/edit.vue +++ b/packages/client/src/pages/gallery/edit.vue @@ -37,7 +37,7 @@ import FormTuple from '@/components/debobigego/tuple.vue'; import FormBase from '@/components/debobigego/base.vue'; import FormGroup from '@/components/debobigego/group.vue'; import FormSuspense from '@/components/debobigego/suspense.vue'; -import { selectFile } from '@/scripts/select-file'; +import { selectFiles } from '@/scripts/select-file'; import * as os from '@/os'; import * as symbols from '@/symbols'; @@ -95,7 +95,7 @@ export default defineComponent({ methods: { selectFile(e) { - selectFile(e.currentTarget || e.target, null, true).then(files => { + selectFiles(e.currentTarget || e.target, null).then(files => { this.files = this.files.concat(files); }); }, diff --git a/packages/client/src/pages/messaging/messaging-room.form.vue b/packages/client/src/pages/messaging/messaging-room.form.vue index 0ce589f034..8d92c430f1 100644 --- a/packages/client/src/pages/messaging/messaging-room.form.vue +++ b/packages/client/src/pages/messaging/messaging-room.form.vue @@ -152,7 +152,7 @@ export default defineComponent({ }, chooseFile(e) { - selectFile(e.currentTarget || e.target, this.$ts.selectFile, false).then(file => { + selectFile(e.currentTarget || e.target, this.$ts.selectFile).then(file => { this.file = file; }); }, diff --git a/packages/client/src/pages/page-editor/page-editor.vue b/packages/client/src/pages/page-editor/page-editor.vue index 52f6858b0b..fe207555f8 100644 --- a/packages/client/src/pages/page-editor/page-editor.vue +++ b/packages/client/src/pages/page-editor/page-editor.vue @@ -448,7 +448,7 @@ export default defineComponent({ }, setEyeCatchingImage(e) { - selectFile(e.currentTarget || e.target, null, false).then(file => { + selectFile(e.currentTarget || e.target, null).then(file => { this.eyeCatchingImageId = file.id; }); }, diff --git a/packages/client/src/pages/room/room.vue b/packages/client/src/pages/room/room.vue index fa35d7d93e..eb85d39dc4 100644 --- a/packages/client/src/pages/room/room.vue +++ b/packages/client/src/pages/room/room.vue @@ -210,7 +210,7 @@ export default defineComponent({ }, chooseImage(key, e) { - selectFile(e.currentTarget || e.target, null, false).then(file => { + selectFile(e.currentTarget || e.target, null).then(file => { room.updateProp(key, `/proxy/?${urlQuery({ url: file.thumbnailUrl })}`); this.$refs.preview.selected(room.getSelectedObject()); this.changed = true; diff --git a/packages/client/src/pages/settings/theme.vue b/packages/client/src/pages/settings/theme.vue index 2f4daa26c0..357b2ab830 100644 --- a/packages/client/src/pages/settings/theme.vue +++ b/packages/client/src/pages/settings/theme.vue @@ -188,7 +188,7 @@ export default defineComponent({ themesCount, wallpaper, setWallpaper(e) { - selectFile(e.currentTarget || e.target, null, false).then(file => { + selectFile(e.currentTarget || e.target, null).then(file => { wallpaper.value = file.url; }); }, diff --git a/packages/client/src/scripts/select-file.ts b/packages/client/src/scripts/select-file.ts index 0c6bd7ccde..6019890444 100644 --- a/packages/client/src/scripts/select-file.ts +++ b/packages/client/src/scripts/select-file.ts @@ -1,8 +1,9 @@ import * as os from '@/os'; import { i18n } from '@/i18n'; import { defaultStore } from '@/store'; +import { DriveFile } from 'misskey-js/built/entities'; -export function selectFile(src: any, label: string | null, multiple = false) { +function select(src: any, label: string | null, multiple: boolean): Promise { return new Promise((res, rej) => { const chooseFileFromPc = () => { const input = document.createElement('input'); @@ -86,3 +87,11 @@ export function selectFile(src: any, label: string | null, multiple = false) { }], src); }); } + +export function selectFile(src: any, label: string | null = null): Promise { + return select(src, label, false) as Promise; +} + +export function selectFiles(src: any, label: string | null = null): Promise { + return select(src, label, true) as Promise; +} diff --git a/packages/client/src/ui/chat/post-form.vue b/packages/client/src/ui/chat/post-form.vue index e22bedf6bd..8c572e3b1c 100644 --- a/packages/client/src/ui/chat/post-form.vue +++ b/packages/client/src/ui/chat/post-form.vue @@ -59,7 +59,7 @@ import * as Acct from 'misskey-js/built/acct'; import { formatTimeString } from '@/scripts/format-time-string'; import { Autocomplete } from '@/scripts/autocomplete'; import * as os from '@/os'; -import { selectFile } from '@/scripts/select-file'; +import { selectFiles } from '@/scripts/select-file'; import { notePostInterruptors, postFormActions } from '@/store'; import { throttle } from 'throttle-debounce'; @@ -342,7 +342,7 @@ export default defineComponent({ }, chooseFileFrom(ev) { - selectFile(ev.currentTarget || ev.target, this.$ts.attachFile, true).then(files => { + selectFiles(ev.currentTarget || ev.target, this.$ts.attachFile).then(files => { for (const file of files) { this.files.push(file); }