1 import { randomStr } from "@utils/helpers";
2 import { Component, linkEvent } from "inferno";
3 import { SortType } from "lemmy-js-client";
4 import { relTags, sortingHelpUrl } from "../../config";
5 import { i18n } from "../../i18next";
6 import { Icon } from "./icon";
8 interface SortSelectProps {
10 onChange(val: SortType): void;
12 hideMostComments?: boolean;
15 interface SortSelectState {
19 export class SortSelect extends Component<SortSelectProps, SortSelectState> {
20 private id = `sort-select-${randomStr()}`;
21 state: SortSelectState = {
22 sort: this.props.sort,
25 constructor(props: any, context: any) {
26 super(props, context);
29 static getDerivedStateFromProps(props: SortSelectProps): SortSelectState {
41 value={this.state.sort}
42 onChange={linkEvent(this, this.handleSortChange)}
43 className="sort-select form-select d-inline-block w-auto me-2"
44 aria-label={i18n.t("sort_type")}
46 <option disabled aria-hidden="true">
49 {!this.props.hideHot && [
50 <option key={"Hot"} value={"Hot"}>
53 <option key={"Active"} value={"Active"}>
57 <option value={"New"}>{i18n.t("new")}</option>
58 <option value={"Old"}>{i18n.t("old")}</option>
59 {!this.props.hideMostComments && [
60 <option key={"MostComments"} value={"MostComments"}>
61 {i18n.t("most_comments")}
63 <option key={"NewComments"} value={"NewComments"}>
64 {i18n.t("new_comments")}
67 <option disabled aria-hidden="true">
70 <option value={"TopHour"}>{i18n.t("top_hour")}</option>
71 <option value={"TopSixHour"}>{i18n.t("top_six_hours")}</option>
72 <option value={"TopTwelveHour"}>{i18n.t("top_twelve_hours")}</option>
73 <option value={"TopDay"}>{i18n.t("top_day")}</option>
74 <option value={"TopWeek"}>{i18n.t("top_week")}</option>
75 <option value={"TopMonth"}>{i18n.t("top_month")}</option>
76 <option value={"TopYear"}>{i18n.t("top_year")}</option>
77 <option value={"TopAll"}>{i18n.t("top_all")}</option>
80 className="sort-select-icon text-muted"
83 title={i18n.t("sorting_help")}
85 <Icon icon="help-circle" classes="icon-inline" />
91 handleSortChange(i: SortSelect, event: any) {
92 i.props.onChange(event.target.value);