enhance(frontend): ユーザーメニューでスイッチでユーザーリストに追加・削除できるように (#11439)
* メニューのトグルをいい感じにする * user list toggle! * add changelog * fix * stop
This commit is contained in:
@@ -16,6 +16,7 @@ import { defaultStore, noteActions } from '@/store';
|
||||
import { miLocalStorage } from '@/local-storage';
|
||||
import { getUserMenu } from '@/scripts/get-user-menu';
|
||||
import { clipsCache } from '@/cache';
|
||||
import { MenuItem } from '@/types/menu';
|
||||
|
||||
export async function getNoteClipMenu(props: {
|
||||
note: misskey.entities.Note;
|
||||
@@ -108,6 +109,8 @@ export function getNoteMenu(props: {
|
||||
|
||||
const appearNote = isRenote ? props.note.renote as misskey.entities.Note : props.note;
|
||||
|
||||
const cleanups = [] as (() => void)[];
|
||||
|
||||
function del(): void {
|
||||
os.confirm({
|
||||
type: 'warning',
|
||||
@@ -233,7 +236,7 @@ export function getNoteMenu(props: {
|
||||
props.translation.value = res;
|
||||
}
|
||||
|
||||
let menu;
|
||||
let menu: MenuItem[];
|
||||
if ($i) {
|
||||
const statePromise = os.api('notes/state', {
|
||||
noteId: appearNote.id,
|
||||
@@ -295,7 +298,7 @@ export function getNoteMenu(props: {
|
||||
action: () => toggleFavorite(true),
|
||||
}),
|
||||
{
|
||||
type: 'parent',
|
||||
type: 'parent' as const,
|
||||
icon: 'ti ti-paperclip',
|
||||
text: i18n.ts.clip,
|
||||
children: () => getNoteClipMenu(props),
|
||||
@@ -318,15 +321,17 @@ export function getNoteMenu(props: {
|
||||
text: i18n.ts.pin,
|
||||
action: () => togglePin(true),
|
||||
} : undefined,
|
||||
appearNote.userId !== $i.id ? {
|
||||
type: 'parent',
|
||||
{
|
||||
type: 'parent' as const,
|
||||
icon: 'ti ti-user',
|
||||
text: i18n.ts.user,
|
||||
children: async () => {
|
||||
const user = await os.api('users/show', { userId: appearNote.userId });
|
||||
return getUserMenu(user);
|
||||
const user = appearNote.userId === $i?.id ? $i : await os.api('users/show', { userId: appearNote.userId });
|
||||
const { menu, cleanup } = getUserMenu(user);
|
||||
cleanups.push(cleanup);
|
||||
return menu;
|
||||
},
|
||||
} : undefined,
|
||||
},
|
||||
/*
|
||||
...($i.isModerator || $i.isAdmin ? [
|
||||
null,
|
||||
@@ -411,5 +416,13 @@ export function getNoteMenu(props: {
|
||||
}]);
|
||||
}
|
||||
|
||||
return menu;
|
||||
const cleanup = () => {
|
||||
if (_DEV_) console.log('note menu cleanup', cleanups);
|
||||
cleanups.forEach(cleanup => cleanup());
|
||||
};
|
||||
|
||||
return {
|
||||
menu,
|
||||
cleanup,
|
||||
};
|
||||
}
|
||||
|
@@ -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,
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user