1 import { Component, linkEvent } from "inferno";
2 import { ListingType } from "lemmy-js-client";
3 import { i18n } from "../../i18next";
4 import { UserService } from "../../services";
5 import { randomStr } from "../../utils";
7 interface ListingTypeSelectProps {
10 showSubscribed: boolean;
11 onChange(val: ListingType): void;
14 interface ListingTypeSelectState {
18 export class ListingTypeSelect extends Component<
19 ListingTypeSelectProps,
20 ListingTypeSelectState
22 private id = `listing-type-input-${randomStr()}`;
24 state: ListingTypeSelectState = {
25 type_: this.props.type_,
28 constructor(props: any, context: any) {
29 super(props, context);
32 static getDerivedStateFromProps(
33 props: ListingTypeSelectProps
34 ): ListingTypeSelectState {
42 <div className="btn-group btn-group-toggle flex-wrap">
43 {this.props.showSubscribed && (
45 title={i18n.t("subscribed_description")}
46 className={`btn btn-outline-secondary
47 ${this.state.type_ == "Subscribed" && "active"}
48 ${!UserService.Instance.myUserInfo ? "disabled" : "pointer"}
52 id={`${this.id}-subscribed`}
56 checked={this.state.type_ == "Subscribed"}
57 onChange={linkEvent(this, this.handleTypeChange)}
58 disabled={!UserService.Instance.myUserInfo}
60 {i18n.t("subscribed")}
63 {this.props.showLocal && (
65 title={i18n.t("local_description")}
66 className={`pointer btn btn-outline-secondary ${
67 this.state.type_ == "Local" && "active"
71 id={`${this.id}-local`}
75 checked={this.state.type_ == "Local"}
76 onChange={linkEvent(this, this.handleTypeChange)}
82 title={i18n.t("all_description")}
83 className={`pointer btn btn-outline-secondary ${
84 (this.state.type_ == "All" && "active") ||
85 (!this.props.showLocal && this.state.type_ == "Local" && "active")
93 checked={this.state.type_ == "All"}
94 onChange={linkEvent(this, this.handleTypeChange)}
102 handleTypeChange(i: ListingTypeSelect, event: any) {
103 i.props.onChange(event.target.value);