1 import { Component, linkEvent } from 'inferno';
2 import { ListingType } from 'lemmy-js-client';
3 import { UserService } from '../services';
4 import { randomStr } from '../utils';
5 import { i18n } from '../i18next';
7 interface ListingTypeSelectProps {
9 onChange?(val: ListingType): any;
12 interface ListingTypeSelectState {
16 export class ListingTypeSelect extends Component<
17 ListingTypeSelectProps,
18 ListingTypeSelectState
20 private id = `listing-type-input-${randomStr()}`;
22 private emptyState: ListingTypeSelectState = {
23 type_: this.props.type_,
26 constructor(props: any, context: any) {
27 super(props, context);
28 this.state = this.emptyState;
31 static getDerivedStateFromProps(props: any): ListingTypeSelectProps {
39 <div class="btn-group btn-group-toggle flex-wrap mb-2">
41 className={`btn btn-outline-secondary
42 ${this.state.type_ == ListingType.Subscribed && 'active'}
43 ${UserService.Instance.user == undefined ? 'disabled' : 'pointer'}
47 id={`${this.id}-subscribed`}
49 value={ListingType.Subscribed}
50 checked={this.state.type_ == ListingType.Subscribed}
51 onChange={linkEvent(this, this.handleTypeChange)}
52 disabled={UserService.Instance.user == undefined}
54 {i18n.t('subscribed')}
57 className={`pointer btn btn-outline-secondary ${
58 this.state.type_ == ListingType.All && 'active'
64 value={ListingType.All}
65 checked={this.state.type_ == ListingType.All}
66 onChange={linkEvent(this, this.handleTypeChange)}
74 handleTypeChange(i: ListingTypeSelect, event: any) {
75 i.props.onChange(event.target.value);