1 import { randomStr } from "@utils/helpers";
2 import { Component, linkEvent } from "inferno";
3 import { CommentSortType } from "lemmy-js-client";
4 import { relTags, sortingHelpUrl } from "../../config";
5 import { i18n } from "../../i18next";
6 import { Icon } from "./icon";
8 interface CommentSortSelectProps {
10 onChange?(val: CommentSortType): any;
13 interface CommentSortSelectState {
14 sort: CommentSortType;
17 export class CommentSortSelect extends Component<
18 CommentSortSelectProps,
19 CommentSortSelectState
21 private id = `sort-select-${randomStr()}`;
22 state: CommentSortSelectState = {
23 sort: this.props.sort,
26 constructor(props: any, context: any) {
27 super(props, context);
30 static getDerivedStateFromProps(props: any): CommentSortSelectState {
42 value={this.state.sort}
43 onChange={linkEvent(this, this.handleSortChange)}
44 className="sort-select form-select d-inline-block w-auto me-2 mb-2"
45 aria-label={i18n.t("sort_type")}
47 <option disabled aria-hidden="true">
50 <option value={"Hot"}>{i18n.t("hot")}</option>,
51 <option value={"Top"}>{i18n.t("top")}</option>,
52 <option value={"New"}>{i18n.t("new")}</option>
53 <option value={"Old"}>{i18n.t("old")}</option>
56 className="sort-select-help text-muted"
59 title={i18n.t("sorting_help")}
61 <Icon icon="help-circle" classes="icon-inline" />
67 handleSortChange(i: CommentSortSelect, event: any) {
68 i.props.onChange?.(event.target.value);