Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/javascript/components/ListComment.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { UserIconFrameClass } from './UserIconFrameClass'
import userIconFrameClass from '../user-icon-frame-class.js'

export default function ListComment({ report }) {
return (
Expand All @@ -21,7 +21,11 @@ export default function ListComment({ report }) {
className="card-list-item__user-icons-icon"
href={`/users/${comment.user_id}`}
key={comment.user_id}>
<span className={UserIconFrameClass(comment)}>
<span
className={userIconFrameClass(
comment.primary_role,
comment.joining_status
)}>
<img className="a-user-icon" src={comment.user_icon} />
</span>
</a>
Expand Down
7 changes: 4 additions & 3 deletions app/javascript/components/NotificationsBell/Notifications.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import LoadingListPlaceholder from '../LoadingListPlaceholder'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import { UserIconFrameClass } from '../UserIconFrameClass'
import userIconFrameClass from '../../user-icon-frame-class.js'
dayjs.extend(relativeTime)

export default function Notifications({ notifications, targetStatus }) {
Expand Down Expand Up @@ -58,8 +58,9 @@ function Notification({ notification }) {
className="header-dropdown__item-link unconfirmed_link">
<div className="header-notifications-item__body">
<span
className={`${UserIconFrameClass(
notification.sender
className={`${userIconFrameClass(
notification.sender.primary_role,
notification.sender.joining_status
)} header-notifications-item__user-icon`}>
<img
src={notification.sender.avatar_url}
Expand Down
8 changes: 6 additions & 2 deletions app/javascript/components/Report.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import ListComment from './ListComment'
import { UserIconFrameClass } from './UserIconFrameClass'
import userIconFrameClass from '../user-icon-frame-class.js'

export default function Report({ report, currentUserId, displayUserIcon }) {
return (
Expand Down Expand Up @@ -70,7 +70,11 @@ const DisplayUserIcon = ({ report }) => {
return (
<div className="card-list-item__user">
<a href={report.user.url} className="card-list-item__user-link">
<span className={UserIconFrameClass(report.user)}>
<span
className={userIconFrameClass(
report.user.primary_role,
report.user.joining_status
)}>
<img
className="card-list-item__user-icon a-user-icon"
src={report.user.avatar_url}
Expand Down
5 changes: 0 additions & 5 deletions app/javascript/components/UserIconFrameClass.jsx

This file was deleted.

7 changes: 7 additions & 0 deletions app/javascript/user-icon-frame-class.js
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

元ファイルは引数にuserを受け取っていましたが、本ファイルではロールとステータスの2つをそれぞれ受け取るようにした理由はなんでしょうか??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

引数がuser になっていましたが、実際の呼び出しの引数はUserIconFrameClass(comment)UserIconFrameClass(notification.sender) のようになっておりuser という変数名が適切では無いと感じたためです。
引数を2つに分けることで呼び出し時の引数を明確にすることを意図していました。

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function userIconFrameClass(primaryRole, joiningStatus) {
const primaryRoleClass = primaryRole ? `is-${primaryRole}` : ''
const newUserClass = joiningStatus === 'new-user' ? 'is-new-user' : ''
return ['a-user-role', primaryRoleClass, newUserClass]
.filter(Boolean)
.join(' ')
}