Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Bug 1603610: Enable users to leave comments on translations (#1524)
Note: The feature is currently disabled in the UI.
- Loading branch information
Showing
38 changed files
with
985 additions
and
215 deletions.
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
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,19 @@ | ||
/* @flow */ | ||
|
||
import APIBase from './base'; | ||
|
||
|
||
export default class CommentAPI extends APIBase { | ||
add(comment: string, translationId: number) { | ||
const payload = new URLSearchParams(); | ||
payload.append('comment', comment); | ||
payload.append('translationId', translationId.toString()); | ||
|
||
const headers = new Headers(); | ||
const csrfToken = this.getCSRFToken(); | ||
headers.append('X-Requested-With', 'XMLHttpRequest'); | ||
headers.append('X-CSRFToken', csrfToken); | ||
|
||
return this.fetch('/add-comment/', 'POST', payload, headers); | ||
} | ||
} |
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
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,10 @@ | ||
.comments-list .add-comment textarea { | ||
background-color: #333941; | ||
border: none; | ||
border-radius: 4px; | ||
color: #FFFFFF; | ||
font-size: 11px; | ||
height: 24px; | ||
line-height: 24px; | ||
padding: 6px; | ||
} |
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,76 @@ | ||
/* @flow */ | ||
|
||
import * as React from 'react'; | ||
import { Localized } from '@fluent/react'; | ||
|
||
import './AddComment.css'; | ||
|
||
import { UserAvatar } from 'core/user' | ||
|
||
type Props = {| | ||
user: string, | ||
username: string, | ||
imageURL: string, | ||
translationId: number, | ||
addComment: (string, number) => void, | ||
|}; | ||
|
||
|
||
export default function AddComments(props: Props) { | ||
const { | ||
user, | ||
username, | ||
imageURL, | ||
translationId, | ||
addComment, | ||
} = props; | ||
|
||
let commentInput: any = React.useRef(); | ||
|
||
if (!user) { | ||
return null; | ||
} | ||
|
||
const onEnterSubmit = (event: SyntheticKeyboardEvent<HTMLTextAreaElement>) => { | ||
if (event.keyCode === 13 && event.shiftKey === false) { | ||
event.preventDefault(); | ||
submitComment(event); | ||
} | ||
} | ||
|
||
const submitComment = (event: SyntheticKeyboardEvent<>) => { | ||
event.preventDefault(); | ||
const comment = commentInput.current.value; | ||
|
||
if (!comment) { | ||
return null; | ||
} | ||
|
||
addComment(comment, translationId); | ||
commentInput.current.value = ''; | ||
}; | ||
|
||
return <div className='comment add-comment'> | ||
<UserAvatar | ||
user={ user } | ||
username={ username } | ||
title='' | ||
imageUrl={ imageURL } | ||
/> | ||
<form className='container'> | ||
<Localized | ||
id='comments-AddComment--input' | ||
attrs={{ placeholder: true }} | ||
> | ||
<textarea | ||
id='comment-input' | ||
name='comment' | ||
dir='auto' | ||
placeholder={ `Write a comment…` } | ||
ref={ commentInput } | ||
onKeyDown={ onEnterSubmit } | ||
/> | ||
</Localized> | ||
</form> | ||
</div> | ||
} |
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,29 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import sinon from 'sinon'; | ||
|
||
import AddComment from './AddComment'; | ||
|
||
|
||
const DEFAULT_USER = { | ||
user: 'RSwanson', | ||
username: 'Ron_Swanson', | ||
imageURL: '', | ||
} | ||
|
||
describe('<AddComment>', () => { | ||
it('calls submitComment function', () => { | ||
const submitCommentFn = sinon.spy(); | ||
const wrapper = shallow(<AddComment | ||
{ ...DEFAULT_USER } | ||
submitComment={ submitCommentFn } | ||
/>); | ||
|
||
const event = { | ||
preventDefault: sinon.spy(), | ||
}; | ||
|
||
wrapper.find('form').simulate('submit', event); | ||
expect(submitCommentFn.calledOnce).toBeTruthy; | ||
}); | ||
}); |
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,30 @@ | ||
.comments-list ul .comment { | ||
padding-bottom: 10px; | ||
} | ||
|
||
.comments-list .comment a { | ||
color: #7BC876; | ||
font-weight: 400; | ||
} | ||
|
||
.comments-list .comment .content { | ||
background-color: #4d5967; | ||
border: solid 1px #4d5967; | ||
border-radius: 4px; | ||
display: flex; | ||
font-size: 11px; | ||
padding: 6px; | ||
} | ||
|
||
.comments-list .comment .content p { | ||
color: #CCCCCC; | ||
margin-left: 4px; | ||
} | ||
|
||
.comments-list .comment .info { | ||
color: #AAAAAA; | ||
font-size: 11px; | ||
font-weight: 300; | ||
margin-top: -2px; | ||
padding-left: 8px; | ||
} |
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,54 @@ | ||
/* @flow */ | ||
|
||
import * as React from 'react'; | ||
import ReactTimeAgo from 'react-time-ago'; | ||
|
||
import './Comment.css'; | ||
|
||
import { UserAvatar } from 'core/user' | ||
|
||
import type { TranslationComment } from 'core/api'; | ||
|
||
|
||
type Props = {| | ||
comment: TranslationComment, | ||
|}; | ||
|
||
|
||
export default function Comment(props: Props) { | ||
const { comment } = props; | ||
|
||
if (!comment) { | ||
return null; | ||
} | ||
|
||
return <li className='comment'> | ||
<UserAvatar | ||
user={ comment.author } | ||
username={ comment.username } | ||
imageUrl={ comment.userGravatarUrlSmall } | ||
/> | ||
<div className='container'> | ||
<div className='content' dir='auto'> | ||
<a | ||
href={ `/contributors/${comment.username}` } | ||
target='_blank' | ||
rel='noopener noreferrer' | ||
onClick={ (e: SyntheticMouseEvent<>) => e.stopPropagation() } | ||
> | ||
{ comment.author } | ||
</a> | ||
<p> | ||
{ comment.content } | ||
</p> | ||
</div> | ||
<div className='info'> | ||
<ReactTimeAgo | ||
dir='ltr' | ||
date={ new Date(comment.dateIso) } | ||
title={ `${comment.createdAt} UTC` } | ||
/> | ||
</div> | ||
</div> | ||
</li> | ||
} |
Oops, something went wrong.