Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: logic related to readability #60

Open
wit03 opened this issue Oct 9, 2024 · 0 comments
Open

refactor: logic related to readability #60

wit03 opened this issue Oct 9, 2024 · 0 comments

Comments

@wit03
Copy link
Member

wit03 commented Oct 9, 2024

          _:hammer_and_wrench: Refactor suggestion_

Refactor complex className logic for better readability

The ternary expressions used in lines 132-139 and 156-165 within the className prop are complex and can impact readability and maintainability. Consider extracting the conditional logic into variables or helper functions for clarity.

Example refactoring for lines 132-139:

+const isAllFiltersCleared = Object.values(checkBox).every(
+  (value) => value.length === 0
+)
+
 className={` 
   h-10
   hover:bg-secondaryRed hover:text-primaryRed hover:border hover:border-primaryRed
   border rounded-full px-3 py-2 cursor-pointer transition-colors self-center shrink-0
-  ${
-    Object.keys(checkBox).every(
-      (key) =>
-        checkBox[key as keyof CheckBoxStateType]
-          .length === 0
-    )
-      ? 'bg-secondaryRed text-primaryRed border-secondaryRed'
-      : 'text-slate-900 border'
-  }
+  ${isAllFiltersCleared ? 'bg-secondaryRed text-primaryRed border-secondaryRed' : 'text-slate-900 border'}
 `}

And for lines 156-165:

+const isCategorySelected = checkBox.category.includes(item.name)
+
 className={`
   lg:block h-10 group relative ctn-category shadow
   hover:bg-secondaryRed hover:text-primaryRed hover:border hover:border-primaryRed
   border rounded-full px-3 py-2 cursor-pointer transition-colors self-center shrink-0
-  ${
-    checkBox.category.some(
-      (elem) =>
-        elem ===
-        category.find(
-          (elem) => elem.name === item.name
-        )?.name
-    )
-      ? 'bg-secondaryRed text-primaryRed border-secondaryRed'
-      : 'text-slate-900 border'
-  }
+  ${isCategorySelected ? 'bg-secondaryRed text-primaryRed border-secondaryRed' : 'text-slate-900 border'}
 `}

This refactoring enhances readability and makes the conditional styling logic clearer.

Also applies to: 156-165

Originally posted by @coderabbitai[bot] in #46 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant