diff --git a/frontend/src/components/category-pill.tsx b/frontend/src/components/category-pill.tsx index 69ab7af7..130efc3f 100644 --- a/frontend/src/components/category-pill.tsx +++ b/frontend/src/components/category-pill.tsx @@ -4,16 +4,24 @@ import { twMerge } from 'tailwind-merge'; interface CategoryPillProps extends React.HTMLAttributes { category: string; selected?: boolean; + disabled?: boolean; } -export default function CategoryPill({ category, selected = false }: CategoryPillProps) { +export default function CategoryPill({ category, disabled, selected = false }: CategoryPillProps) { + const disabledColor: string = + 'opacity-50 bg-light-primary/10 dark:bg-dark-primary/10 dark:text-dark-primary/50 cursor-not-allowed'; + const [defaultColor, selectedColor]: [string, string] = getCategoryColors(category); + const getSelectedColor = (selected: boolean): string => { + return selected ? selectedColor : defaultColor; + }; + return ( {category} diff --git a/frontend/src/pages/add-blog.tsx b/frontend/src/pages/add-blog.tsx index 0dc64d95..69a83d36 100644 --- a/frontend/src/pages/add-blog.tsx +++ b/frontend/src/pages/add-blog.tsx @@ -34,12 +34,19 @@ function AddBlog() { isFeaturedPost: false, }); + //checks the length of the categories array and if the category is already selected + const isValidCategory = (category: string): boolean => { + return formData.categories.length >= 3 && !formData.categories.includes(category); + }; + const handleInputChange = (e: ChangeEvent) => { const { name, value } = e.target; setFormData({ ...formData, [name]: value }); }; const handleCategoryClick = (category: string) => { + if (isValidCategory(category)) return; + if (formData.categories.includes(category)) { setFormData({ ...formData, @@ -52,6 +59,7 @@ function AddBlog() { }); } }; + const handleselector = () => { setFormData({ ...formData, @@ -232,7 +240,11 @@ function AddBlog() {
{categories.map((category, index) => ( @@ -240,6 +252,7 @@ function AddBlog() { ))}