From 331afcb96a638d436f7fa925bc395ef04057a147 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 21 Jan 2022 20:17:31 +0900 Subject: feat(client): make possible to switch account instantly in post form --- packages/client/src/components/post-form.vue | 46 ++++++++++++++++++++++++++-- packages/client/src/components/ui/menu.vue | 2 +- 2 files changed, 44 insertions(+), 4 deletions(-) (limited to 'packages/client/src/components') diff --git a/packages/client/src/components/post-form.vue b/packages/client/src/components/post-form.vue index 60b062f054..3ab8af3092 100644 --- a/packages/client/src/components/post-form.vue +++ b/packages/client/src/components/post-form.vue @@ -8,6 +8,9 @@ >
+
{{ maxTextLength - textLength }} @@ -83,7 +86,7 @@ import { throttle } from 'throttle-debounce'; import MkInfo from '@/components/ui/info.vue'; import { i18n } from '@/i18n'; import { instance } from '@/instance'; -import { $i } from '@/account'; +import { $i, getAccounts, openAccountMenu as openAccountMenu_ } from '@/account'; const modal = inject('modal'); @@ -553,8 +556,15 @@ async function post() { } } + let token = undefined; + + if (postAccount) { + const storedAccounts = await getAccounts(); + token = storedAccounts.find(x => x.id === postAccount.id)?.token; + } + posting = true; - os.api('notes/create', data).then(() => { + os.api('notes/create', data, token).then(() => { clear(); nextTick(() => { deleteDraft(); @@ -585,7 +595,7 @@ function insertMention() { }); } -async function insertEmoji(ev) { +async function insertEmoji(ev: MouseEvent) { os.openEmojiPicker(ev.currentTarget || ev.target, {}, textareaEl); } @@ -602,6 +612,23 @@ function showActions(ev) { })), ev.currentTarget || ev.target); } +let postAccount = $ref(null); + +function openAccountMenu(ev: MouseEvent) { + openAccountMenu_({ + withExtraOperation: false, + includeCurrentAccount: true, + active: postAccount != null ? postAccount.id : $i.id, + onChoose: (account) => { + if (account.id === $i.id) { + postAccount = null; + } else { + postAccount = account; + } + }, + }, ev); +} + onMounted(() => { if (props.autofocus) { focus(); @@ -678,6 +705,19 @@ onMounted(() => { line-height: 66px; } + > .account { + height: 100%; + aspect-ratio: 1/1; + display: inline-flex; + vertical-align: bottom; + + > .avatar { + width: 28px; + height: 28px; + margin: auto; + } + } + > div { position: absolute; top: 0; diff --git a/packages/client/src/components/ui/menu.vue b/packages/client/src/components/ui/menu.vue index 6f3f277b11..41165c8d33 100644 --- a/packages/client/src/components/ui/menu.vue +++ b/packages/client/src/components/ui/menu.vue @@ -24,7 +24,7 @@ {{ item.text }} - -- cgit v1.2.3-freya