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
|
|
|
import { T } from 'inferno-i18next';
|
|
|
|
|
|
|
|
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"
|
|
|
|
>
|
|
|
|
<option disabled>
|
2020-01-31 20:52:27 +00:00
|
|
|
{ i18n.t('sort_type') }
|
2019-10-21 00:49:13 +00:00
|
|
|
</option>
|
|
|
|
{!this.props.hideHot && (
|
|
|
|
<option value={SortType.Hot}>
|
2020-01-31 20:52:27 +00:00
|
|
|
{ i18n.t('hot') }
|
2019-10-21 00:49:13 +00:00
|
|
|
</option>
|
|
|
|
)}
|
|
|
|
<option value={SortType.New}>
|
2020-01-31 20:52:27 +00:00
|
|
|
{ i18n.t('new') }
|
2019-10-21 00:49:13 +00:00
|
|
|
</option>
|
|
|
|
<option disabled>─────</option>
|
|
|
|
<option value={SortType.TopDay}>
|
2020-01-31 20:52:27 +00:00
|
|
|
{ i18n.t('top_day') }
|
2019-10-21 00:49:13 +00:00
|
|
|
</option>
|
|
|
|
<option value={SortType.TopWeek}>
|
2020-01-31 20:52:27 +00:00
|
|
|
{ i18n.t('week') }
|
2019-10-21 00:49:13 +00:00
|
|
|
</option>
|
|
|
|
<option value={SortType.TopMonth}>
|
2020-01-31 20:52:27 +00:00
|
|
|
{ i18n.t('month') }
|
2019-10-21 00:49:13 +00:00
|
|
|
</option>
|
|
|
|
<option value={SortType.TopYear}>
|
2020-01-31 20:52:27 +00:00
|
|
|
{ i18n.t('year') }
|
2019-10-21 00:49:13 +00:00
|
|
|
</option>
|
|
|
|
<option value={SortType.TopAll}>
|
2020-01-31 20:52:27 +00:00
|
|
|
{ i18n.t('all') }
|
2019-10-21 00:49:13 +00:00
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSortChange(i: SortSelect, event: any) {
|
|
|
|
i.state.sort = Number(event.target.value);
|
|
|
|
i.setState(i.state);
|
|
|
|
i.props.onChange(i.state.sort);
|
|
|
|
}
|
|
|
|
}
|