-
Notifications
You must be signed in to change notification settings - Fork 75
通知機能一覧をReactからRails viewとJSに移行しました #9273
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8ec339c
railsviewとJSで書き換えた
smallmonkeykey bdeef0b
reactのファイルを削除
smallmonkeykey b846fa4
定数を追加
smallmonkeykey f556556
QueryObjectパターンで書き換えた
smallmonkeykey 4411be6
NotificationsControllerのロジックを整理し、絞り込み処理をQueryObjectへ移行
smallmonkeykey 874a3ea
notifications_testをmainの最新に更新
smallmonkeykey 07803f2
不要なクラスを削除
smallmonkeykey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| document.addEventListener('DOMContentLoaded', () => { | ||
| const notificationPage = document.querySelector('#notifications') | ||
| if (!notificationPage) return | ||
|
|
||
| const allOpenButton = document.querySelector( | ||
| '#js-shortcut-unconfirmed-links-open' | ||
| ) | ||
| if (!allOpenButton) return | ||
|
|
||
| allOpenButton.addEventListener('click', () => { | ||
| document.querySelector('.card-list')?.remove() | ||
| allOpenButton.closest('.card-footer')?.remove() | ||
| document.querySelector('.a-border-tint')?.remove() | ||
|
|
||
| const container = document.querySelector('.page-content') | ||
| if (container) { | ||
| container.innerHTML = ` | ||
| <div class="o-empty-message"> | ||
| <div class="o-empty-message__icon"> | ||
| <div class="i fa-regular fa-smile"></div> | ||
| </div> | ||
| <p class="o-empty-message__text">未読の通知はありません</p> | ||
| </div> | ||
| ` | ||
| } | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| nav.pill-nav | ||
| .container | ||
| ul.pill-nav__items | ||
| li.pill-nav__item | ||
| = link_to '未読', | ||
| notifications_path(status: 'unread', target: params[:target]), | ||
| class: "pill-nav__item-link #{params[:status] == 'unread' ? 'is-active' : ''}" | ||
|
|
||
| li.pill-nav__item | ||
| = link_to '全て', | ||
| notifications_path(target: params[:target]), | ||
| class: "pill-nav__item-link #{params[:status] == 'unread' ? '' : 'is-active'}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. もともと |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| - read_class = notification.read? ? 'is-read' : 'is-unread' | ||
|
|
||
| .card-list-item class=read_class | ||
| .card-list-item__inner | ||
| .card-list-item__user | ||
| = link_to user_path(notification.sender), class: 'card-list-item__user-link' do | ||
| = image_tag notification.sender.avatar_url, | ||
| class: 'card-list-item__user-icon a-user-icon', | ||
| alt: notification.sender.login_name | ||
|
|
||
| .card-list-item__rows | ||
| .card-list-item__row | ||
| .card-list-item-title | ||
| .card-list-item-title__start | ||
| - if !notification.read? | ||
| .a-list-item-badge.is-unread | ||
| span 未読 | ||
|
|
||
| h2.card-list-item-title__title[itemProp="name"] | ||
| = link_to notification.path, | ||
| class: 'card-list-item-title__link a-text-link js-unconfirmed-link', | ||
| itemProp: 'url' do | ||
| span.card-list-item-title__link-label = notification.message | ||
|
|
||
| .card-list-item__row | ||
| .card-list-item-meta | ||
| .card-list-item-meta__items | ||
| .card-list-item-meta__item | ||
| time.a-meta dateTime=notification.created_at | ||
| = l(notification.created_at, format: :long) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
#9184 (review)
を読んでいて思ったのですが、通知に関してはリロードすれば未読通知や「一括で開く」ボタンは消えるのではないかなと思いました(違っていたらすみません)
現状だと、
app/javascript/unconfirmed-links-open.jsとapp/javascript/notifications_remove_after_open.jsで処理が別れていますが、上記のプルリクエストのようにapp/javascript/unconfirmed-links-open.js内でlocation.reload()を行えばDOMの削除や置き換えが不要になるのではないかなと思いましたがいかがでしょうか?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.
コメントありがとうございます!
ページリロードについては検討したのですが、ページをリロードするとすべてを読み込むため、一部差し換えのほうが処理負担がかからないのではないかと思いこの実装にしてみました。
Junさんはこの点についてどう思われますか?
リロードのほうがすっきりするとは思いますので、特に問題なければリロードに差し替えます!
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.
確かにその通りだと思います🙋♂️
一方で、一括で開くボタンを押した時点で複数タブでページを読み込み始めているので、もう一枚リロードによる読み込みが増えても変わらないのでは?とも思いました。
もう一点理由というか気になった点があり、#9184 で未確認のリンクを一括で開くボタン(UnconfirmedLink.jsx)をバニラJSで実装しており、通知一覧ページのボタンもそれらの修正に含まれます。
本来なら一括で開くボタンの修正は#9184 で行うべきで、このPRで修正しなくて良い箇所だと思いました。安定を取るなら#9184 マージされるのを待っても良い気がします。そのまま進めるなら未読通知を一括で開くボタンを押したときの処理はなるべく#9184 の実装に合わせた方が後々コンフリクトが起きた際も修正しやすいのではと思いました。
ちょっとこのあたり認識が間違っていたら申し訳ありませんが気になったのでコメント致しました🙇♂️
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.
この点について改めて考えたのですが、やはりリロードではなく部分更新の方が良いのではと思いました。
例えば、Reactなどのクライアント側で状態を管理する実装を想定した場合、ページ遷移を伴わずに要素を操作するケースでは、リロードではなく、状態更新によって表示を切り替えるのが一般的だと思います。
リロードすれば結果的に画面は更新されますが、それを前提にしてしまうと、クライアント側で状態や表示を制御している意味が薄れてしまうのではと思いました。
こちらに関してなのですが現在のmainの一括で開くJSの処理
app/javascript/unconfirmed-links-open.jsは以下のようになっています。#9184 の
app/javascript/unconfirmed-links-open.jsを確認したところ、が追加されおりjunさんのおっしゃる通り、このファイルの変更の箇所はいらなくなると思います。
しかし現在のmainでは一括処理のみのJSしかない形なので、画面を変更する箇所は必要だと思いました。
またどちらが先にマージされるかはわからないですが、仮にどちらがされてもこのファイルを削除するだけで対応できると思うので、現時点では大きなバッティングや解消が難しいコンフリクトにはならないと考えています!
もし認識がずれていればご指摘いただけると助かります。