-
Notifications
You must be signed in to change notification settings - Fork 1
fix: プレビューを正しく表示できるようにする #601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the preview display functionality for uploaded files by properly passing the file's data URL to the image preview component.
Key Changes:
- Added
previewUrlfield to theFileSeedinterface to store the file's preview URL - Updated file upload logic to capture and store the FileReader result as
previewUrl - Changed image source binding from filename to the actual preview URL
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/features/file/entities.ts | Added optional previewUrl property to FileSeed interface |
| src/components/newApplication/NewApplicationFileForm.vue | Updated file handling to store preview URL and corrected image src binding |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
871ca1f to
3fe4144
Compare
| const emit = defineEmits<(e: 'input', value: FileSeed[]) => void>() | ||
| const inputRef = ref() | ||
| const filePreviewUrls = ref<string[]>([]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
今はなさそうですが、props.filesが親側で変更された場合に追従できない気がします
- refactor: `files` を `v-model` で渡す
c3ab260 to
3366719
Compare
| files, | ||
| files => { | ||
| filePreviewUrls.value = files.map(({ file }) => { | ||
| if (previewUrlCache.has(file)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previewUrlCache.get(file)を取得してundefinedでなかったらreturnする方が型的には安全そうな気がします
| 'input', | ||
| props.files.filter((_, i) => index !== i) | ||
| ) | ||
| files.value.splice(index, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
悩みどころだけどremoveFileでもrevokeObjectURLを呼ばないとユーザーの操作次第では重くなりそうな気がします
| // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
| return previewUrlCache.get(file)! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previewUrlCache.get(file)を取得してundefinedでなかったらreturnする方が型的に保証されていて安全なので、そうする方がいい気がします
| // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
| URL.revokeObjectURL(previewUrlCache.get(file)!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previewUrlCache.get(file)がundefinedでない時だけrevokeObjectURLを呼ぶ、みたいなラフな実装でいいので、null assertionはあんまり使わないようにお願いします
型チェックの恩恵は受けられないより受けられる方がましです
| files.value.splice(index, 1) | ||
| } | ||
| const filePreviewUrls = computed(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
必須ではないんですけど、useFilePreviewUrlsみたいなcomposableをこのコンポーネント内か別ファイルに作って、previewUrlCacheはその中でだけ参照されるようにしつつ、onUnmountedをその中で呼び出すようにすると、特定の役割をしている変数と処理群をまとめられるので可読性と将来的な変更のしやすさが上げられたり、変数の可視範囲を狭められて将来誤った変更をする可能性を減らせたりするので良いんじゃないかなと思います
User description
close: #590
PR Type
Bug fix, Enhancement
Description
画像プレビュー用URLを状態に保持
プレビューimgのsrcにpreviewUrlを使用
FileSeedへpreviewUrlフィールドを追加
Diagram Walkthrough
File Walkthrough
entities.ts
FileSeedにpreviewUrlプロパティを追加src/features/file/entities.ts
NewApplicationFileForm.vue
プレビューURL保存とimg参照先の修正src/components/newApplication/NewApplicationFileForm.vue