From 693efb99a0b60435c73ef61133338ae5fd8c1d88 Mon Sep 17 00:00:00 2001 From: mattyatea Date: Sun, 14 Jan 2024 03:39:43 +0900 Subject: [PATCH] list multiple select --- .../src/components/MkUserSelectDialog.vue | 15 ++++++++----- packages/frontend/src/os.ts | 19 +++++++++++++--- packages/frontend/src/pages/my-lists/list.vue | 22 +++++++++++++------ 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/packages/frontend/src/components/MkUserSelectDialog.vue b/packages/frontend/src/components/MkUserSelectDialog.vue index f4aa06950d..90f2194a97 100644 --- a/packages/frontend/src/components/MkUserSelectDialog.vue +++ b/packages/frontend/src/components/MkUserSelectDialog.vue @@ -7,7 +7,7 @@ SPDX-License-Identifier: AGPL-3.0-only +
-
+
@@ -43,7 +44,7 @@ SPDX-License-Identifier: AGPL-3.0-only
-
+
@@ -67,6 +68,7 @@ import { defaultStore } from '@/store.js'; import { i18n } from '@/i18n.js'; import { $i } from '@/account.js'; import { hostname } from '@/config.js'; +import { multipleSelectUser } from '@/os.js'; const emit = defineEmits<{ (ev: 'ok', selected: Misskey.entities.UserDetailed): void; @@ -76,6 +78,7 @@ const emit = defineEmits<{ const props = defineProps<{ includeSelf?: boolean; + multiple?: boolean; }>(); const username = ref(''); @@ -83,6 +86,7 @@ const host = ref(''); const users = ref([]); const recentUsers = ref([]); const selected = ref(null); +const multipleSelected = ref([]); const dialogEl = ref(); const search = () => { @@ -101,11 +105,12 @@ const search = () => { }; const ok = () => { - if (selected.value == null) return; - emit('ok', selected.value); + if ((!selected.value && multipleSelected.value.length < 1)) return; + emit('ok', selected.value ?? multipleSelected.value); dialogEl.value.close(); // 最近使ったユーザー更新 + if (multipleSelected.value.length < 0) return; let recents = defaultStore.state.recentlyUsedUsers; recents = recents.filter(x => x !== selected.value.id); recents.unshift(selected.value.id); diff --git a/packages/frontend/src/os.ts b/packages/frontend/src/os.ts index 11ab7cc0a9..a5df3a6ff0 100644 --- a/packages/frontend/src/os.ts +++ b/packages/frontend/src/os.ts @@ -24,7 +24,7 @@ import MkContextMenu from '@/components/MkContextMenu.vue'; import { MenuItem } from '@/types/menu.js'; import copyToClipboard from '@/scripts/copy-to-clipboard.js'; import { showMovedDialog } from '@/scripts/show-moved-dialog.js'; -import MkSwitch from "@/components/MkSwitch.vue"; +import MkSwitch from '@/components/MkSwitch.vue'; export const openingWindowsCount = ref(0); @@ -220,7 +220,7 @@ export function switch1(props: { text?: string | null; okText?: string; cancelText?: string; -}): Promise<{ canceled: boolean , result: boolean }> { +}): Promise<{ canceled: boolean, result: boolean }> { return new Promise((resolve, reject) => { popup(MkDialog, { ...props, @@ -437,7 +437,20 @@ export function form(title, form) { }); } -export async function selectUser(opts: { includeSelf?: boolean } = {}) { +export async function selectUser(opts: { includeSelf?: boolean, multiple?: boolean, } = {}) { + return new Promise((resolve, reject) => { + popup(defineAsyncComponent(() => import('@/components/MkUserSelectDialog.vue')), { + includeSelf: opts.includeSelf, + multiple: opts.multiple, + }, { + ok: user => { + resolve(user); + }, + }, 'closed'); + }); +} + +export async function multipleSelectUser(opts: { includeSelf?: boolean } = {}) { return new Promise((resolve, reject) => { popup(defineAsyncComponent(() => import('@/components/MkUserSelectDialog.vue')), { includeSelf: opts.includeSelf, diff --git a/packages/frontend/src/pages/my-lists/list.vue b/packages/frontend/src/pages/my-lists/list.vue index 85775a2fdd..326d2b75e2 100644 --- a/packages/frontend/src/pages/my-lists/list.vue +++ b/packages/frontend/src/pages/my-lists/list.vue @@ -104,14 +104,22 @@ function fetchList() { } function addUser() { - os.selectUser().then(user => { + os.selectUser( { multiple: true }).then(user => { if (!list.value) return; - os.apiWithDialog('users/lists/push', { - listId: list.value.id, - userId: user.id, - }).then(() => { - paginationEl.value.reload(); - }); + if (Array.isArray(user)) { + user.forEach(u => { + misskeyApi('users/lists/push', { + listId: list.value.id, + userId: u.id, + }); + }); + } else if (typeof user === 'string') { + os.apiWithDialog('users/lists/push', { + listId: list.value.id, + userId: user.id, + }); + } + paginationEl.value.reload(); }); }