2023-06-21 22:28:24 +00:00
|
|
|
import { randomStr } from "@utils/helpers";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
|
|
|
import { SortType } from "lemmy-js-client";
|
2023-06-21 22:28:24 +00:00
|
|
|
import { relTags, sortingHelpUrl } from "../../config";
|
2023-06-22 00:54:35 +00:00
|
|
|
import { I18NextService } from "../../services";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { Icon } from "./icon";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
interface SortSelectProps {
|
|
|
|
sort: SortType;
|
2023-06-14 12:20:40 +00:00
|
|
|
onChange(val: SortType): void;
|
2020-09-06 16:15:25 +00:00
|
|
|
hideHot?: boolean;
|
2021-02-01 18:48:42 +00:00
|
|
|
hideMostComments?: boolean;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface SortSelectState {
|
|
|
|
sort: SortType;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class SortSelect extends Component<SortSelectProps, SortSelectState> {
|
|
|
|
private id = `sort-select-${randomStr()}`;
|
2023-01-04 16:56:24 +00:00
|
|
|
state: SortSelectState = {
|
2020-09-06 16:15:25 +00:00
|
|
|
sort: this.props.sort,
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
static getDerivedStateFromProps(props: SortSelectProps): SortSelectState {
|
2020-09-06 16:15:25 +00:00
|
|
|
return {
|
|
|
|
sort: props.sort,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<select
|
|
|
|
id={this.id}
|
|
|
|
name={this.id}
|
|
|
|
value={this.state.sort}
|
|
|
|
onChange={linkEvent(this, this.handleSortChange)}
|
2023-06-20 18:46:16 +00:00
|
|
|
className="sort-select form-select d-inline-block w-auto me-2"
|
2023-06-22 00:54:35 +00:00
|
|
|
aria-label={I18NextService.i18n.t("sort_type")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<option disabled aria-hidden="true">
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("sort_type")}
|
2021-02-11 20:35:27 +00:00
|
|
|
</option>
|
2021-02-01 18:48:42 +00:00
|
|
|
{!this.props.hideHot && [
|
2023-05-11 18:32:32 +00:00
|
|
|
<option key={"Hot"} value={"Hot"}>
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("hot")}
|
2022-09-22 15:03:35 +00:00
|
|
|
</option>,
|
2023-05-11 18:32:32 +00:00
|
|
|
<option key={"Active"} value={"Active"}>
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("active")}
|
2022-09-22 15:03:35 +00:00
|
|
|
</option>,
|
2021-02-01 18:48:42 +00:00
|
|
|
]}
|
2023-06-22 00:54:35 +00:00
|
|
|
<option value={"New"}>{I18NextService.i18n.t("new")}</option>
|
|
|
|
<option value={"Old"}>{I18NextService.i18n.t("old")}</option>
|
2021-02-18 15:57:00 +00:00
|
|
|
{!this.props.hideMostComments && [
|
2023-05-11 18:32:32 +00:00
|
|
|
<option key={"MostComments"} value={"MostComments"}>
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("most_comments")}
|
2021-02-18 15:57:00 +00:00
|
|
|
</option>,
|
2023-05-11 18:32:32 +00:00
|
|
|
<option key={"NewComments"} value={"NewComments"}>
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("new_comments")}
|
2021-02-18 15:57:00 +00:00
|
|
|
</option>,
|
|
|
|
]}
|
2021-02-11 20:35:27 +00:00
|
|
|
<option disabled aria-hidden="true">
|
|
|
|
─────
|
|
|
|
</option>
|
2023-06-22 03:23:35 +00:00
|
|
|
<option value={"TopHour"}>{I18NextService.i18n.t("top_hour")}</option>
|
2023-06-22 03:52:04 +00:00
|
|
|
<option value={"TopSixHour"}>
|
|
|
|
{I18NextService.i18n.t("top_six_hours")}
|
|
|
|
</option>
|
|
|
|
<option value={"TopTwelveHour"}>
|
|
|
|
{I18NextService.i18n.t("top_twelve_hours")}
|
|
|
|
</option>
|
2023-06-22 00:54:35 +00:00
|
|
|
<option value={"TopDay"}>{I18NextService.i18n.t("top_day")}</option>
|
|
|
|
<option value={"TopWeek"}>{I18NextService.i18n.t("top_week")}</option>
|
2023-06-22 03:52:04 +00:00
|
|
|
<option value={"TopMonth"}>
|
|
|
|
{I18NextService.i18n.t("top_month")}
|
|
|
|
</option>
|
2023-06-22 00:54:35 +00:00
|
|
|
<option value={"TopYear"}>{I18NextService.i18n.t("top_year")}</option>
|
|
|
|
<option value={"TopAll"}>{I18NextService.i18n.t("top_all")}</option>
|
2020-09-06 16:15:25 +00:00
|
|
|
</select>
|
|
|
|
<a
|
2023-06-20 18:46:16 +00:00
|
|
|
className="sort-select-icon text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
href={sortingHelpUrl}
|
2022-02-24 15:31:44 +00:00
|
|
|
rel={relTags}
|
2023-06-22 00:54:35 +00:00
|
|
|
title={I18NextService.i18n.t("sorting_help")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="help-circle" classes="icon-inline" />
|
2020-09-06 16:15:25 +00:00
|
|
|
</a>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSortChange(i: SortSelect, event: any) {
|
2023-06-14 12:20:40 +00:00
|
|
|
i.props.onChange(event.target.value);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|