mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 19:57:52 +01:00
100 lines
2.5 KiB
TypeScript
100 lines
2.5 KiB
TypeScript
|
|
import * as React from 'react';
|
||
|
|
import I18n from 'i18n-js';
|
||
|
|
import Button from '../common/Button';
|
||
|
|
|
||
|
|
interface Props {
|
||
|
|
id: number;
|
||
|
|
initialBody: string;
|
||
|
|
initialIsPostUpdate: boolean;
|
||
|
|
|
||
|
|
isPowerUser: boolean;
|
||
|
|
|
||
|
|
handleUpdateComment(body: string, isPostUpdate: boolean): void;
|
||
|
|
toggleEditMode(): void;
|
||
|
|
}
|
||
|
|
|
||
|
|
interface State {
|
||
|
|
body: string;
|
||
|
|
isPostUpdate: boolean;
|
||
|
|
}
|
||
|
|
|
||
|
|
class CommentEditForm extends React.Component<Props, State> {
|
||
|
|
constructor(props) {
|
||
|
|
super(props);
|
||
|
|
|
||
|
|
this.state = {
|
||
|
|
body: '',
|
||
|
|
isPostUpdate: false,
|
||
|
|
};
|
||
|
|
|
||
|
|
this.handleCommentBodyChange = this.handleCommentBodyChange.bind(this);
|
||
|
|
this.handleCommentIsPostUpdateChange = this.handleCommentIsPostUpdateChange.bind(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
componentDidMount() {
|
||
|
|
this.setState({
|
||
|
|
body: this.props.initialBody,
|
||
|
|
isPostUpdate: this.props.initialIsPostUpdate,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
handleCommentBodyChange(newCommentBody: string) {
|
||
|
|
this.setState({ body: newCommentBody });
|
||
|
|
}
|
||
|
|
|
||
|
|
handleCommentIsPostUpdateChange(newIsPostUpdate: boolean) {
|
||
|
|
this.setState({ isPostUpdate: newIsPostUpdate });
|
||
|
|
}
|
||
|
|
|
||
|
|
render() {
|
||
|
|
const { id, isPowerUser, handleUpdateComment, toggleEditMode } = this.props;
|
||
|
|
const { body, isPostUpdate } = this.state;
|
||
|
|
|
||
|
|
return (
|
||
|
|
<div className="editCommentForm">
|
||
|
|
<textarea
|
||
|
|
value={body}
|
||
|
|
onChange={e => this.handleCommentBodyChange(e.target.value)}
|
||
|
|
className="commentForm"
|
||
|
|
/>
|
||
|
|
|
||
|
|
<div>
|
||
|
|
<div>
|
||
|
|
{
|
||
|
|
isPowerUser ?
|
||
|
|
<>
|
||
|
|
<input
|
||
|
|
id={`isPostUpdateFlagComment${id}`}
|
||
|
|
type="checkbox"
|
||
|
|
onChange={e => this.handleCommentIsPostUpdateChange(e.target.checked)}
|
||
|
|
checked={isPostUpdate || false}
|
||
|
|
/>
|
||
|
|
|
||
|
|
<label htmlFor={`isPostUpdateFlagComment${id}`}>
|
||
|
|
{I18n.t('post.new_comment.is_post_update')}
|
||
|
|
</label>
|
||
|
|
</>
|
||
|
|
:
|
||
|
|
null
|
||
|
|
}
|
||
|
|
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div>
|
||
|
|
<a className="commentLink" onClick={toggleEditMode}>
|
||
|
|
{ I18n.t('common.buttons.cancel') }
|
||
|
|
</a>
|
||
|
|
|
||
|
|
<Button
|
||
|
|
onClick={() => handleUpdateComment(body, isPostUpdate)}
|
||
|
|
>
|
||
|
|
{ I18n.t('common.buttons.update') }
|
||
|
|
</Button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export default CommentEditForm;
|