From 5fa695830d23c4830db87f864cde05cf9c9cec62 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 20 Sep 2020 22:05:34 +0900 Subject: [PATCH] wip --- src/client/components/post-form.vue | 3 +-- src/client/os.ts | 25 +++++++++++++++++++ src/client/pages/my-settings/drive.vue | 3 +-- .../page-editor/els/page-editor.el.image.vue | 3 +-- src/client/pages/page-editor/page-editor.vue | 3 +-- src/client/pages/test.vue | 3 +-- src/client/root.vue | 4 +-- src/client/scripts/select-drive-file.ts | 12 --------- src/client/scripts/select-drive-folder.ts | 13 ---------- src/client/scripts/select-file.ts | 3 +-- src/client/{ => ui}/deck.vue | 2 +- src/client/{ => ui}/default.vue | 4 +-- 12 files changed, 36 insertions(+), 42 deletions(-) delete mode 100644 src/client/scripts/select-drive-file.ts delete mode 100644 src/client/scripts/select-drive-folder.ts rename src/client/{ => ui}/deck.vue (99%) rename src/client/{ => ui}/default.vue (99%) diff --git a/src/client/components/post-form.vue b/src/client/components/post-form.vue index ea1bad82cf..073a31aa82 100644 --- a/src/client/components/post-form.vue +++ b/src/client/components/post-form.vue @@ -66,7 +66,6 @@ import { erase, unique } from '../../prelude/array'; import extractMentions from '../../misc/extract-mentions'; import getAcct from '../../misc/acct/render'; import { formatTimeString } from '../../misc/format-time-string'; -import { selectDriveFile } from '@/scripts/select-drive-file'; import { Autocomplete } from '@/scripts/autocomplete'; import { noteVisibilities } from '../../types'; import { utils } from '@syuilo/aiscript'; @@ -379,7 +378,7 @@ export default defineComponent({ }, chooseFileFromDrive() { - selectDriveFile(true).then(files => { + os.selectDriveFile(true).then(files => { for (const file of files) { this.attachMedia(file); } diff --git a/src/client/os.ts b/src/client/os.ts index 3de504d2ea..8c1944a73a 100644 --- a/src/client/os.ts +++ b/src/client/os.ts @@ -143,6 +143,31 @@ export function dialog(props: Record, opts?: { cancelableByBgClick: }); } +export function selectDriveFile(multiple) { + return new Promise(async (res, rej) => { + modal(await import('@/components/drive-window.vue'), { + type: 'file', + multiple + }).then(files => { + res(multiple ? files : files[0]); + }); + }); +} + +export function selectDriveFolder(multiple) { + return new Promise((res, rej) => { + import('@/components/drive-window.vue').then(dialog => { + const w = $root.new(dialog, { + type: 'folder', + multiple + }); + w.$once('selected', folders => { + res(multiple ? folders : (folders.length === 0 ? null : folders[0])); + }); + }); + }); +} + export function menu(props: Record, opts?: { source: any; }) { return modal(defineAsyncComponent(() => import('@/components/menu.vue')), props, {}, { position: 'source', diff --git a/src/client/pages/my-settings/drive.vue b/src/client/pages/my-settings/drive.vue index 8622eacaf2..d13f1f25a7 100644 --- a/src/client/pages/my-settings/drive.vue +++ b/src/client/pages/my-settings/drive.vue @@ -13,7 +13,6 @@ import { defineComponent } from 'vue'; import { faCloud, faFolderOpen } from '@fortawesome/free-solid-svg-icons'; import { faClock, faEyeSlash, faTrashAlt } from '@fortawesome/free-regular-svg-icons'; import MkButton from '@/components/ui/button.vue'; -import { selectDriveFolder } from '@/scripts/select-drive-folder'; import * as os from '@/os'; export default defineComponent({ @@ -38,7 +37,7 @@ export default defineComponent({ methods: { chooseUploadFolder() { - selectDriveFolder(false).then(async folder => { + os.selectDriveFolder(false).then(async folder => { await this.$store.dispatch('settings/set', { key: 'uploadFolder', value: folder ? folder.id : null }); os.dialog({ type: 'success', diff --git a/src/client/pages/page-editor/els/page-editor.el.image.vue b/src/client/pages/page-editor/els/page-editor.el.image.vue index 8a7885e12f..ad48ff8d2f 100644 --- a/src/client/pages/page-editor/els/page-editor.el.image.vue +++ b/src/client/pages/page-editor/els/page-editor.el.image.vue @@ -19,7 +19,6 @@ import { faPencilAlt } from '@fortawesome/free-solid-svg-icons'; import { faImage, faFolderOpen } from '@fortawesome/free-regular-svg-icons'; import XContainer from '../page-editor.container.vue'; import MkFileThumbnail from '@/components/drive-file-thumbnail.vue'; -import { selectDriveFile } from '@/scripts/select-drive-file'; import * as os from '@/os'; export default defineComponent({ @@ -58,7 +57,7 @@ export default defineComponent({ methods: { async choose() { - selectDriveFile(false).then(file => { + os.selectDriveFile(false).then(file => { this.file = file; this.value.fileId = file.id; }); diff --git a/src/client/pages/page-editor/page-editor.vue b/src/client/pages/page-editor/page-editor.vue index d0533a0614..e60cfe3b2a 100644 --- a/src/client/pages/page-editor/page-editor.vue +++ b/src/client/pages/page-editor/page-editor.vue @@ -106,7 +106,6 @@ import { blockDefs } from '@/scripts/hpml/index'; import { HpmlTypeChecker } from '@/scripts/hpml/type-checker'; import { url } from '@/config'; import { collectPageVars } from '@/scripts/collect-page-vars'; -import { selectDriveFile } from '@/scripts/select-drive-file'; import * as os from '@/os'; export default defineComponent({ @@ -414,7 +413,7 @@ export default defineComponent({ }, setEyeCatchingImage() { - selectDriveFile(false).then(file => { + os.selectDriveFile(false).then(file => { this.eyeCatchingImageId = file.id; }); }, diff --git a/src/client/pages/test.vue b/src/client/pages/test.vue index d11cdef8d0..9f3674771b 100644 --- a/src/client/pages/test.vue +++ b/src/client/pages/test.vue @@ -58,7 +58,6 @@ import MkButton from '@/components/ui/button.vue'; import MkInput from '@/components/ui/input.vue'; import MkSwitch from '@/components/ui/switch.vue'; import MkTextarea from '@/components/ui/textarea.vue'; -import { selectDriveFile } from '@/scripts/select-drive-file'; import * as os from '@/os'; export default defineComponent({ @@ -101,7 +100,7 @@ export default defineComponent({ }, async selectDriveFile() { - const files = await selectDriveFile(); + const files = await os.selectDriveFile(); } } }); diff --git a/src/client/root.vue b/src/client/root.vue index 5b217a7c12..7c566d83c4 100644 --- a/src/client/root.vue +++ b/src/client/root.vue @@ -26,8 +26,8 @@