2022-07-30 13:28:08 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
|
|
|
import { CommentSortType } from "lemmy-js-client";
|
|
|
|
import { i18n } from "../../i18next";
|
|
|
|
import { randomStr, relTags, sortingHelpUrl } from "../../utils";
|
|
|
|
import { Icon } from "./icon";
|
|
|
|
|
|
|
|
interface CommentSortSelectProps {
|
|
|
|
sort: CommentSortType;
|
|
|
|
onChange?(val: CommentSortType): any;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface CommentSortSelectState {
|
|
|
|
sort: CommentSortType;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class CommentSortSelect extends Component<
|
|
|
|
CommentSortSelectProps,
|
|
|
|
CommentSortSelectState
|
|
|
|
> {
|
|
|
|
private id = `sort-select-${randomStr()}`;
|
2023-01-04 16:56:24 +00:00
|
|
|
state: CommentSortSelectState = {
|
2022-07-30 13:28:08 +00:00
|
|
|
sort: this.props.sort,
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static getDerivedStateFromProps(props: any): CommentSortSelectState {
|
|
|
|
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 12:01:29 +00:00
|
|
|
className="form-select d-inline-block w-auto me-2 mb-2"
|
2022-07-30 13:28:08 +00:00
|
|
|
aria-label={i18n.t("sort_type")}
|
|
|
|
>
|
|
|
|
<option disabled aria-hidden="true">
|
|
|
|
{i18n.t("sort_type")}
|
|
|
|
</option>
|
2023-05-11 18:32:32 +00:00
|
|
|
<option value={"Hot"}>{i18n.t("hot")}</option>,
|
|
|
|
<option value={"Top"}>{i18n.t("top")}</option>,
|
|
|
|
<option value={"New"}>{i18n.t("new")}</option>
|
|
|
|
<option value={"Old"}>{i18n.t("old")}</option>
|
2022-07-30 13:28:08 +00:00
|
|
|
</select>
|
|
|
|
<a
|
|
|
|
className="text-muted"
|
|
|
|
href={sortingHelpUrl}
|
|
|
|
rel={relTags}
|
|
|
|
title={i18n.t("sorting_help")}
|
|
|
|
>
|
|
|
|
<Icon icon="help-circle" classes="icon-inline" />
|
|
|
|
</a>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSortChange(i: CommentSortSelect, event: any) {
|
2023-01-04 16:56:24 +00:00
|
|
|
i.props.onChange?.(event.target.value);
|
2022-07-30 13:28:08 +00:00
|
|
|
}
|
|
|
|
}
|