enhance(client): improve usability of user select

This commit is contained in:
syuilo 2023-01-16 05:29:44 +09:00
parent f3c5ca6cf4
commit fbfe42d6f0
3 changed files with 17 additions and 4 deletions

View file

@ -60,6 +60,7 @@ import MkModalWindow from '@/components/MkModalWindow.vue';
import * as os from '@/os'; import * as os from '@/os';
import { defaultStore } from '@/store'; import { defaultStore } from '@/store';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
import { $i } from '@/account';
const emit = defineEmits<{ const emit = defineEmits<{
(ev: 'ok', selected: misskey.entities.UserDetailed): void; (ev: 'ok', selected: misskey.entities.UserDetailed): void;
@ -67,6 +68,10 @@ const emit = defineEmits<{
(ev: 'closed'): void; (ev: 'closed'): void;
}>(); }>();
const props = defineProps<{
includeSelf?: boolean;
}>();
let username = $ref(''); let username = $ref('');
let host = $ref(''); let host = $ref('');
let users: misskey.entities.UserDetailed[] = $ref([]); let users: misskey.entities.UserDetailed[] = $ref([]);
@ -110,7 +115,11 @@ onMounted(() => {
os.api('users/show', { os.api('users/show', {
userIds: defaultStore.state.recentlyUsedUsers, userIds: defaultStore.state.recentlyUsedUsers,
}).then(users => { }).then(users => {
recentUsers = users; if (props.includeSelf) {
recentUsers = [$i, ...users];
} else {
recentUsers = users;
}
}); });
}); });
</script> </script>

View file

@ -322,9 +322,11 @@ export function form(title, form) {
}); });
} }
export async function selectUser() { export async function selectUser(opts: { includeSelf?: boolean } = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/MkUserSelectDialog.vue')), {}, { popup(defineAsyncComponent(() => import('@/components/MkUserSelectDialog.vue')), {
includeSelf: opts.includeSelf,
}, {
ok: user => { ok: user => {
resolve(user); resolve(user);
}, },

View file

@ -77,7 +77,9 @@ async function del() {
} }
function assign() { function assign() {
os.selectUser().then(async (user) => { os.selectUser({
includeSelf: true,
}).then(async (user) => {
await os.apiWithDialog('admin/roles/assign', { roleId: role.id, userId: user.id }); await os.apiWithDialog('admin/roles/assign', { roleId: role.id, userId: user.id });
role.users.push(user); role.users.push(user);
}); });