+import { myAuthRequired } from "@utils/app";
+import { capitalizeFirstLetter } from "@utils/helpers";
import { Component, InfernoMouseEvent, linkEvent } from "inferno";
import { EditSite, Tagline } from "lemmy-js-client";
-import { i18n } from "../../i18next";
-import { capitalizeFirstLetter, myAuthRequired } from "../../utils";
+import { I18NextService } from "../../services";
import { HtmlTags } from "../common/html-tags";
import { Icon, Spinner } from "../common/icon";
import { MarkdownTextArea } from "../common/markdown-textarea";
interface TaglineFormProps {
taglines: Array<Tagline>;
onSaveSite(form: EditSite): void;
+ loading: boolean;
}
interface TaglineFormState {
taglines: Array<string>;
- loading: boolean;
editingRow?: number;
}
export class TaglineForm extends Component<TaglineFormProps, TaglineFormState> {
state: TaglineFormState = {
- loading: false,
editingRow: undefined,
taglines: this.props.taglines.map(x => x.content),
};
super(props, context);
}
get documentTitle(): string {
- return i18n.t("taglines");
- }
-
- componentWillReceiveProps() {
- this.setState({ loading: false });
+ return I18NextService.i18n.t("taglines");
}
render() {
return (
- <div className="col-12">
+ <div className="tagline-form col-12">
<HtmlTags
title={this.documentTitle}
path={this.context.router.route.match.url}
/>
- <h5 className="col-12">{i18n.t("taglines")}</h5>
+ <h1 className="h4 mb-4">{I18NextService.i18n.t("taglines")}</h1>
<div className="table-responsive col-12">
<table id="taglines_table" className="table table-sm table-hover">
<thead className="pointer">
{ i: this, index: index },
this.handleEditTaglineClick
)}
- data-tippy-content={i18n.t("edit")}
- aria-label={i18n.t("edit")}
+ data-tippy-content={I18NextService.i18n.t("edit")}
+ aria-label={I18NextService.i18n.t("edit")}
>
- <Icon icon="edit" classes={`icon-inline`} />
+ <Icon icon="edit" classes="icon-inline" />
</button>
<button
{ i: this, index: index },
this.handleDeleteTaglineClick
)}
- data-tippy-content={i18n.t("delete")}
- aria-label={i18n.t("delete")}
+ data-tippy-content={I18NextService.i18n.t("delete")}
+ aria-label={I18NextService.i18n.t("delete")}
>
- <Icon icon="trash" classes={`icon-inline text-danger`} />
+ <Icon icon="trash" classes="icon-inline text-danger" />
</button>
</td>
</tr>
))}
</tbody>
</table>
- <div className="form-group row">
+ <div className="mb-3 row">
<div className="col-12">
<button
- className="btn btn-sm btn-secondary mr-2"
+ className="btn btn-sm btn-secondary me-2"
onClick={linkEvent(this, this.handleAddTaglineClick)}
>
- {i18n.t("add_tagline")}
+ {I18NextService.i18n.t("add_tagline")}
</button>
</div>
</div>
- <div className="form-group row">
+ <div className="mb-3 row">
<div className="col-12">
<button
onClick={linkEvent(this, this.handleSaveClick)}
- className="btn btn-secondary mr-2"
- disabled={this.state.loading}
+ className="btn btn-secondary me-2"
+ disabled={this.props.loading}
>
- {this.state.loading ? (
+ {this.props.loading ? (
<Spinner />
) : (
- capitalizeFirstLetter(i18n.t("save"))
+ capitalizeFirstLetter(I18NextService.i18n.t("save"))
)}
</button>
</div>
handleEditTaglineClick(d: { i: TaglineForm; index: number }, event: any) {
event.preventDefault();
- if (this.state.editingRow == d.index) {
+ if (d.i.state.editingRow == d.index) {
d.i.setState({ editingRow: undefined });
} else {
d.i.setState({ editingRow: d.index });
}
async handleSaveClick(i: TaglineForm) {
- i.setState({ loading: true });
i.props.onSaveSite({
taglines: i.state.taglines,
auth: myAuthRequired(),