-
Notifications
You must be signed in to change notification settings - Fork 84
FEAT MM/2 513 #206
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
base: test
Are you sure you want to change the base?
FEAT MM/2 513 #206
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
💡 Enable Vercel Agent with $100 free credit for automated AI reviews |
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.