Skip to content

Commit

Permalink
update category object
Browse files Browse the repository at this point in the history
  • Loading branch information
alim1496 committed May 27, 2024
1 parent 0e3dbc9 commit 3d80d37
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/models/Category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface Category {
name: string;
slug: string;
url: string;
}
3 changes: 2 additions & 1 deletion src/models/ProductSlice.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Category } from "./Category";
import { Product } from "./Product";

export interface ProductSlice {
allProducts: Product[];
newProducts: Product[];
featuredProducts: Product[];
wishlist: Product[];
categories: string[];
categories: Category[];
}
8 changes: 4 additions & 4 deletions src/pages/AllProducts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,18 @@ const AllProducts: FC = () => {
<div className="space-y-1">
{allCategories.map((_category) => (
<div
key={_category}
key={_category.slug}
className={`cursor-pointer dark:text-white hover:text-blue-500 ${
_category === category ? "text-blue-500" : ""
_category.slug === category ? "text-blue-500" : ""
}`}
onClick={() => {
setCategory(_category);
setCategory(_category.slug);
if (sortRef && sortRef.current)
sortRef.current.value = "default";
sortProducts("default");
}}
>
{_category}
{_category.name}
</div>
))}
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/redux/features/productSlice.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { Product } from "../../models/Product";
import { ProductSlice } from "../../models/ProductSlice";
import { Category } from "../../models/Category";

const initialState: ProductSlice = {
allProducts: [],
Expand All @@ -27,7 +28,7 @@ export const productSlice = createSlice({
return { ...state, wishlist: updatedList };
}
},
addCategories: (state, action: PayloadAction<string[]>) => {
addCategories: (state, action: PayloadAction<Category[]>) => {
return { ...state, categories: action.payload };
},
addProducts: (state, action: PayloadAction<Product[]>) => {
Expand Down

0 comments on commit 3d80d37

Please sign in to comment.