diff options
| author | syuilo <4439005+syuilo@users.noreply.github.com> | 2025-08-26 17:31:36 +0900 |
|---|---|---|
| committer | syuilo <4439005+syuilo@users.noreply.github.com> | 2025-08-26 17:31:36 +0900 |
| commit | 69bbac013a5875b1ffb686e63c8896b86eacdebf (patch) | |
| tree | b2e4ec2c6c2fab7649e5333753ff6add8ca93377 /packages/frontend/src | |
| parent | chore(frontend): tweak MkServerSetupWizard (diff) | |
| download | misskey-69bbac013a5875b1ffb686e63c8896b86eacdebf.tar.gz misskey-69bbac013a5875b1ffb686e63c8896b86eacdebf.tar.bz2 misskey-69bbac013a5875b1ffb686e63c8896b86eacdebf.zip | |
refactor
Diffstat (limited to 'packages/frontend/src')
| -rw-r--r-- | packages/frontend/src/accounts.ts | 35 | ||||
| -rw-r--r-- | packages/frontend/src/components/MkLink.vue | 4 | ||||
| -rw-r--r-- | packages/frontend/src/components/MkNote.vue | 2 | ||||
| -rw-r--r-- | packages/frontend/src/components/MkNoteDetailed.vue | 5 | ||||
| -rw-r--r-- | packages/frontend/src/components/MkPostFormDialog.vue | 2 | ||||
| -rw-r--r-- | packages/frontend/src/os.ts | 4 | ||||
| -rw-r--r-- | packages/frontend/src/pages/flash/flash-edit.vue | 11 | ||||
| -rw-r--r-- | packages/frontend/src/store.ts | 2 | ||||
| -rw-r--r-- | packages/frontend/src/types/menu.ts | 16 | ||||
| -rw-r--r-- | packages/frontend/src/types/post-form.ts | 9 | ||||
| -rw-r--r-- | packages/frontend/src/utility/drive.ts | 2 | ||||
| -rw-r--r-- | packages/frontend/src/utility/extract-url-from-mfm.ts | 2 |
12 files changed, 61 insertions, 33 deletions
diff --git a/packages/frontend/src/accounts.ts b/packages/frontend/src/accounts.ts index 3693ac3308..afa2ecb911 100644 --- a/packages/frontend/src/accounts.ts +++ b/packages/frontend/src/accounts.ts @@ -23,7 +23,7 @@ export async function getAccounts(): Promise<{ host: string; id: Misskey.entities.User['id']; username: Misskey.entities.User['username']; - user?: Misskey.entities.User | null; + user?: Misskey.entities.MeDetailed | null; token: string | null; }[]> { const tokens = store.s.accountTokens; @@ -38,7 +38,7 @@ export async function getAccounts(): Promise<{ })); } -async function addAccount(host: string, user: Misskey.entities.User, token: AccountWithToken['token']) { +async function addAccount(host: string, user: Misskey.entities.MeDetailed, token: AccountWithToken['token']) { if (!prefer.s.accounts.some(x => x[0] === host && x[1].id === user.id)) { store.set('accountTokens', { ...store.s.accountTokens, [host + '/' + user.id]: token }); store.set('accountInfos', { ...store.s.accountInfos, [host + '/' + user.id]: user }); @@ -149,9 +149,10 @@ export function updateCurrentAccountPartial(accountData: Partial<Misskey.entitie export async function refreshCurrentAccount() { if (!$i) return; + const me = $i; return fetchAccount($i.token, $i.id).then(updateCurrentAccount).catch(reason => { if (reason === isAccountDeleted) { - removeAccount(host, $i.id); + removeAccount(host, me.id); if (Object.keys(store.s.accountTokens).length > 0) { login(Object.values(store.s.accountTokens)[0]); } else { @@ -214,46 +215,58 @@ export async function openAccountMenu(opts: { includeCurrentAccount?: boolean; withExtraOperation: boolean; active?: Misskey.entities.User['id']; - onChoose?: (account: Misskey.entities.User) => void; + onChoose?: (account: Misskey.entities.MeDetailed) => void; }, ev: MouseEvent) { if (!$i) return; + const me = $i; - function createItem(host: string, id: Misskey.entities.User['id'], username: Misskey.entities.User['username'], account: Misskey.entities.User | null | undefined, token: string): MenuItem { + const callback = opts.onChoose; + + function createItem(host: string, id: Misskey.entities.User['id'], username: Misskey.entities.User['username'], account: Misskey.entities.MeDetailed | null | undefined, token: string | null): MenuItem { if (account) { return { type: 'user' as const, user: account, active: opts.active != null ? opts.active === id : false, action: async () => { - if (opts.onChoose) { - opts.onChoose(account); + if (callback) { + callback(account); } else { switchAccount(host, id); } }, }; - } else { + } else if (token != null) { return { type: 'button' as const, text: username, active: opts.active != null ? opts.active === id : false, action: async () => { - if (opts.onChoose) { + if (callback) { fetchAccount(token, id).then(account => { - opts.onChoose(account); + callback(account); }); } else { switchAccount(host, id); } }, }; + } else { + return { + type: 'button' as const, + text: username, + active: opts.active != null ? opts.active === id : false, + action: async () => { + // TODO + }, + }; } } const menuItems: MenuItem[] = []; // TODO: $iのホストも比較したいけど通常null - const accountItems = (await getAccounts().then(accounts => accounts.filter(x => x.id !== $i.id))).map(a => createItem(a.host, a.id, a.username, a.user, a.token)); + const accountItems = (await getAccounts().then(accounts => accounts.filter(x => x.id !== me.id))).map(a => createItem(a.host, a.id, a.username, a.user, a.token)); if (opts.withExtraOperation) { menuItems.push({ diff --git a/packages/frontend/src/components/MkLink.vue b/packages/frontend/src/components/MkLink.vue index 1959f97565..163f172f57 100644 --- a/packages/frontend/src/components/MkLink.vue +++ b/packages/frontend/src/components/MkLink.vue @@ -39,10 +39,12 @@ const el = ref<HTMLElement | { $el: HTMLElement }>(); if (isEnabledUrlPreview.value) { useTooltip(el, (showing) => { + const anchorElement = el.value instanceof HTMLElement ? el.value : el.value?.$el; + if (anchorElement == null) return; const { dispose } = os.popup(defineAsyncComponent(() => import('@/components/MkUrlPreviewPopup.vue')), { showing, url: props.url, - anchorElement: el.value instanceof HTMLElement ? el.value : el.value?.$el, + anchorElement: anchorElement, }, { closed: () => dispose(), }); diff --git a/packages/frontend/src/components/MkNote.vue b/packages/frontend/src/components/MkNote.vue index 17d4c70bfc..729bded03c 100644 --- a/packages/frontend/src/components/MkNote.vue +++ b/packages/frontend/src/components/MkNote.vue @@ -654,7 +654,7 @@ function showRenoteMenu(): void { getCopyNoteLinkMenu(note, i18n.ts.copyLinkRenote), { type: 'divider' }, getAbuseNoteMenu(note, i18n.ts.reportAbuseRenote), - ($i?.isModerator || $i?.isAdmin) ? getUnrenote() : undefined, + ...(($i?.isModerator || $i?.isAdmin) ? [getUnrenote()] : []), ], renoteTime.value); } } diff --git a/packages/frontend/src/components/MkNoteDetailed.vue b/packages/frontend/src/components/MkNoteDetailed.vue index 42e8665fe5..48fd9908bd 100644 --- a/packages/frontend/src/components/MkNoteDetailed.vue +++ b/packages/frontend/src/components/MkNoteDetailed.vue @@ -392,6 +392,9 @@ const reactionsPaginator = markRaw(new Paginator('notes/reactions', { })); useTooltip(renoteButton, async (showing) => { + const anchorElement = renoteButton.value; + if (anchorElement == null) return; + const renotes = await misskeyApi('notes/renotes', { noteId: appearNote.id, limit: 11, @@ -405,7 +408,7 @@ useTooltip(renoteButton, async (showing) => { showing, users, count: appearNote.renoteCount, - anchorElement: renoteButton.value, + anchorElement: anchorElement, }, { closed: () => dispose(), }); diff --git a/packages/frontend/src/components/MkPostFormDialog.vue b/packages/frontend/src/components/MkPostFormDialog.vue index 1f7796bd83..bf332e706e 100644 --- a/packages/frontend/src/components/MkPostFormDialog.vue +++ b/packages/frontend/src/components/MkPostFormDialog.vue @@ -57,7 +57,7 @@ async function _close() { modal.value?.close(); } -function onEsc(ev: KeyboardEvent) { +function onEsc() { _close(); } diff --git a/packages/frontend/src/os.ts b/packages/frontend/src/os.ts index 6ba3af72b9..56a2b8d269 100644 --- a/packages/frontend/src/os.ts +++ b/packages/frontend/src/os.ts @@ -684,7 +684,7 @@ export async function cropImageFile(imageFile: File | Blob, options: { }); } -export function popupMenu(items: MenuItem[], anchorElement?: HTMLElement | EventTarget | null, options?: { +export function popupMenu(items: (MenuItem | null)[], anchorElement?: HTMLElement | EventTarget | null, options?: { align?: string; width?: number; onClosing?: () => void; @@ -696,7 +696,7 @@ export function popupMenu(items: MenuItem[], anchorElement?: HTMLElement | Event let returnFocusTo = getHTMLElementOrNull(anchorElement) ?? getHTMLElementOrNull(window.document.activeElement); return new Promise(resolve => nextTick(() => { const { dispose } = popup(MkPopupMenu, { - items, + items: items.filter(x => x != null), anchorElement, width: options?.width, align: options?.align, diff --git a/packages/frontend/src/pages/flash/flash-edit.vue b/packages/frontend/src/pages/flash/flash-edit.vue index d2c2621a35..81b9d1cead 100644 --- a/packages/frontend/src/pages/flash/flash-edit.vue +++ b/packages/frontend/src/pages/flash/flash-edit.vue @@ -383,7 +383,7 @@ if (props.id) { const title = ref(flash.value?.title ?? 'New Play'); const summary = ref(flash.value?.summary ?? ''); -const permissions = ref(flash.value?.permissions ?? []); +const permissions = ref([]); // not implemented yet const visibility = ref<'private' | 'public'>(flash.value?.visibility ?? 'public'); const script = ref(flash.value?.script ?? PRESET_DEFAULT); @@ -412,9 +412,9 @@ function selectPreset(ev: MouseEvent) { } async function save() { - if (flash.value) { + if (flash.value != null) { os.apiWithDialog('flash/update', { - flashId: props.id, + flashId: flash.value.id, title: title.value, summary: summary.value, permissions: permissions.value, @@ -448,6 +448,8 @@ function show() { } async function del() { + if (flash.value == null) return; + const { canceled } = await os.confirm({ type: 'warning', text: i18n.tsx.deleteAreYouSure({ x: flash.value.title }), @@ -455,7 +457,7 @@ async function del() { if (canceled) return; await os.apiWithDialog('flash/delete', { - flashId: props.id, + flashId: flash.value.id, }); router.push('/play'); } @@ -468,6 +470,7 @@ definePage(() => ({ title: flash.value ? `${i18n.ts._play.edit}: ${flash.value.title}` : i18n.ts._play.new, })); </script> + <style lang="scss" module> .footer { backdrop-filter: var(--MI-blur, blur(15px)); diff --git a/packages/frontend/src/store.ts b/packages/frontend/src/store.ts index e9402cfb70..750ca69133 100644 --- a/packages/frontend/src/store.ts +++ b/packages/frontend/src/store.ts @@ -106,7 +106,7 @@ export const store = markRaw(new Pizzax('base', { }, accountInfos: { where: 'device', - default: {} as Record<string, Misskey.entities.User>, // host/userId, user + default: {} as Record<string, Misskey.entities.MeDetailed>, // host/userId, user }, enablePreferencesAutoCloudBackup: { diff --git a/packages/frontend/src/types/menu.ts b/packages/frontend/src/types/menu.ts index 6f2f08cb6d..e0bf135ef8 100644 --- a/packages/frontend/src/types/menu.ts +++ b/packages/frontend/src/types/menu.ts @@ -18,7 +18,7 @@ export type MenuAction = (ev: MouseEvent) => void; export interface MenuButton { type?: 'button'; text: Text; - caption?: Text; + caption?: Text | null | undefined | ComputedRef<null | undefined>; icon?: string; indicate?: boolean; danger?: boolean; @@ -38,14 +38,14 @@ export interface MenuDivider extends MenuBase { export interface MenuLabel extends MenuBase { type: 'label'; text: Text; - caption?: Text; + caption?: Text | null | undefined | ComputedRef<null | undefined>; } export interface MenuLink extends MenuBase { type: 'link'; to: string; text: Text; - caption?: Text; + caption?: Text | null | undefined | ComputedRef<null | undefined>; icon?: string; indicate?: boolean; avatar?: Misskey.entities.User; @@ -57,7 +57,7 @@ export interface MenuA extends MenuBase { target?: string; download?: string; text: Text; - caption?: Text; + caption?: Text | null | undefined | ComputedRef<null | undefined>; icon?: string; indicate?: boolean; } @@ -74,7 +74,7 @@ export interface MenuSwitch extends MenuBase { type: 'switch'; ref: Ref<boolean>; text: Text; - caption?: Text; + caption?: Text | null | undefined | ComputedRef<null | undefined>; icon?: string; disabled?: boolean | Ref<boolean>; } @@ -82,7 +82,7 @@ export interface MenuSwitch extends MenuBase { export interface MenuRadio extends MenuBase { type: 'radio'; text: Text; - caption?: Text; + caption?: Text | null | undefined | ComputedRef<null | undefined>; icon?: string; ref: Ref<MenuRadioOptionsDef[keyof MenuRadioOptionsDef]>; options: MenuRadioOptionsDef; @@ -92,7 +92,7 @@ export interface MenuRadio extends MenuBase { export interface MenuRadioOption extends MenuBase { type: 'radioOption'; text: Text; - caption?: Text; + caption?: Text | null | undefined | ComputedRef<null | undefined>; action: MenuAction; active?: boolean | ComputedRef<boolean>; } @@ -106,7 +106,7 @@ export interface MenuComponent<T extends Component = any> extends MenuBase { export interface MenuParent extends MenuBase { type: 'parent'; text: Text; - caption?: Text; + caption?: Text | null | undefined | ComputedRef<null | undefined>; icon?: string; children: MenuItem[] | (() => Promise<MenuItem[]> | MenuItem[]); } diff --git a/packages/frontend/src/types/post-form.ts b/packages/frontend/src/types/post-form.ts index 10e68d2d4a..90c8605f31 100644 --- a/packages/frontend/src/types/post-form.ts +++ b/packages/frontend/src/types/post-form.ts @@ -8,7 +8,14 @@ import * as Misskey from 'misskey-js'; export interface PostFormProps { reply?: Misskey.entities.Note | null; renote?: Misskey.entities.Note | null; - channel?: Misskey.entities.Channel | null; // TODO + channel?: { + id: string; + name: string; + color: string; + isSensitive: boolean; + allowRenoteToExternal: boolean; + userId: string | null; + } | null; mention?: Misskey.entities.User; specified?: Misskey.entities.UserDetailed; initialText?: string; diff --git a/packages/frontend/src/utility/drive.ts b/packages/frontend/src/utility/drive.ts index f2f491b3fd..5ff066f61b 100644 --- a/packages/frontend/src/utility/drive.ts +++ b/packages/frontend/src/utility/drive.ts @@ -233,7 +233,7 @@ function select(anchorElement: HTMLElement | EventTarget | null, label: string | os.popupMenu([label ? { text: label, type: 'label', - } : undefined, { + } : null, { text: i18n.ts.upload, icon: 'ti ti-upload', action: () => chooseFileFromPcAndUpload({ multiple, features }).then(files => res(files)), diff --git a/packages/frontend/src/utility/extract-url-from-mfm.ts b/packages/frontend/src/utility/extract-url-from-mfm.ts index 570823d5b5..48243dff36 100644 --- a/packages/frontend/src/utility/extract-url-from-mfm.ts +++ b/packages/frontend/src/utility/extract-url-from-mfm.ts @@ -13,7 +13,7 @@ const removeHash = (x: string) => x.replace(/#[^#]*$/, ''); export function extractUrlFromMfm(nodes: mfm.MfmNode[], respectSilentFlag = true): string[] { const urlNodes = mfm.extract(nodes, (node) => { return (node.type === 'url') || (node.type === 'link' && (!respectSilentFlag || !node.props.silent)); - }); + }) as mfm.MfmUrl[]; const urls: string[] = unique(urlNodes.map(x => x.props.url)); return urls.reduce((array, url) => { |