2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2021-04-23 06:01:52 +02:00
|
|
|
<template>
|
2023-01-08 05:10:01 +01:00
|
|
|
<div class="">
|
2021-04-23 06:01:52 +02:00
|
|
|
<FormSuspense :p="init">
|
2023-01-08 05:10:01 +01:00
|
|
|
<div class="_gaps">
|
2023-03-09 06:27:16 +01:00
|
|
|
<div class="_buttons">
|
2023-09-30 21:53:52 +02:00
|
|
|
<MkButton primary @click="addAccount"><i class="ph-plus ph-bold ph-lg"></i> {{ i18n.ts.addAccount }}</MkButton>
|
2023-11-03 23:20:53 +01:00
|
|
|
<MkButton @click="init"><i class="ph-arrows-counter-clockwise ph-bold ph-lg"></i> {{ i18n.ts.reloadAccountsList }}</MkButton>
|
2021-04-23 06:01:52 +02:00
|
|
|
</div>
|
2023-03-09 06:27:16 +01:00
|
|
|
|
|
|
|
<MkUserCardMini v-for="user in accounts" :key="user.id" :user="user" :class="$style.user" @click.prevent="menu(user, $event)"/>
|
2021-04-23 06:01:52 +02:00
|
|
|
</div>
|
|
|
|
</FormSuspense>
|
2022-01-04 10:21:00 +01:00
|
|
|
</div>
|
2021-04-23 06:01:52 +02:00
|
|
|
</template>
|
|
|
|
|
2022-05-03 13:33:40 +02:00
|
|
|
<script lang="ts" setup>
|
2022-06-20 10:38:49 +02:00
|
|
|
import { defineAsyncComponent, ref } from 'vue';
|
2023-05-19 13:52:15 +02:00
|
|
|
import type * as Misskey from 'misskey-js';
|
2022-01-04 10:21:00 +01:00
|
|
|
import FormSuspense from '@/components/form/suspense.vue';
|
2023-01-06 01:41:14 +01:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import * as os from '@/os.js';
|
|
|
|
import { getAccounts, addAccount as addAccounts, removeAccount as _removeAccount, login, $i } from '@/account.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata.js';
|
2023-03-09 06:27:16 +01:00
|
|
|
import MkUserCardMini from '@/components/MkUserCardMini.vue';
|
2021-04-23 06:01:52 +02:00
|
|
|
|
2022-05-03 13:33:40 +02:00
|
|
|
const storedAccounts = ref<any>(null);
|
2023-03-09 06:27:16 +01:00
|
|
|
const accounts = ref<Misskey.entities.UserDetailed[]>([]);
|
2021-04-23 06:01:52 +02:00
|
|
|
|
2022-05-03 13:33:40 +02:00
|
|
|
const init = async () => {
|
|
|
|
getAccounts().then(accounts => {
|
|
|
|
storedAccounts.value = accounts.filter(x => x.id !== $i!.id);
|
2021-04-23 06:01:52 +02:00
|
|
|
|
2022-05-03 13:33:40 +02:00
|
|
|
return os.api('users/show', {
|
2022-06-20 10:38:49 +02:00
|
|
|
userIds: storedAccounts.value.map(x => x.id),
|
2022-05-03 13:33:40 +02:00
|
|
|
});
|
|
|
|
}).then(response => {
|
|
|
|
accounts.value = response;
|
|
|
|
});
|
2022-06-10 07:36:55 +02:00
|
|
|
};
|
2022-05-03 13:33:40 +02:00
|
|
|
|
|
|
|
function menu(account, ev) {
|
|
|
|
os.popupMenu([{
|
|
|
|
text: i18n.ts.switch,
|
2023-10-01 00:46:42 +02:00
|
|
|
icon: 'ph-arrows-left-right ph-bold ph-lg',
|
2022-05-03 13:33:40 +02:00
|
|
|
action: () => switchAccount(account),
|
|
|
|
}, {
|
2023-03-09 06:27:16 +01:00
|
|
|
text: i18n.ts.logout,
|
2023-09-30 21:53:52 +02:00
|
|
|
icon: 'ph-trash ph-bold ph-lg',
|
2022-05-03 13:33:40 +02:00
|
|
|
danger: true,
|
|
|
|
action: () => removeAccount(account),
|
|
|
|
}], ev.currentTarget ?? ev.target);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addAccount(ev) {
|
|
|
|
os.popupMenu([{
|
|
|
|
text: i18n.ts.existingAccount,
|
|
|
|
action: () => { addExistingAccount(); },
|
|
|
|
}, {
|
|
|
|
text: i18n.ts.createAccount,
|
|
|
|
action: () => { createAccount(); },
|
|
|
|
}], ev.currentTarget ?? ev.target);
|
|
|
|
}
|
|
|
|
|
2023-03-09 06:27:16 +01:00
|
|
|
async function removeAccount(account) {
|
|
|
|
await _removeAccount(account.id);
|
|
|
|
accounts.value = accounts.value.filter(x => x.id !== account.id);
|
2022-06-20 10:38:49 +02:00
|
|
|
}
|
|
|
|
|
2022-05-03 13:33:40 +02:00
|
|
|
function addExistingAccount() {
|
2022-08-30 17:24:33 +02:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/MkSigninDialog.vue')), {}, {
|
2023-03-09 06:27:16 +01:00
|
|
|
done: async res => {
|
|
|
|
await addAccounts(res.id, res.i);
|
2022-05-03 13:33:40 +02:00
|
|
|
os.success();
|
2023-03-09 06:27:16 +01:00
|
|
|
init();
|
2021-04-23 06:01:52 +02:00
|
|
|
},
|
2022-05-03 13:33:40 +02:00
|
|
|
}, 'closed');
|
|
|
|
}
|
2021-04-23 06:01:52 +02:00
|
|
|
|
2022-05-03 13:33:40 +02:00
|
|
|
function createAccount() {
|
2022-08-30 17:24:33 +02:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/MkSignupDialog.vue')), {}, {
|
2023-03-09 06:27:16 +01:00
|
|
|
done: async res => {
|
|
|
|
await addAccounts(res.id, res.i);
|
2022-05-03 13:33:40 +02:00
|
|
|
switchAccountWithToken(res.i);
|
2021-04-23 06:01:52 +02:00
|
|
|
},
|
2022-05-03 13:33:40 +02:00
|
|
|
}, 'closed');
|
|
|
|
}
|
|
|
|
|
|
|
|
async function switchAccount(account: any) {
|
|
|
|
const fetchedAccounts: any[] = await getAccounts();
|
|
|
|
const token = fetchedAccounts.find(x => x.id === account.id).token;
|
|
|
|
switchAccountWithToken(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
function switchAccountWithToken(token: string) {
|
|
|
|
login(token);
|
|
|
|
}
|
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.accounts,
|
2023-11-03 23:20:53 +01:00
|
|
|
icon: 'ph-users ph-bold ph-lg',
|
2021-04-23 06:01:52 +02:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2023-03-09 06:27:16 +01:00
|
|
|
<style lang="scss" module>
|
|
|
|
.user {
|
|
|
|
cursor: pointer;
|
2021-04-23 06:01:52 +02:00
|
|
|
}
|
|
|
|
</style>
|