1 import { Component, linkEvent } from 'inferno';
2 import { SortType } from 'lemmy-js-client';
3 import { sortingHelpUrl, randomStr } from '../utils';
4 import { i18n } from '../i18next';
6 interface SortSelectProps {
8 onChange?(val: SortType): any;
12 interface SortSelectState {
16 export class SortSelect extends Component<SortSelectProps, SortSelectState> {
17 private id = `sort-select-${randomStr()}`;
18 private emptyState: SortSelectState = {
19 sort: this.props.sort,
22 constructor(props: any, context: any) {
23 super(props, context);
24 this.state = this.emptyState;
27 static getDerivedStateFromProps(props: any): SortSelectState {
39 value={this.state.sort}
40 onChange={linkEvent(this, this.handleSortChange)}
41 class="custom-select w-auto mr-2 mb-2"
43 <option disabled>{i18n.t('sort_type')}</option>
44 {!this.props.hideHot && (
46 <option value={SortType.Active}>{i18n.t('active')}</option>
47 <option value={SortType.Hot}>{i18n.t('hot')}</option>
50 <option value={SortType.New}>{i18n.t('new')}</option>
51 <option disabled>─────</option>
52 <option value={SortType.TopDay}>{i18n.t('top_day')}</option>
53 <option value={SortType.TopWeek}>{i18n.t('week')}</option>
54 <option value={SortType.TopMonth}>{i18n.t('month')}</option>
55 <option value={SortType.TopYear}>{i18n.t('year')}</option>
56 <option value={SortType.TopAll}>{i18n.t('all')}</option>
59 className="text-muted"
63 title={i18n.t('sorting_help')}
65 <svg class={`icon icon-inline`}>
66 <use xlinkHref="#icon-help-circle"></use>
73 handleSortChange(i: SortSelect, event: any) {
74 i.props.onChange(event.target.value);