1 import { randomStr } from "@utils/helpers";
2 import classNames from "classnames";
3 import { Component, linkEvent } from "inferno";
4 import { DataType } from "../../interfaces";
5 import { I18NextService } from "../../services";
7 interface DataTypeSelectProps {
9 onChange?(val: DataType): any;
12 interface DataTypeSelectState {
16 export class DataTypeSelect extends Component<
20 private id = `listing-type-input-${randomStr()}`;
22 state: DataTypeSelectState = {
23 type_: this.props.type_,
26 constructor(props: any, context: any) {
27 super(props, context);
30 static getDerivedStateFromProps(props: any): DataTypeSelectProps {
39 className="data-type-select btn-group btn-group-toggle flex-wrap"
43 id={`${this.id}-posts`}
47 checked={this.state.type_ === DataType.Post}
48 onChange={linkEvent(this, this.handleTypeChange)}
51 htmlFor={`${this.id}-posts`}
52 className={classNames("pointer btn btn-outline-secondary", {
53 active: this.state.type_ === DataType.Post,
56 {I18NextService.i18n.t("posts")}
60 id={`${this.id}-comments`}
63 value={DataType.Comment}
64 checked={this.state.type_ === DataType.Comment}
65 onChange={linkEvent(this, this.handleTypeChange)}
68 htmlFor={`${this.id}-comments`}
69 className={classNames("pointer btn btn-outline-secondary", {
70 active: this.state.type_ === DataType.Comment,
73 {I18NextService.i18n.t("comments")}
79 handleTypeChange(i: DataTypeSelect, event: any) {
80 i.props.onChange?.(Number(event.target.value));