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: Disable other options if three categories are selected while creating a post #73

Closed
wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Dec 6, 2023

Summary

Disable other options if three categories are selected while creating a post

Description

To improve the current UX, disable the remaining categories when the user selects three categories while a new blog post is being created.

Images

Screenshot from 2023-12-06 10-35-30

Issue(s) Addressed

Closes #66

Prerequisites

Copy link

vercel bot commented Dec 6, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
wanderlust ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 6, 2023 5:11am
wanderlust-backend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 6, 2023 5:11am

@krishnaacharyaa
Copy link
Owner

Hey @SanjeevKrSingh, Thank you for your quick update,

image
Can we also handle for dark theme, presently it works only on the light mode.

Copy link
Owner

@krishnaacharyaa krishnaacharyaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly do the require changes, including support to the dark theme


return (
<span
className={twMerge(
'cursor-pointer rounded-3xl px-3 py-1 text-xs font-medium text-light-primary/80 dark:text-dark-primary/80',
selected ? selectedColor : defaultColor
selected ? selectedColor : defaultColor,
disabled && disabledColor
)}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disabled && disabledColor

I didn't get this logic, what is this? What are you trying to achieve? by this

Then you can simply add disabled ? disabledColor : defaultColor to the twMerge() argument.
#69 (comment)

Why did you chose not to do this way? any reason?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the logic but it has its pitfalls. Using a ternary will always be preferable.
Read this article to see why you should avoid using logical AND for conditional rendering: https://kentcdodds.com/blog/use-ternaries-rather-than-and-and-in-jsx

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @chinmaykunkikar @krishnaacharyaa here there is three state of the category
First is nomal state
second is selected state
and third is disabled state
If i do like this
disabled ? disabledColor : defaultColor
how to handle selected state we need to like this
disabled ? disabledColor : selected ? selectedColor : defaultColor

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SanjeevKrSingh

disabled ? disabledColor : selected ? selectedColor : defaultColor

This seems reasonable to me.
But for better reading, we can split it to

  1. disabled ? disabledColor : getSelectedColor(selected)
    OR
  2. getCategoryColor(disabled,selected)
    Inside getCategoryColor function, we can do disabled ? disabledColor : getSelectedColor(selected)

I find 2 modular and precise, and easy to understand, if you have any better approaches, feel free to let us know :) @chinmaykunkikar kindly share your thoughts if you get free time.

setFormData({
...formData,
categories: [...formData.categories, category],
categories: formData.categories.includes(category) ? formData.categories.filter((cat) => cat !== category) : [...formData.categories, category]
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to split this into understandable code, as already reviewed in the previous PR, kindly work on it.

@@ -238,6 +235,7 @@ function AddBlog() {
{categories.map((category, index) => (
<span key={`${category}-${index}`} onClick={() => handleCategoryClick(category)}>
<CategoryPill
disabled={isValidCategory(category)}
category={category}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better,
to something similar to this you can do in the above comment

@chinmaykunkikar
Copy link
Collaborator

@SanjeevKrSingh @krishnaacharyaa I just realised that we can further improve UX by adding a simple hint to the Categories label like we did for the Blog cover image label. This will reduce any kind of confusion.

Before

Screenshot_20231208_124258

We can simply add (max 3 categories) beside Categories label.

The final result will look like this:

After

image

What do you think?

@krishnaacharyaa
Copy link
Owner

We are closing this, as it is inactive and the author confirmed he isn't going to work on this

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

Successfully merging this pull request may close these issues.

[ENHANCEMENT] Disable other options if three categories are selected while creating a post
2 participants