summaryrefslogtreecommitdiffstats
path: root/ui/src/utils.ts
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2020-02-07 23:05:15 -0500
committerDessalines <tyhou13@gmx.com>2020-02-07 23:05:15 -0500
commitecd10482a6815fc3b51b2da7cd5f494c01c385e6 (patch)
tree16d25467ba4224bfd807122806d1f77ddfaee6e8 /ui/src/utils.ts
parent779a72581c4c1dee846296cd0f3ea761914aedc6 (diff)
Add new comments views to main and community pages. Fixes #480
Diffstat (limited to 'ui/src/utils.ts')
-rw-r--r--ui/src/utils.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/ui/src/utils.ts b/ui/src/utils.ts
index 9ad0920f..51836c6f 100644
--- a/ui/src/utils.ts
+++ b/ui/src/utils.ts
@@ -19,6 +19,7 @@ import {
User,
SortType,
ListingType,
+ DataType,
SearchType,
WebSocketResponse,
WebSocketJsonResponse,
@@ -198,6 +199,10 @@ export function routeListingTypeToEnum(type: string): ListingType {
return ListingType[capitalizeFirstLetter(type)];
}
+export function routeDataTypeToEnum(type: string): DataType {
+ return DataType[capitalizeFirstLetter(type)];
+}
+
export function routeSearchTypeToEnum(type: string): SearchType {
return SearchType[capitalizeFirstLetter(type)];
}
@@ -519,3 +524,30 @@ function communitySearch(text: string, cb: any) {
cb([]);
}
}
+
+export function getListingTypeFromProps(props: any): ListingType {
+ return props.match.params.listing_type
+ ? routeListingTypeToEnum(props.match.params.listing_type)
+ : UserService.Instance.user
+ ? UserService.Instance.user.default_listing_type
+ : ListingType.All;
+}
+
+// TODO might need to add a user setting for this too
+export function getDataTypeFromProps(props: any): DataType {
+ return props.match.params.data_type
+ ? routeDataTypeToEnum(props.match.params.data_type)
+ : DataType.Post;
+}
+
+export function 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;
+}
+
+export function getPageFromProps(props: any): number {
+ return props.match.params.page ? Number(props.match.params.page) : 1;
+}