]> Untitled Git - lemmy-ui.git/commitdiff
refactor if into switch case
authorIvo Barros <devL3v3L@gmail.com>
Wed, 21 Jun 2023 00:21:14 +0000 (01:21 +0100)
committerIvo Barros <devL3v3L@gmail.com>
Wed, 21 Jun 2023 00:21:14 +0000 (01:21 +0100)
src/shared/utils.ts

index be7b11b08b40db12ff1ad740da0e021c6fa5466d..d6946ccea75db310b726c79d7b23b30198793ac1 100644 (file)
@@ -853,24 +853,28 @@ export function commentsToFlatNodes(comments: CommentView[]): CommentNodeI[] {
 }
 
 export function convertCommentSortType(sort: SortType): CommentSortType {
-  if (
-    sort == "TopAll" ||
-    sort == "TopHour" ||
-    sort == "TopSixHour" ||
-    sort == "TopTwelveHour" ||
-    sort == "TopDay" ||
-    sort == "TopWeek" ||
-    sort == "TopMonth" ||
-    sort == "TopYear"
-  ) {
-    return "Top";
-  } else if (sort == "New") {
-    return "New";
-  } else if (sort == "Hot" || sort == "Active") {
-    return "Hot";
-  } else {
-    return "Hot";
-  }
+    switch(sort) {
+        case "TopAll":
+        case "TopHour":
+        case "TopSixHour":
+        case "TopTwelveHour":
+        case "TopDay":
+        case "TopWeek":
+        case "TopMonth":
+        case "TopYear": {
+            return "Top";
+        }
+        case "New": {
+            return "New";
+        }
+        case "Hot":
+        case "Active": {
+            return "Hot";
+        }
+        default: {
+            return "Hot";
+        }
+    }
 }
 
 export function buildCommentsTree(