"engineStrict": true,
"husky": {
"hooks": {
- "pre-commit": "yarn run lint && lint-staged"
+ "pre-commit": "lint-staged"
}
},
"lint-staged": {
- "*.js": [
+ "*.{ts,tsx,js}": [
"prettier --write",
- "yarn run lint",
- "git add"
- ],
- "*.ts": [
- "prettier --write",
- "yarn run lint",
- "git add"
- ],
- "*.tsx": [
- "prettier --write",
- "yarn run lint",
+ "eslint --fix",
"git add"
],
"package.json": [
} from '../interfaces';
import { WebSocketService } from '../services';
import { PostListings } from './post-listings';
+import { SortSelect } from './sort-select';
import { Sidebar } from './sidebar';
import {
msgOp,
super(props, context);
this.state = this.emptyState;
+ this.handleSortChange = this.handleSortChange.bind(this);
this.subscription = WebSocketService.Instance.subject
.pipe(
// Necessary for back button for some reason
componentWillReceiveProps(nextProps: any) {
- if (nextProps.history.action == 'POP') {
- this.state = this.emptyState;
+ if (
+ nextProps.history.action == 'POP' ||
+ nextProps.history.action == 'PUSH'
+ ) {
this.state.sort = this.getSortTypeFromProps(nextProps);
this.state.page = this.getPageFromProps(nextProps);
+ this.setState(this.state);
this.fetchPosts();
}
}
selects() {
return (
- <div className="mb-2">
- <select
- value={this.state.sort}
- onChange={linkEvent(this, this.handleSortChange)}
- class="custom-select custom-select-sm w-auto"
- >
- <option disabled>
- <T i18nKey="sort_type">#</T>
- </option>
- <option value={SortType.Hot}>
- <T i18nKey="hot">#</T>
- </option>
- <option value={SortType.New}>
- <T i18nKey="new">#</T>
- </option>
- <option disabled>──────</option>
- <option value={SortType.TopDay}>
- <T i18nKey="top_day">#</T>
- </option>
- <option value={SortType.TopWeek}>
- <T i18nKey="week">#</T>
- </option>
- <option value={SortType.TopMonth}>
- <T i18nKey="month">#</T>
- </option>
- <option value={SortType.TopYear}>
- <T i18nKey="year">#</T>
- </option>
- <option value={SortType.TopAll}>
- <T i18nKey="all">#</T>
- </option>
- </select>
+ <div class="mb-2">
+ <SortSelect sort={this.state.sort} onChange={this.handleSortChange} />
</div>
);
}
window.scrollTo(0, 0);
}
- handleSortChange(i: Community, event: any) {
- i.state.sort = Number(event.target.value);
- i.state.page = 1;
- i.setState(i.state);
- i.updateUrl();
- i.fetchPosts();
+ handleSortChange(val: SortType) {
+ this.state.sort = val;
+ this.state.page = 1;
+ this.state.loading = true;
+ this.setState(this.state);
+ this.updateUrl();
+ this.fetchPosts();
window.scrollTo(0, 0);
}
import { WebSocketService, UserService } from '../services';
import { msgOp } from '../utils';
import { CommentNodes } from './comment-nodes';
+import { SortSelect } from './sort-select';
import { i18n } from '../i18next';
import { T } from 'inferno-i18next';
super(props, context);
this.state = this.emptyState;
+ this.handleSortChange = this.handleSortChange.bind(this);
this.subscription = WebSocketService.Instance.subject
.pipe(
<T i18nKey="mentions">#</T>
</option>
</select>
- <select
- value={this.state.sort}
- onChange={linkEvent(this, this.handleSortChange)}
- class="custom-select custom-select-sm w-auto"
- >
- <option disabled>
- <T i18nKey="sort_type">#</T>
- </option>
- <option value={SortType.New}>
- <T i18nKey="new">#</T>
- </option>
- <option value={SortType.TopDay}>
- <T i18nKey="top_day">#</T>
- </option>
- <option value={SortType.TopWeek}>
- <T i18nKey="week">#</T>
- </option>
- <option value={SortType.TopMonth}>
- <T i18nKey="month">#</T>
- </option>
- <option value={SortType.TopYear}>
- <T i18nKey="year">#</T>
- </option>
- <option value={SortType.TopAll}>
- <T i18nKey="all">#</T>
- </option>
- </select>
+ <SortSelect
+ sort={this.state.sort}
+ onChange={this.handleSortChange}
+ hideHot
+ />
</div>
);
}
WebSocketService.Instance.getUserMentions(userMentionsForm);
}
- handleSortChange(i: Inbox, event: any) {
- i.state.sort = Number(event.target.value);
- i.state.page = 1;
- i.setState(i.state);
- i.refetch();
+ handleSortChange(val: SortType) {
+ this.state.sort = val;
+ this.state.page = 1;
+ this.setState(this.state);
+ this.refetch();
}
markAllAsRead() {
} from '../interfaces';
import { WebSocketService, UserService } from '../services';
import { PostListings } from './post-listings';
+import { SortSelect } from './sort-select';
import { SiteForm } from './site-form';
import {
msgOp,
this.state = this.emptyState;
this.handleEditCancel = this.handleEditCancel.bind(this);
+ this.handleSortChange = this.handleSortChange.bind(this);
this.subscription = WebSocketService.Instance.subject
.pipe(
{i18n.t('all')}
</label>
</div>
- <select
- value={this.state.sort}
- onChange={linkEvent(this, this.handleSortChange)}
- class="ml-2 custom-select custom-select-sm w-auto"
- >
- <option disabled>
- <T i18nKey="sort_type">#</T>
- </option>
- <option value={SortType.Hot}>
- <T i18nKey="hot">#</T>
- </option>
- <option value={SortType.New}>
- <T i18nKey="new">#</T>
- </option>
- <option disabled>─────</option>
- <option value={SortType.TopDay}>
- <T i18nKey="top_day">#</T>
- </option>
- <option value={SortType.TopWeek}>
- <T i18nKey="week">#</T>
- </option>
- <option value={SortType.TopMonth}>
- <T i18nKey="month">#</T>
- </option>
- <option value={SortType.TopYear}>
- <T i18nKey="year">#</T>
- </option>
- <option value={SortType.TopAll}>
- <T i18nKey="all">#</T>
- </option>
- </select>
+ <span class="ml-2">
+ <SortSelect sort={this.state.sort} onChange={this.handleSortChange} />
+ </span>
</div>
);
}
window.scrollTo(0, 0);
}
- handleSortChange(i: Main, event: any) {
- i.state.sort = Number(event.target.value);
- i.state.page = 1;
- i.state.loading = true;
- i.setState(i.state);
- i.updateUrl();
- i.fetchPosts();
+ handleSortChange(val: SortType) {
+ this.state.sort = val;
+ this.state.page = 1;
+ this.state.loading = true;
+ this.setState(this.state);
+ this.updateUrl();
+ this.fetchPosts();
window.scrollTo(0, 0);
}
routeSortTypeToEnum,
} from '../utils';
import { PostListing } from './post-listing';
+import { SortSelect } from './sort-select';
import { CommentNodes } from './comment-nodes';
import { i18n } from '../i18next';
import { T } from 'inferno-i18next';
super(props, context);
this.state = this.emptyState;
+ this.handleSortChange = this.handleSortChange.bind(this);
this.subscription = WebSocketService.Instance.subject
.pipe(
<T i18nKey="users">#</T>
</option>
</select>
- <select
- value={this.state.sort}
- onChange={linkEvent(this, this.handleSortChange)}
- class="custom-select custom-select-sm w-auto ml-2"
- >
- <option disabled>
- <T i18nKey="sort_type">#</T>
- </option>
- <option value={SortType.New}>
- <T i18nKey="new">#</T>
- </option>
- <option value={SortType.TopDay}>
- <T i18nKey="top_day">#</T>
- </option>
- <option value={SortType.TopWeek}>
- <T i18nKey="week">#</T>
- </option>
- <option value={SortType.TopMonth}>
- <T i18nKey="month">#</T>
- </option>
- <option value={SortType.TopYear}>
- <T i18nKey="year">#</T>
- </option>
- <option value={SortType.TopAll}>
- <T i18nKey="all">#</T>
- </option>
- </select>
+ <span class="ml-2">
+ <SortSelect
+ sort={this.state.sort}
+ onChange={this.handleSortChange}
+ hideHot
+ />
+ </span>
</div>
);
}
}
}
- handleSortChange(i: Search, event: any) {
- i.state.sort = Number(event.target.value);
- i.state.page = 1;
- i.setState(i.state);
- i.updateUrl();
+ handleSortChange(val: SortType) {
+ this.state.sort = val;
+ this.state.page = 1;
+ this.setState(this.state);
+ this.updateUrl();
}
handleTypeChange(i: Search, event: any) {
--- /dev/null
+import { Component, linkEvent } from 'inferno';
+import { SortType } from '../interfaces';
+
+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>
+ <T i18nKey="sort_type">#</T>
+ </option>
+ {!this.props.hideHot && (
+ <option value={SortType.Hot}>
+ <T i18nKey="hot">#</T>
+ </option>
+ )}
+ <option value={SortType.New}>
+ <T i18nKey="new">#</T>
+ </option>
+ <option disabled>─────</option>
+ <option value={SortType.TopDay}>
+ <T i18nKey="top_day">#</T>
+ </option>
+ <option value={SortType.TopWeek}>
+ <T i18nKey="week">#</T>
+ </option>
+ <option value={SortType.TopMonth}>
+ <T i18nKey="month">#</T>
+ </option>
+ <option value={SortType.TopYear}>
+ <T i18nKey="year">#</T>
+ </option>
+ <option value={SortType.TopAll}>
+ <T i18nKey="all">#</T>
+ </option>
+ </select>
+ );
+ }
+
+ handleSortChange(i: SortSelect, event: any) {
+ i.state.sort = Number(event.target.value);
+ i.setState(i.state);
+ i.props.onChange(i.state.sort);
+ }
+}
setTheme,
} from '../utils';
import { PostListing } from './post-listing';
+import { SortSelect } from './sort-select';
import { CommentNodes } from './comment-nodes';
import { MomentTime } from './moment-time';
import { i18n } from '../i18next';
super(props, context);
this.state = this.emptyState;
+ this.handleSortChange = this.handleSortChange.bind(this);
this.state.user_id = Number(this.props.match.params.id);
this.state.username = this.props.match.params.username;
// Necessary for back button for some reason
componentWillReceiveProps(nextProps: any) {
- if (nextProps.history.action == 'POP') {
- this.state = this.emptyState;
+ if (
+ nextProps.history.action == 'POP' ||
+ nextProps.history.action == 'PUSH'
+ ) {
this.state.view = this.getViewFromProps(nextProps);
this.state.sort = this.getSortTypeFromProps(nextProps);
this.state.page = this.getPageFromProps(nextProps);
+ this.setState(this.state);
this.refetch();
}
}
<T i18nKey="saved">#</T>
</option>
</select>
- <select
- value={this.state.sort}
- onChange={linkEvent(this, this.handleSortChange)}
- class="custom-select custom-select-sm w-auto ml-2"
- >
- <option disabled>
- <T i18nKey="sort_type">#</T>
- </option>
- <option value={SortType.New}>
- <T i18nKey="new">#</T>
- </option>
- <option value={SortType.TopDay}>
- <T i18nKey="top_day">#</T>
- </option>
- <option value={SortType.TopWeek}>
- <T i18nKey="week">#</T>
- </option>
- <option value={SortType.TopMonth}>
- <T i18nKey="month">#</T>
- </option>
- <option value={SortType.TopYear}>
- <T i18nKey="year">#</T>
- </option>
- <option value={SortType.TopAll}>
- <T i18nKey="all">#</T>
- </option>
- </select>
+ <span class="ml-2">
+ <SortSelect
+ sort={this.state.sort}
+ onChange={this.handleSortChange}
+ hideHot
+ />
+ </span>
</div>
);
}
WebSocketService.Instance.getUserDetails(form);
}
- handleSortChange(i: User, event: any) {
- i.state.sort = Number(event.target.value);
- i.state.page = 1;
- i.setState(i.state);
- i.updateUrl();
- i.refetch();
+ handleSortChange(val: SortType) {
+ this.state.sort = val;
+ this.state.page = 1;
+ this.setState(this.state);
+ this.updateUrl();
+ this.refetch();
}
handleViewChange(i: User, event: any) {
return SortType.TopWeek;
} else if (sort == 'topmonth') {
return SortType.TopMonth;
+ } else if (sort == 'topyear') {
+ return SortType.TopYear;
} else if (sort == 'topall') {
return SortType.TopAll;
}