1 import { Component } from "inferno";
2 import { T } from "inferno-i18next-dess";
3 import { Link } from "inferno-router";
4 import { CreateComment, EditComment, Language } from "lemmy-js-client";
5 import { i18n } from "../../i18next";
6 import { CommentNodeI } from "../../interfaces";
7 import { UserService } from "../../services";
8 import { capitalizeFirstLetter, myAuthRequired } from "../../utils";
9 import { Icon } from "../common/icon";
10 import { MarkdownTextArea } from "../common/markdown-textarea";
12 interface CommentFormProps {
14 * Can either be the parent, or the editable comment. The right side is a postId.
16 node: CommentNodeI | number;
21 onReplyCancel?(): void;
22 allLanguages: Language[];
23 siteLanguages: number[];
24 containerClass?: string;
25 onUpsertComment(form: EditComment | CreateComment): void;
28 export class CommentForm extends Component<CommentFormProps, any> {
29 constructor(props: any, context: any) {
30 super(props, context);
32 this.handleCommentSubmit = this.handleCommentSubmit.bind(this);
36 const initialContent =
37 typeof this.props.node !== "number"
39 ? this.props.node.comment_view.comment.content
45 className={["comment-form", "mb-3", this.props.containerClass].join(
49 {UserService.Instance.myUserInfo ? (
51 initialContent={initialContent}
53 buttonTitle={this.buttonTitle}
54 finished={this.props.finished}
55 replyType={typeof this.props.node !== "number"}
56 focus={this.props.focus}
57 disabled={this.props.disabled}
58 onSubmit={this.handleCommentSubmit}
59 onReplyCancel={this.props.onReplyCancel}
60 placeholder={i18n.t("comment_here")}
61 allLanguages={this.props.allLanguages}
62 siteLanguages={this.props.siteLanguages}
65 <div className="alert alert-warning" role="alert">
66 <Icon icon="alert-triangle" classes="icon-inline me-2" />
67 <T i18nKey="must_login" class="d-inline">
69 <Link className="alert-link" to="/login">
79 get buttonTitle(): string {
80 return typeof this.props.node === "number"
81 ? capitalizeFirstLetter(i18n.t("post"))
83 ? capitalizeFirstLetter(i18n.t("save"))
84 : capitalizeFirstLetter(i18n.t("reply"));
87 handleCommentSubmit(content: string, form_id: string, language_id?: number) {
88 const { node, onUpsertComment, edit } = this.props;
89 if (typeof node === "number") {
96 auth: myAuthRequired(),
100 const comment_id = node.comment_view.comment.id;
106 auth: myAuthRequired(),
109 const post_id = node.comment_view.post.id;
110 const parent_id = node.comment_view.comment.id;
111 this.props.onUpsertComment({
117 auth: myAuthRequired(),