From 90ce1f1a3fca5c8d8a13e91f991b23ecb77f1faf Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 20 Oct 2019 21:21:54 -0700 Subject: Adding default sort / filter into user settings. - Fixes #295 --- ui/src/components/main.tsx | 53 ++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 37 deletions(-) (limited to 'ui/src/components/main.tsx') diff --git a/ui/src/components/main.tsx b/ui/src/components/main.tsx index e4ff5a50..c871db72 100644 --- a/ui/src/components/main.tsx +++ b/ui/src/components/main.tsx @@ -21,6 +21,7 @@ import { import { WebSocketService, UserService } from '../services'; import { PostListings } from './post-listings'; import { SortSelect } from './sort-select'; +import { ListingTypeSelect } from './listing-type-select'; import { SiteForm } from './site-form'; import { msgOp, @@ -81,13 +82,15 @@ export class Main extends Component { return props.match.params.type ? routeListingTypeToEnum(props.match.params.type) : UserService.Instance.user - ? ListingType.Subscribed + ? UserService.Instance.user.default_listing_type : ListingType.All; } getSortTypeFromProps(props: any): SortType { return props.match.params.sort ? routeSortTypeToEnum(props.match.params.sort) + : UserService.Instance.user + ? UserService.Instance.user.default_sort_type : SortType.Hot; } @@ -101,6 +104,7 @@ export class Main extends Component { this.state = this.emptyState; this.handleEditCancel = this.handleEditCancel.bind(this); this.handleSortChange = this.handleSortChange.bind(this); + this.handleTypeChange = this.handleTypeChange.bind(this); this.subscription = WebSocketService.Instance.subject .pipe( @@ -423,35 +427,10 @@ export class Main extends Component { selects() { return (
-
- - -
+ @@ -527,13 +506,13 @@ export class Main extends Component { window.scrollTo(0, 0); } - handleTypeChange(i: Main, event: any) { - i.state.type_ = Number(event.target.value); - i.state.page = 1; - i.state.loading = true; - i.setState(i.state); - i.updateUrl(); - i.fetchPosts(); + handleTypeChange(val: ListingType) { + this.state.type_ = val; + this.state.page = 1; + this.state.loading = true; + this.setState(this.state); + this.updateUrl(); + this.fetchPosts(); window.scrollTo(0, 0); } -- cgit v1.2.3