summaryrefslogtreecommitdiff
path: root/packages/frontend/src/scripts/get-user-menu.ts
diff options
context:
space:
mode:
authortamaina <tamaina@hotmail.co.jp>2023-08-01 15:32:03 +0900
committerGitHub <noreply@github.com>2023-08-01 15:32:03 +0900
commit8a72a05958f415aa035ae3523e28c0b75f2a8d26 (patch)
treefa255718093f498c936008ba21665654521610bc /packages/frontend/src/scripts/get-user-menu.ts
parentupdate deps (#11409) (diff)
downloadsharkey-8a72a05958f415aa035ae3523e28c0b75f2a8d26.tar.gz
sharkey-8a72a05958f415aa035ae3523e28c0b75f2a8d26.tar.bz2
sharkey-8a72a05958f415aa035ae3523e28c0b75f2a8d26.zip
enhance(frontend): ユーザーメニューでスイッチでユーザーリストに追加・削除できるように (#11439)
* メニューのトグルをいい感じにする * user list toggle! * add changelog * fix * stop
Diffstat (limited to 'packages/frontend/src/scripts/get-user-menu.ts')
-rw-r--r--packages/frontend/src/scripts/get-user-menu.ts49
1 files changed, 37 insertions, 12 deletions
diff --git a/packages/frontend/src/scripts/get-user-menu.ts b/packages/frontend/src/scripts/get-user-menu.ts
index 7f2111be4c..445560b0c3 100644
--- a/packages/frontend/src/scripts/get-user-menu.ts
+++ b/packages/frontend/src/scripts/get-user-menu.ts
@@ -4,7 +4,7 @@
*/
import { toUnicode } from 'punycode';
-import { defineAsyncComponent } from 'vue';
+import { defineAsyncComponent, ref, watch } from 'vue';
import * as misskey from 'misskey-js';
import { i18n } from '@/i18n';
import copyToClipboard from '@/scripts/copy-to-clipboard';
@@ -19,6 +19,8 @@ import { antennasCache, rolesCache, userListsCache } from '@/cache';
export function getUserMenu(user: misskey.entities.UserDetailed, router: Router = mainRouter) {
const meId = $i ? $i.id : null;
+ const cleanups = [] as (() => void)[];
+
async function toggleMute() {
if (user.isMuted) {
os.apiWithDialog('mute/delete', {
@@ -168,17 +170,32 @@ export function getUserMenu(user: misskey.entities.UserDetailed, router: Router
text: i18n.ts.addToList,
children: async () => {
const lists = await userListsCache.fetch(() => os.api('users/lists/list'));
+ return lists.map(list => {
+ const isListed = ref(list.userIds.includes(user.id));
+ cleanups.push(watch(isListed, () => {
+ if (isListed.value) {
+ os.apiWithDialog('users/lists/push', {
+ listId: list.id,
+ userId: user.id,
+ }).then(() => {
+ list.userIds.push(user.id);
+ });
+ } else {
+ os.apiWithDialog('users/lists/pull', {
+ listId: list.id,
+ userId: user.id,
+ }).then(() => {
+ list.userIds.splice(list.userIds.indexOf(user.id), 1);
+ });
+ }
+ }));
- return lists.map(list => ({
- text: list.name,
- action: async () => {
- await os.apiWithDialog('users/lists/push', {
- listId: list.id,
- userId: user.id,
- });
- userListsCache.delete();
- },
- }));
+ return {
+ type: 'switch',
+ text: list.name,
+ ref: isListed,
+ };
+ });
},
}, {
type: 'parent',
@@ -311,5 +328,13 @@ export function getUserMenu(user: misskey.entities.UserDetailed, router: Router
}))]);
}
- return menu;
+ const cleanup = () => {
+ if (_DEV_) console.log('user menu cleanup', cleanups);
+ cleanups.forEach(cleanup => cleanup());
+ };
+
+ return {
+ menu,
+ cleanup,
+ };
}