2019-10-21 00:49:13 +00:00
|
|
|
import { Component, linkEvent } from 'inferno';
|
|
|
|
import { SortType } from '../interfaces';
|
2020-01-31 20:52:27 +00:00
|
|
|
import { i18n } from '../i18next';
|
2019-10-21 00:49:13 +00:00
|
|
|
|
|
|
|
interface SortSelectProps {
|
|
|
|
sort: SortType;
|
|
|
|
onChange?(val: SortType): any;
|
|
|
|
hideHot?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface SortSelectState {
|
|
|
|
sort: SortType;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class SortSelect extends Component<SortSelectProps, SortSelectState> {
|
|
|
|
private emptyState: SortSelectState = {
|
|
|
|
sort: this.props.sort,
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
this.state = this.emptyState;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<select
|
|
|
|
value={this.state.sort}
|
|
|
|
onChange={linkEvent(this, this.handleSortChange)}
|
|
|
|
class="custom-select custom-select-sm w-auto"
|
|
|
|
>
|
2020-02-02 18:50:44 +00:00
|
|
|
<option disabled>{i18n.t('sort_type')}</option>
|
2019-10-21 00:49:13 +00:00
|
|
|
{!this.props.hideHot && (
|
2020-02-02 18:50:44 +00:00
|
|
|
<option value={SortType.Hot}>{i18n.t('hot')}</option>
|
2019-10-21 00:49:13 +00:00
|
|
|
)}
|
2020-02-02 18:50:44 +00:00
|
|
|
<option value={SortType.New}>{i18n.t('new')}</option>
|
2019-10-21 00:49:13 +00:00
|
|
|
<option disabled>─────</option>
|
2020-02-02 18:50:44 +00:00
|
|
|
<option value={SortType.TopDay}>{i18n.t('top_day')}</option>
|
|
|
|
<option value={SortType.TopWeek}>{i18n.t('week')}</option>
|
|
|
|
<option value={SortType.TopMonth}>{i18n.t('month')}</option>
|
|
|
|
<option value={SortType.TopYear}>{i18n.t('year')}</option>
|
|
|
|
<option value={SortType.TopAll}>{i18n.t('all')}</option>
|
2019-10-21 00:49:13 +00:00
|
|
|
</select>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSortChange(i: SortSelect, event: any) {
|
|
|
|
i.state.sort = Number(event.target.value);
|
|
|
|
i.setState(i.state);
|
|
|
|
i.props.onChange(i.state.sort);
|
|
|
|
}
|
|
|
|
}
|