WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@karlley
Copy link
Contributor

@karlley karlley commented Nov 17, 2025

Issue

概要

ドラッグ&ドロップで画像選択できるように修正

変更確認方法

  1. bug/portfolio-thumbnail-drag-drop ブランチをローカルに取り込む
  2. ポートフォリオ作成ページ(/works/new)にアクセス
  3. サムネイル画像に画像をドラッグ&ドロップ
  4. 画像が選択状態になっていることを確認

Screenshot

見た目の変更はありません

Summary by CodeRabbit

  • 新機能
    • ファイル入力にドラッグ&ドロップ対応を追加しました。入力エリアへファイルをドラッグ&ドロップすると選択され、既存の変更イベント処理やHEIC→JPEG変換のフローはそのまま動作します。

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 17, 2025

Walkthrough

ファイル入力要素にドラッグ&ドロップを追加。ドロップゾーンで dragoverdrop をハンドルし、ドロップされたファイルを該当 inputfiles に割り当てて change イベントを発火。既存のHEIC→JPEG変換処理はそのまま維持。

Changes

Cohort / File(s) Summary
ドラッグ・アンド・ドロップ対応
app/javascript/fileinput.js
ドロップゾーンに dragover / drop イベントハンドラを追加。ドロップ時に preventDefault() を呼び、ドロップされた FileList をターゲットの input.files に設定して change イベントをディスパッチ。既存の change ハンドラおよび HEIC→JPEG 変換フローは変更なし。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • 単一ファイルの追加で処理は直線的
  • 注意点:
    • drop 時の preventDefault()/stopPropagation() の適切さ
    • input.files へ代入する方法(互換性)
    • 複数ファイル対応と既存の change ハンドラ(HEIC変換)が期待どおり動作するか

Suggested reviewers

  • okuramasafumi
  • komagata

Poem

🐰 ぽとりと落としたその一枚
ふわり受け止めて画面にぴょんと
change が鳴れば変換の旅へ行く
小さな改良が手をつなぐ道
🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed タイトルは変更の主要な目的を正確に反映しており、ドラッグ&ドロップで画像選択できるようにしたという主な変更内容を簡潔に説明しています。
Description check ✅ Passed プルリクエストの説明は必須セクションをすべて含み、Issue番号、概要、変更確認方法、スクリーンショットセクションが適切に記載されています。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bug/portfolio-thumbnail-drag-drop

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 54e468e and 3986db2.

📒 Files selected for processing (1)
  • app/javascript/fileinput.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/javascript/fileinput.js
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/javascript/fileinput.js (1)

32-38: ドラッグ&ドロップの実装が正しく動作します

実装は正常に機能しますが、より堅牢にするために以下の改善を検討してください:

  1. ドロップされたファイルの存在確認を追加
  2. 複数ファイルがドロップされた場合の動作を明示(現在は1つ目のファイルのみ処理されます)

以下のようにバリデーションを追加できます:

 dropZone.addEventListener('drop', (e) => {
   e.preventDefault()
+  if (!e.dataTransfer.files || e.dataTransfer.files.length === 0) return
   input.files = e.dataTransfer.files
   input.dispatchEvent(new Event('change'))
 })
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c42e0d and ab13734.

📒 Files selected for processing (1)
  • app/javascript/fileinput.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js

⚙️ CodeRabbit configuration file

