From 7387cae138cf92c1932e8d09d2b96fe5ad226647 Mon Sep 17 00:00:00 2001 From: yukineko <27853966+hideki0403@users.noreply.github.com> Date: Tue, 9 Jan 2024 01:10:47 +0900 Subject: [PATCH] refactor: fix some type errors --- .../frontend/src/components/MkCwButton.vue | 18 ++---- .../src/components/MkInstanceTicker.vue | 6 +- .../frontend/src/components/MkMediaList.vue | 17 +++-- .../frontend/src/components/MkMediaVideo.vue | 6 +- .../frontend/src/components/MkMenu.child.vue | 5 +- packages/frontend/src/components/MkMenu.vue | 20 +++--- .../frontend/src/components/MkMiniChart.vue | 4 +- .../frontend/src/components/MkModalWindow.vue | 4 +- packages/frontend/src/components/MkNote.vue | 64 ++++++++++--------- .../src/components/MkSwitch.button.vue | 2 +- .../frontend/src/scripts/get-note-menu.ts | 15 +++-- .../frontend/src/scripts/reaction-picker.ts | 2 +- .../frontend/src/scripts/use-note-capture.ts | 6 +- 13 files changed, 85 insertions(+), 84 deletions(-) diff --git a/packages/frontend/src/components/MkCwButton.vue b/packages/frontend/src/components/MkCwButton.vue index 4a6d2dfba2..8d5c0ee559 100644 --- a/packages/frontend/src/components/MkCwButton.vue +++ b/packages/frontend/src/components/MkCwButton.vue @@ -17,22 +17,14 @@ import MkButton from '@/components/MkButton.vue'; const props = defineProps<{ modelValue: boolean; text: string | null; - renote: Misskey.entities.Note | null; - files: Misskey.entities.DriveFile[]; - poll?: { - expiresAt: string | null; - multiple: boolean; - choices: { - isVoted: boolean; - text: string; - votes: number; - }[]; - } | { + renote?: Misskey.entities.Note | null; + files?: Misskey.entities.DriveFile[]; + poll?: Misskey.entities.Note['poll'] | { choices: string[]; multiple: boolean; expiresAt: string | null; expiredAfter: string | null; - }; + } | null; }>(); const emit = defineEmits<{ @@ -43,7 +35,7 @@ const label = computed(() => { return concat([ props.text ? [i18n.t('_cw.chars', { count: props.text.length })] : [], props.renote ? [i18n.ts.quote] : [], - props.files.length !== 0 ? [i18n.t('_cw.files', { count: props.files.length })] : [], + props.files && props.files.length !== 0 ? [i18n.t('_cw.files', { count: props.files.length })] : [], props.poll != null ? [i18n.ts.poll] : [], ] as string[][]).join(' / '); }); diff --git a/packages/frontend/src/components/MkInstanceTicker.vue b/packages/frontend/src/components/MkInstanceTicker.vue index b16838dcd5..27cd693481 100644 --- a/packages/frontend/src/components/MkInstanceTicker.vue +++ b/packages/frontend/src/components/MkInstanceTicker.vue @@ -18,9 +18,9 @@ import { getProxiedImageUrlNullable } from '@/scripts/media-proxy.js'; const props = defineProps<{ instance?: { - faviconUrl?: string - name: string - themeColor?: string + faviconUrl?: string | null + name?: string | null + themeColor?: string | null } }>(); diff --git a/packages/frontend/src/components/MkMediaList.vue b/packages/frontend/src/components/MkMediaList.vue index 09c5ad9222..4938754bcd 100644 --- a/packages/frontend/src/components/MkMediaList.vue +++ b/packages/frontend/src/components/MkMediaList.vue @@ -52,7 +52,7 @@ const count = computed(() => props.mediaList.filter(media => previewable(media)) let lightbox: PhotoSwipeLightbox | null; const popstateHandler = (): void => { - if (lightbox.pswp && lightbox.pswp.isOpen === true) { + if (lightbox?.pswp && lightbox.pswp.isOpen === true) { lightbox.pswp.close(); } }; @@ -67,7 +67,10 @@ async function calcAspectRatio() { return; } - const ratioMax = (ratio: number) => `${Math.max(ratio, img.properties.width / img.properties.height).toString()} / 1`; + const ratioMax = (ratio: number) => { + if (!img.properties.width || !img.properties.height) return ''; + return `${Math.max(ratio, img.properties.width / img.properties.height).toString()} / 1`; + }; switch (defaultStore.state.mediaListWithOneImageAppearance) { case '16_9': @@ -137,7 +140,7 @@ onMounted(() => { // element is children const { element } = itemData; - const id = element.dataset.id; + const id = element?.dataset.id; const file = props.mediaList.find(media => media.id === id); if (!file) return; @@ -147,14 +150,14 @@ onMounted(() => { if (file.properties.orientation != null && file.properties.orientation >= 5) { [itemData.w, itemData.h] = [itemData.h, itemData.w]; } - itemData.msrc = file.thumbnailUrl; + itemData.msrc = file.thumbnailUrl ?? undefined; itemData.alt = file.comment ?? file.name; itemData.comment = file.comment ?? file.name; itemData.thumbCropped = true; }); lightbox.on('uiRegister', () => { - lightbox.pswp.ui.registerElement({ + lightbox?.pswp?.ui?.registerElement({ name: 'altText', className: 'pwsp__alt-text-container', appendTo: 'wrapper', @@ -163,8 +166,8 @@ onMounted(() => { textBox.className = 'pwsp__alt-text _acrylic'; el.appendChild(textBox); - pwsp.on('change', (a) => { - textBox.textContent = pwsp.currSlide.data.comment; + pwsp.on('change', () => { + textBox.textContent = pwsp.currSlide?.data.comment; }); }, }); diff --git a/packages/frontend/src/components/MkMediaVideo.vue b/packages/frontend/src/components/MkMediaVideo.vue index f9dba0b15a..53d4393b10 100644 --- a/packages/frontend/src/components/MkMediaVideo.vue +++ b/packages/frontend/src/components/MkMediaVideo.vue @@ -16,8 +16,8 @@ SPDX-License-Identifier: AGPL-3.0-only