]> Untitled Git - lemmy-ui.git/blobdiff - src/shared/components/home/home.tsx
Changing all bigints to numbers
[lemmy-ui.git] / src / shared / components / home / home.tsx
index c23586a6d5b7d8ae65742f9ccaf212ec3a8b4bac..52a82126082eb3d371fb47fc16c5a0c8fe8512dc 100644 (file)
@@ -61,9 +61,6 @@ import {
   QueryParams,
   relTags,
   restoreScrollPosition,
-  routeDataTypeToEnum,
-  routeListingTypeToEnum,
-  routeSortTypeToEnum,
   saveCommentRes,
   saveScrollPosition,
   setIsoData,
@@ -106,33 +103,24 @@ interface HomeProps {
   page: number;
 }
 
-const getDataTypeFromQuery = (type?: string) =>
-  routeDataTypeToEnum(type ?? "", DataType.Post);
+function getDataTypeFromQuery(type?: string): DataType {
+  return type ? DataType[type] : DataType.Post;
+}
 
-function getListingTypeFromQuery(type?: string) {
-  const mui = UserService.Instance.myUserInfo;
+function getListingTypeFromQuery(type?: string): ListingType {
+  const myListingType =
+    UserService.Instance.myUserInfo?.local_user_view?.local_user
+      ?.default_listing_type;
 
-  return routeListingTypeToEnum(
-    type ?? "",
-    mui
-      ? Object.values(ListingType)[
-          mui.local_user_view.local_user.default_listing_type
-        ]
-      : ListingType.Local
-  );
+  return type ? (type as ListingType) : myListingType ?? "Local";
 }
 
-function getSortTypeFromQuery(type?: string) {
-  const mui = UserService.Instance.myUserInfo;
+function getSortTypeFromQuery(type?: string): SortType {
+  const mySortType =
+    UserService.Instance.myUserInfo?.local_user_view?.local_user
+      ?.default_sort_type;
 
-  return routeSortTypeToEnum(
-    type ?? "",
-    mui
-      ? Object.values(SortType)[
-          mui.local_user_view.local_user.default_listing_type
-        ]
-      : SortType.Active
-  );
+  return type ? (type as SortType) : mySortType ?? "Active";
 }
 
 const getHomeQueryParams = () =>
@@ -145,8 +133,8 @@ const getHomeQueryParams = () =>
 
 function fetchTrendingCommunities() {
   const listCommunitiesForm: ListCommunities = {
-    type_: ListingType.Local,
-    sort: SortType.Hot,
+    type_: "Local",
+    sort: "Hot",
     limit: trendingFetchLimit,
     auth: myAuth(false),
   };
@@ -222,15 +210,15 @@ function getRss(listingType: ListingType) {
   let rss: string | undefined = undefined;
 
   switch (listingType) {
-    case ListingType.All: {
+    case "All": {
       rss = `/feeds/all.xml?sort=${sort}`;
       break;
     }
-    case ListingType.Local: {
+    case "Local": {
       rss = `/feeds/local.xml?sort=${sort}`;
       break;
     }
-    case ListingType.Subscribed: {
+    case "Subscribed": {
       rss = auth ? `/feeds/front/${auth}.xml?sort=${sort}` : undefined;
       break;
     }
@@ -366,8 +354,8 @@ export class Home extends Component<any, HomeState> {
     }
 
     const trendingCommunitiesForm: ListCommunities = {
-      type_: ListingType.Local,
-      sort: SortType.Hot,
+      type_: "Local",
+      sort: "Hot",
       limit: trendingFetchLimit,
       auth,
     };
@@ -784,14 +772,14 @@ export class Home extends Component<any, HomeState> {
             let shouldAddPost: boolean;
 
             switch (listingType) {
-              case ListingType.Subscribed: {
+              case "Subscribed": {
                 // If you're on subscribed, only push it if you're subscribed.
                 shouldAddPost = !!mui?.follows.some(
                   ({ community: { id } }) => id === post_view.community.id
                 );
                 break;
               }
-              case ListingType.Local: {
+              case "Local": {
                 // If you're on the local view, only push it if its local
                 shouldAddPost = post_view.post.local;
                 break;
@@ -885,7 +873,7 @@ export class Home extends Component<any, HomeState> {
 
             // If you're on subscribed, only push it if you're subscribed.
             const shouldAddComment =
-              listingType === ListingType.Subscribed
+              listingType === "Subscribed"
                 ? UserService.Instance.myUserInfo?.follows.some(
                     ({ community: { id } }) => id === comment_view.community.id
                   )