Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
# Conflicts: # src/lib/data/products.ts
| const sortOptions = [ | ||
| { label: "Newest", value: "created_at" }, | ||
| { label: "Price: Low to High", value: "price_asc" }, | ||
| { label: "Price: High to Low", value: "price_desc" }, | ||
| ] |
There was a problem hiding this comment.
this already exists in code, how about moving this to consts?
| ] | ||
|
|
||
| export default function Wishlist() { | ||
| const [user, setUser] = useState<any>(null) |
There was a problem hiding this comment.
please type this without any
| const sortProducts = (products: any[]) => { | ||
| if (!products) return [] | ||
|
|
||
| return [...products].sort((a, b) => { | ||
| if (sortBy === "created_at") { | ||
| return new Date(b.created_at).getTime() - new Date(a.created_at).getTime() | ||
| } else if (sortBy === "price_asc") { | ||
| return a.calculated_amount - b.calculated_amount | ||
| } else if (sortBy === "price_desc") { | ||
| return b.calculated_amount - a.calculated_amount | ||
| } | ||
| return 0 | ||
| }) |
There was a problem hiding this comment.
- couldn't we sort on BE side?
- if we don't, there's helper function for FE sorting in lib/helpers
There was a problem hiding this comment.
Of course, the only right way is to do it on BE side.
| const [wishlist, setWishlist] = useState<WishlistType[]>([]) | ||
| const [sortBy, setSortBy] = useState("created_at") | ||
| const [loading, setLoading] = useState(true) | ||
| const [totalCount, setTotalCount] = useState(0) |
There was a problem hiding this comment.
What is the point of tocalCount, if it's not used anywhere anyway?
|
IMO approach to handle pagination and sorting on FE side, using endpoint in current state - is fundamentally wrong. I strongly believe that BE needs to provide an endpoint that will allow to fetch user’s wishlist's products paginated and sorted data (relevance, createdAt_desc, updatedAt_desc). Currently there is only endpoint I strongly advice to not merge current approach. |
No description provided.