From 86e63d1e4f41e4b6cfd953efd9c4d715caba75e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BE=E3=81=A3=E3=81=A1=E3=82=83=E3=81=A8=E3=83=BC?= =?UTF-8?q?=E3=81=AB=E3=82=85?= <17376330+u1-liquid@users.noreply.github.com> Date: Tue, 19 Mar 2024 06:39:17 +0900 Subject: [PATCH] =?UTF-8?q?fix(frontend/MkPostForm):=20=E4=BD=95=E3=82=89?= =?UTF-8?q?=E3=81=8B=E3=81=AE=E7=90=86=E7=94=B1=E3=81=A7=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=A4=E3=83=AB=E3=81=AE=E3=82=A2=E3=83=83=E3=83=97=E3=83=AD?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=83=BB=E9=81=B8=E6=8A=9E=E3=81=AB=E5=A4=B1?= =?UTF-8?q?=E6=95=97=E3=81=97=E3=81=9F=E3=82=B4=E3=83=9F=E3=83=87=E3=83=BC?= =?UTF-8?q?=E3=82=BF=E3=81=8C=E6=AE=8B=E3=82=8A=E6=8A=95=E7=A8=BF=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=81=AA=E3=81=8F=E3=81=AA=E3=82=8B=E5=95=8F=E9=A1=8C?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3=20(MisskeyIO#534)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frontend/src/components/MkPostForm.vue | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/frontend/src/components/MkPostForm.vue b/packages/frontend/src/components/MkPostForm.vue index 578f38b3bb..578fc4274b 100644 --- a/packages/frontend/src/components/MkPostForm.vue +++ b/packages/frontend/src/components/MkPostForm.vue @@ -421,7 +421,8 @@ function chooseFileFrom(ev) { if (props.mock) return; selectFiles(ev.currentTarget ?? ev.target, i18n.ts.attachFile).then(files_ => { - for (const file of files_) { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + for (const file of files_.filter(f => f?.id)) { files.value.push(file); } }); @@ -450,7 +451,7 @@ function upload(file: File, name?: string): void { if (props.mock) return; uploadFile(file, defaultStore.state.uploadFolder, name).then(res => { - files.value.push(res); + if (res.id) files.value.push(res); }); } @@ -657,7 +658,7 @@ function onDrop(ev: DragEvent): void { const driveFile = ev.dataTransfer?.getData(_DATA_TRANSFER_DRIVE_FILE_); if (driveFile != null && driveFile !== '') { const file = JSON.parse(driveFile); - files.value.push(file); + if (file?.id) files.value.push(file); ev.preventDefault(); } //#endregion @@ -676,7 +677,8 @@ function saveDraft() { cw: cw.value, visibility: visibility.value, localOnly: localOnly.value, - files: files.value, + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + files: files.value.filter(f => f?.id && f.type && f.name), poll: poll.value, }, }; @@ -747,7 +749,8 @@ async function post(ev?: MouseEvent) { let postData = { text: text.value === '' ? null : text.value, - fileIds: files.value.length > 0 ? files.value.map(f => f.id) : undefined, + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + fileIds: files.value.length > 0 ? files.value.filter(f => f?.id).map(f => f.id) : undefined, replyId: props.reply ? props.reply.id : undefined, renoteId: props.renote ? props.renote.id : quoteId.value ? quoteId.value : undefined, channelId: props.channel ? props.channel.id : undefined, @@ -946,7 +949,8 @@ onMounted(() => { cw.value = draft.data.cw; visibility.value = draft.data.visibility; localOnly.value = draft.data.localOnly; - files.value = (draft.data.files || []).filter(draftFile => draftFile); + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + files.value = draft.data.files?.filter(f => f?.id && f.type && f.name) || []; if (draft.data.poll) { poll.value = draft.data.poll; } @@ -957,7 +961,8 @@ onMounted(() => { if (props.initialNote) { const init = props.initialNote; text.value = init.text ? init.text : ''; - files.value = init.files ?? []; + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + files.value = init.files?.filter(f => f?.id && f.type && f.name) ?? []; cw.value = init.cw ?? null; useCw.value = init.cw != null; if (init.poll) {