Skip to content

Commit

Permalink
umputun#10 add more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Mavrin committed Feb 17, 2020
1 parent 5706b3f commit 0ea9a48
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 18 deletions.
7 changes: 6 additions & 1 deletion frontend/app/components/comment/comment.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,12 @@ describe('<Comment />', () => {
.props()
).toEqual(expect.objectContaining({ defaultMessage: 'Hide' }));
expect(controls.at(3).getDOMNode().childNodes[0].textContent).toEqual('Block');
expect(controls.at(4).text()).toEqual('Delete');
expect(
controls
.at(4)
.find('FormattedMessage')
.props()
).toEqual(expect.objectContaining({ defaultMessage: 'Delete' }));
});

it('for regular user it shows only "hide"', () => {
Expand Down
37 changes: 28 additions & 9 deletions frontend/app/components/comment/comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ import postMessage from '@app/utils/postMessage';
import { FormattedMessage, useIntl, IntlShape, defineMessages } from 'react-intl';

defineMessages({
'comment.delete': {
id: 'comment.delete',
'comment.delete-message': {
id: 'comment.delete-message',
defaultMessage: 'Do you want to delete this comment?',
},
'comment.hide-user-comment': {
id: 'comment.hide-user-comment',
defaultMessage: 'Do you want to hide comments of {userName}?',
},
});

export type Props = {
Expand Down Expand Up @@ -229,8 +233,8 @@ export class Comment extends Component<Props, State> {

deleteComment = () => {
const deleteComment = this.props.intl.formatMessage({
id: 'comment.delete',
defaultMessage: 'comment.delete',
id: 'comment.delete-message',
defaultMessage: 'comment.delete-message',
});
if (confirm(deleteComment)) {
this.props.setReplyEditState!({ id: this.props.data.id, state: CommentMode.None });
Expand All @@ -240,7 +244,14 @@ export class Comment extends Component<Props, State> {
};

hideUser = () => {
if (!confirm(`Do you want to hide comments of ${this.props.data.user.name}?`)) return;
const hideUserComment = this.props.intl.formatMessage(
{
id: 'comment.hide-user-comment',
defaultMessage: 'comment.hide-user-comment',
},
{ userName: this.props.data.user.name }
);
if (!confirm(hideUserComment)) return;
this.props.hideUser!(this.props.data.user);
};

Expand Down Expand Up @@ -452,7 +463,7 @@ export class Comment extends Component<Props, State> {
if (!this.props.data.delete) {
controls.push(
<Button kind="link" {...getHandleClickProps(this.deleteComment)} mix="comment__control">
Delete
<FormattedMessage id="comment.delete" defaultMessage="Delete" />
</Button>
);
}
Expand Down Expand Up @@ -686,7 +697,11 @@ export class Comment extends Component<Props, State> {
<div className="comment__actions">
{!props.data.delete && !props.isCommentsDisabled && !props.disabled && !isGuest && props.view === 'main' && (
<Button kind="link" {...getHandleClickProps(this.toggleReplying)} mix="comment__action">
{isReplying ? 'Cancel' : 'Reply'}
{isReplying ? (
<FormattedMessage id="comment.cancel" defaultMessage="Cancel" />
) : (
<FormattedMessage id="comment.reply" defaultMessage="Reply" />
)}
</Button>
)}
{!props.data.delete &&
Expand All @@ -700,15 +715,19 @@ export class Comment extends Component<Props, State> {
{...getHandleClickProps(this.toggleEditing)}
mix={['comment__action', 'comment__action_type_edit']}
>
{isEditing ? 'Cancel' : 'Edit'}
{isEditing ? (
<FormattedMessage id="comment.cancel" defaultMessage="Cancel" />
) : (
<FormattedMessage id="comment.edit" defaultMessage="Edit" />
)}
</Button>,
!isAdmin && (
<Button
kind="link"
{...getHandleClickProps(this.deleteComment)}
mix={['comment__action', 'comment__action_type_delete']}
>
Delete
<FormattedMessage id="comment.delete" defaultMessage="Delete" />
</Button>
),
state.editDeadline && (
Expand Down
13 changes: 9 additions & 4 deletions frontend/app/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
"commentForm.save": "Save",
"commentForm.replay": "Replay",
"comment.hide": "Hide",
"comment.time": "{day} at {time}",
"comment.delete": "Do you want to delete this comment?",
"commentForm.preview": "Preview",
"authPanel.logout": "Logout?",
"authPanel.login": "Login:",
"authPanel.logged-as": "You logged in as"
}
"authPanel.logged-as": "You logged in as",
"comment.hide-user-comment": "Do you want to hide comments of {userName}?",
"comment.reply": "Reply",
"comment.edit": "Edit",
"comment.delete-message": "Do you want to delete this comment?",
"comment.delete": "Delete",
"comment.time": "{day} at {time}",
"comment.cancel": "Cancel"
}
13 changes: 9 additions & 4 deletions frontend/app/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
"commentForm.save": "Сохранить",
"commentForm.replay": "Ответить",
"comment.hide": "Спрятать",
"comment.time": "{day} в {time}",
"comment.delete": "Удалить комментарий?",
"comment.delete-message": "Удалить комментарий?",
"commentForm.preview": "Предпросмотр",
"authPanel.logout": "Выйти?",
"authPanel.login": "Вход:",
"authPanel.logged-as": "Вы вошли как"
}
"authPanel.logged-as": "Вы вошли как",
"comment.hide-user-comment": "Do you want to hide comments of {userName}?",
"comment.cancel": "Отменить",
"comment.reply": "Ответить",
"comment.edit": "Редактировать",
"comment.delete": "Удалить",
"comment.time": "{day} в {time}"
}

0 comments on commit 0ea9a48

Please sign in to comment.