**/*.js: - どうしても避けられない時以外に新規にVue.js, Reactのコードを追加しない。

  • fetchメソッドの代わりにrequest.jsを使う。

Files:

  • app/javascript/fileinput.js
🧠 Learnings (1)
📓 Common learnings
Learnt from: Miya096jp
Repo: fjordllc/bootcamp PR: 9102
File: app/controllers/mentor/buzzes_controller.rb:0-0
Timestamp: 2025-09-04T01:39:22.261Z
Learning: fjordllc/bootcamp プロジェクトでは、更新処理の成功時の通知メッセージについて、I18n を使用せずに日本語文字列を直接記述する方針で一貫性を保っている。
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test

@karlley karlley self-assigned this Nov 17, 2025
@karlley
Copy link
Contributor Author

karlley commented Nov 17, 2025

@yokomaru
お疲れ様です!
レビューをお願いしたいのですが対応可能でしょうか?
急ぎでは無いです🙇‍♂️

@yokomaru
Copy link
Contributor

@karlley
karlleyさん、ご連絡遅くなり申し訳ありません!🙏
承知しました!1〜2週間ほどお時間いただけると助かります。よろしくお願いいたします。

@karlley
Copy link
Contributor Author

karlley commented Nov 19, 2025

@yokomaru

1〜2週間ほどお時間いただけると助かります。

承知しました!
よろしくお願いします!

@yokomaru yokomaru self-requested a review December 1, 2025 13:39
Copy link
Contributor

@yokomaru yokomaru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karlley
レビューギリギリになってしまい申し訳ありません!🙇‍♀️

動作は問題ありませんでした🙆ドラッグ&ドロップの実装方法とても勉強になりました!

1点だけ、他画面への影響の観点で気になった部分があったためコメントしました。
お手数ですが、ご確認いただければ幸いです🙏

if (!inputs) return null

inputs.forEach((input) => {
const dropZone = input.closest('.js-file-input')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app/javascript/fileinput.jsは共通モジュールだと思うので、今回の変更によって他の画面の画像選択フィールド(file_field)にもドラッグ&ドロップ機能が適用されているかと思います!

↑の部分は画像選択フィールド(file_field)が必ず.js-file-inputの内側にあることが前提になっていると思うので、念のためgit grep "js-file-input" app/viewsなどで、すべての画面で同じDOM構造になっているか確認しておいていただけると安心かなと思いました!(すでに確認済みでしたら申し訳ありません🙏)

DOM構造が統一されていればこの書き方でOKだと思います!🙆‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yokomaru

念のためgit grep "js-file-input" app/viewsなどで、すべての画面で同じDOM構造になっているか確認しておいていただけると安心かなと思いました!

ご指摘の通り他画面への影響の調査が不十分でした。
grepで絞込んで確認したところ全て同一のDOM構造でしたので問題が無いことが確認できました!
ご指摘ありがとうございました😄

Copy link
Contributor Author

@karlley karlley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yokomaru
レビューありがとうございます!
コメント返信しましたのでご確認お願いします。

if (!inputs) return null

inputs.forEach((input) => {
const dropZone = input.closest('.js-file-input')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yokomaru

念のためgit grep "js-file-input" app/viewsなどで、すべての画面で同じDOM構造になっているか確認しておいていただけると安心かなと思いました!

ご指摘の通り他画面への影響の調査が不十分でした。
grepで絞込んで確認したところ全て同一のDOM構造でしたので問題が無いことが確認できました!
ご指摘ありがとうございました😄

@yokomaru yokomaru self-requested a review December 1, 2025 21:39
Copy link
Contributor

@yokomaru yokomaru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご確認ありがとうございます!Approveさせていただきます!🙌

引き続きどうぞよろしくお願いいたします!

@karlley
Copy link
Contributor Author

karlley commented Dec 1, 2025

@yokomaru
確認ありがとうございます😄
引き続きよろしくお願いいたします!

@okuramasafumi
メンバーレビューが完了しましたのでレビューお願いいたします!

Copy link
Contributor

@okuramasafumi okuramasafumi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!


偶然かもしれませんが、dropzoneという名前のライブラリがあり、機能としてはまさしくドラッグ&ドロップだったりします。

https://www.dropzone.dev/

今のブートキャンプアプリには使われていないライブラリですが、今後入ったときに名前が同じで混乱を招く可能性がゼロとは言えません(動作には影響ないはず)。
今のうちに変数名を変更してもよいとは思うのですが、そこまで重要ではないとも思うので、approveしております。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/javascript/fileinput.js (1)

32-38: ドラッグ&ドロップ実装は概ねOKですが、change イベントのバブリングをネイティブ挙動に合わせたいです

  • .js-file-inputclosest で辿って drop ハンドラを足す構成は、既存の DOM 構造前提で自然だと思います 👍
  • 一方で、input.dispatchEvent(new Event('change')) はデフォルトだと bubbles: false なので、もし他のコードで「イベントデリゲーション(例: document / ラッパ要素に change をバインド)」している箇所があれば、ドラッグ&ドロップ時だけそのハンドラが動かない可能性があります。ネイティブの change に近づける意味でも、下記のようにしておくとより安全そうです。
-      input.dispatchEvent(new Event('change'))
+      input.dispatchEvent(new Event('change', { bubbles: true }))
  • ついでに、将来 .js-file-input input の DOM 構造を変えたときに備えて、dropArea が取得できなかった場合を防御的にケアしておくのもアリかなと思いました(必須ではないですが)。
-    const dropArea = input.closest('.js-file-input')
-    dropArea.addEventListener('dragover', (e) => e.preventDefault())
-    dropArea.addEventListener('drop', (e) => {
+    const dropArea = input.closest('.js-file-input')
+    if (!dropArea) return
+    dropArea.addEventListener('dragover', (e) => e.preventDefault())
+    dropArea.addEventListener('drop', (e) => {
       e.preventDefault()
       input.files = e.dataTransfer.files
       input.dispatchEvent(new Event('change'))
     })

上記2点はどちらも「将来の拡張・他コードとの連携を考えたときに安全側に寄せる」ための提案なので、今の要件だけであれば現状のままでも動作は問題なさそうです。

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab13734 and 54e468e.

📒 Files selected for processing (1)
  • app/javascript/fileinput.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
app/**/*.{rb,js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Rails app code should be organized in app/ directory with subdirectories: models/, controllers/, views/, jobs/, helpers/, and frontend code under javascript/ (Shakapacker)

Files:

  • app/javascript/fileinput.js
app/javascript/**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

JavaScript/TypeScript code in app/javascript/ should be linted with ESLint and formatted with Prettier via yarn lint scripts; use React 17 and Shakapacker/Webpack 5

Files:

  • app/javascript/fileinput.js
**/*.js

⚙️ CodeRabbit configuration file

**/*.js: - どうしても避けられない時以外に新規にVue.js, Reactのコードを追加しない。

  • fetchメソッドの代わりにrequest.jsを使う。

Files:

  • app/javascript/fileinput.js
🧠 Learnings (2)
📓 Common learnings
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/notifiers/discord_notifier.rb:131-135
Timestamp: 2025-09-12T21:18:00.834Z
Learning: Rails アップグレードPRにおいて、product_review_not_completed メソッドの webhook URL 設定の shared フォールバック追加も、設定システム全体の変更として別PRで対応すべきである。
📚 Learning: 2025-08-25T08:00:11.369Z
Learnt from: sjabcdefin
Repo: fjordllc/bootcamp PR: 9090
File: app/javascript/user-sns.js:2-25
Timestamp: 2025-08-25T08:00:11.369Z
Learning: app/javascript/user-sns.js において、アクセシビリティ改善(aria-label属性の追加など)は他の箇所との整合性を保つため、別途統一して対応する方針である

Applied to files:

  • app/javascript/fileinput.js
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test

@karlley karlley force-pushed the bug/portfolio-thumbnail-drag-drop branch from 54e468e to 3986db2 Compare December 8, 2025 09:32
@karlley
Copy link
Contributor Author

karlley commented Dec 8, 2025

@okuramasafumi
レビューありがとうございます!

偶然かもしれませんが、dropzoneという名前のライブラリがあり、機能としてはまさしくドラッグ&ドロップだったりします。

そうなんですね!
変数名をAIに相談して決めたのでライブラリ名に引っ張られたのかもしれませんね😅
念の為、変数名は変更しておきました。

@komagata
メンターレビューが完了しましたのでマージお願いします。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants