From 3f79c9ae4927d4186c708e130ecbb1ea4f72d9fa Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 9 Nov 2018 16:00:29 +0900 Subject: Refactor client (#3178) * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip --- src/client/app/mobile/script.ts | 101 ++++++++++++++++++++++++++++++++++------ 1 file changed, 86 insertions(+), 15 deletions(-) (limited to 'src/client/app/mobile/script.ts') diff --git a/src/client/app/mobile/script.ts b/src/client/app/mobile/script.ts index 9412c85980..707aae087b 100644 --- a/src/client/app/mobile/script.ts +++ b/src/client/app/mobile/script.ts @@ -2,6 +2,7 @@ * Mobile Client */ +import Vue from 'vue'; import VueRouter from 'vue-router'; // Style @@ -9,13 +10,6 @@ import './style.styl'; import init from '../init'; -import chooseDriveFolder from './api/choose-drive-folder'; -import chooseDriveFile from './api/choose-drive-file'; -import dialog from './api/dialog'; -import input from './api/input'; -import post from './api/post'; -import notify from './api/notify'; - import MkIndex from './views/pages/index.vue'; import MkSignup from './views/pages/signup.vue'; import MkUser from './views/pages/user.vue'; @@ -39,10 +33,94 @@ import MkTag from './views/pages/tag.vue'; import MkShare from './views/pages/share.vue'; import MkFollow from '../common/views/pages/follow.vue'; +import PostForm from './views/components/post-form-dialog.vue'; +import FileChooser from './views/components/drive-file-chooser.vue'; +import FolderChooser from './views/components/drive-folder-chooser.vue'; +import Dialog from './views/components/dialog.vue'; + /** * init */ init((launch) => { + Vue.mixin({ + methods: { + $post(opts) { + const o = opts || {}; + + document.documentElement.style.overflow = 'hidden'; + + function recover() { + document.documentElement.style.overflow = 'auto'; + } + + const vm = this.$root.new(PostForm, { + reply: o.reply, + renote: o.renote + }); + + vm.$once('cancel', recover); + vm.$once('posted', recover); + if (o.cb) vm.$once('closed', o.cb); + (vm as any).focus(); + }, + + $chooseDriveFile(opts) { + return new Promise((res, rej) => { + const o = opts || {}; + const vm = this.$root.new(FileChooser, { + title: o.title, + multiple: o.multiple, + initFolder: o.currentFolder + }); + vm.$once('selected', file => { + res(file); + }); + }); + }, + + $chooseDriveFolder(opts) { + return new Promise((res, rej) => { + const o = opts || {}; + const vm = this.$root.new(FolderChooser, { + title: o.title, + initFolder: o.currentFolder + }); + vm.$once('selected', folder => { + res(folder); + }); + }); + }, + + $input(opts) { + return new Promise((res, rej) => { + const x = window.prompt(opts.title); + if (x) { + res(x); + } + }); + }, + + $dialog(opts) { + return new Promise((res, rej) => { + const o = opts || {}; + const d = this.$root.new(Dialog, { + title: o.title, + text: o.text, + modal: o.modal, + buttons: o.actions + }); + d.$once('clicked', id => { + res(id); + }); + }); + }, + + $notify(message) { + alert(message); + } + } + }); + // Register directives require('./views/directives'); @@ -85,12 +163,5 @@ init((launch) => { }); // Launch the app - launch(router, os => ({ - chooseDriveFolder, - chooseDriveFile, - dialog: dialog(os), - input, - post: post(os), - notify - })); + launch(router); }, true); -- cgit v1.2.3-freya