-
Notifications
You must be signed in to change notification settings - Fork 71
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
通知一覧をVue.jsで非同期にした #2260
Merged
Merged
通知一覧をVue.jsで非同期にした #2260
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
13efe69
viewからkaminariの記述を削除
sano11o1 e935ae2
vuejs-paginateを導入
sano11o1 9e3b271
既存のNotificationsをNotificationsBellに変更
sano11o1 2e98d3f
notificationsのJSONを返すようにした
sano11o1 fbcc055
通知一覧をviewからvueに移行
sano11o1 b8c14c4
未読の通知一覧を非同期で読み込むようにした
sano11o1 b2b4cd1
通知一覧にページャーを追加
sano11o1 d0fc1ac
vuejs-paginateで生成されるページャーのデザインを追記
sano11o1 e630bac
コントローラーの不要な記述を削除
sano11o1 c006442
通知一覧のページャーのテストを追記
sano11o1 2b45c9c
未読の通知を一括で開くボタンをVue化
sano11o1 cb5a6de
未読の通知を一括で開くボタンが表示されることを確認するテストを修正
sano11o1 266afea
通知一覧のページャーのテストを修正
sano11o1 d8da559
通知のvueファイル、jsファイルの細かな点を修正
sano11o1 526bf4b
notifications/index.json.jbuilderに書いてあったcreated_at系の記述を減らした
sano11o1 e20315e
_notification.html.slim はVueに置き換えたので削除
sano11o1 4742dd8
mentorLoginプロパティをisMentorプロパティに変更
sano11o1 0ee7afc
ページャーの位置調整、disabledのぺージャーリンクを目立たない表示に変更
machida 68fccd4
ページャーが表示されないときは、そのDOMが表示されないようにした
machida 37f5471
ページャーのデザイン変更に合わせてテストを修正
sano11o1 91f9f6d
Notificationsのintegrationテストを書きました
sano11o1 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 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 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,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class API::Notifications::UnreadController < API::BaseController | ||
def index | ||
@notifications = if params[:page] | ||
current_user.notifications | ||
.unreads_with_avatar | ||
.order(created_at: :desc) | ||
.page(params[:page]) | ||
else | ||
current_user.notifications.unreads_with_avatar | ||
end | ||
render template: 'api/notifications/index' | ||
end | ||
end |
This file contains 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 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 |
---|---|---|
@@ -1,10 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class Notifications::UnreadController < ApplicationController | ||
def index | ||
@notifications = current_user.notifications | ||
.unreads_with_avatar | ||
.order(created_at: :desc) | ||
.page(params[:page]) | ||
end | ||
def index; end | ||
end |
This file contains 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 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,35 @@ | ||
<template lang="pug"> | ||
.thread-list-item(:class="notification.read ? 'is-read' : 'is-unread'") | ||
.thread-list-item__inner | ||
.thread-list-item__author | ||
img.thread-list-item__author-icon.a-user-icon(:title="notification.sender.icon_title" :src="notification.sender.avatar_url" :class="[roleClass, daimyoClass]") | ||
header.thread-list-item__header | ||
.thread-list-item__header-title-container | ||
.thread-list-item__header-icon.is-unread(v-if='notification.read === false') | ||
| 未読 | ||
h2.thread-list-item__title(itemprop='name') | ||
a.thread-list-item__title-link.js-unconfirmed-link(:href="notification.path" itemprop='url') | ||
span.thread-list-item__title-link-label {{ notification.message }} | ||
.thread-list-item-meta | ||
time.thread-list-item-meta__created-at(:datetime='notification.created_at') {{ formattedCreatedAtInJapanese }} | ||
</template> | ||
<script> | ||
import dayjs from 'dayjs' | ||
import ja from 'dayjs/locale/ja' | ||
dayjs.locale(ja) | ||
|
||
export default { | ||
props: ['notification'], | ||
computed: { | ||
formattedCreatedAtInJapanese() { | ||
return dayjs(this.notification.created_at).format('YYYY年MM月DD日(ddd) HH:mm') | ||
}, | ||
roleClass() { | ||
return `is-${this.notification.sender.role}` | ||
}, | ||
daimyoClass() { | ||
return { 'is-daimyo': this.notification.sender.daimyo } | ||
} | ||
} | ||
} | ||
</script> |
This file contains 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 |
---|---|---|
@@ -1,32 +1,18 @@ | ||
import Vue from 'vue' | ||
import Notifications from './notifications.vue' | ||
import NotificationsMobile from './notifications_mobile.vue' | ||
import isMobile from 'ismobilejs' | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
if (isMobile(window.navigator).any) { | ||
const notifications = document.querySelector('#js-notifications') | ||
if (notifications) { | ||
notifications.style.display = 'none' | ||
} | ||
|
||
const notificationsMobile = document.querySelector('#js-notifications-mobile') | ||
if (notificationsMobile) { | ||
new Vue({ | ||
render: h => h(NotificationsMobile) | ||
}).$mount('#js-notifications-mobile') | ||
} | ||
} else { | ||
const notificationsMobile = document.querySelector('#js-notifications-mobile') | ||
if (notificationsMobile) { | ||
notificationsMobile.style.display = 'none' | ||
} | ||
|
||
const notifications = document.querySelector('#js-notifications') | ||
if (notifications) { | ||
new Vue({ | ||
render: h => h(Notifications) | ||
}).$mount('#js-notifications') | ||
} | ||
const selector = '#js-notifications' | ||
const notifications = document.querySelector(selector) | ||
if (notifications) { | ||
const isMentor = notifications.getAttribute('data-is-mentor') | ||
new Vue({ | ||
render: h => h(Notifications, { | ||
props: { | ||
// 文字列を真偽値に変換して渡す | ||
isMentor: isMentor === 'true' | ||
} | ||
}) | ||
}).$mount(selector) | ||
} | ||
}) |
This file contains 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 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,32 @@ | ||
import Vue from 'vue' | ||
import NotificationsBell from './notifications_bell.vue' | ||
import NotificationsBellMobile from './notifications_bell_mobile.vue' | ||
import isMobile from 'ismobilejs' | ||
|
||
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. notifications_bellいい名前だと思います! |
||
document.addEventListener('DOMContentLoaded', () => { | ||
if (isMobile(window.navigator).any) { | ||
const notifications = document.querySelector('#js-notifications-bell') | ||
if (notifications) { | ||
notifications.style.display = 'none' | ||
} | ||
|
||
const notificationsBellMobile = document.querySelector('#js-notifications-bell-mobile') | ||
if (notificationsBellMobile) { | ||
new Vue({ | ||
render: h => h(NotificationsBellMobile) | ||
}).$mount('#js-notifications-bell-mobile') | ||
} | ||
} else { | ||
const notificationsBellMobile = document.querySelector('#js-notifications-bell-mobile') | ||
if (notificationsBellMobile) { | ||
notificationsBellMobile.style.display = 'none' | ||
} | ||
|
||
const notificationsBell = document.querySelector('#js-notifications-bell') | ||
if (notificationsBell) { | ||
new Vue({ | ||
render: h => h(NotificationsBell) | ||
}).$mount('#js-notifications-bell') | ||
} | ||
} | ||
}) |
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.
すいません、他のレビューで気づいた点をひとつ。
下記のようなAPIのテストがあるとよりよりかもです。
https://github.com/fjordllc/bootcamp/blob/master/test/integration/api/practices_test.rb
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.
@komagata
APIのテストを書きましたので確認お願いします! 🙏