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

Trailing zero patch for browse and books page generator #271

Merged
merged 2 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion client/src/components/sort.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ const sort = (books, selection) => {
break;
}

function round(value, decimals) {
const roundedValue = Math.round(value * 10 ** decimals) / 10 ** decimals;
return roundedValue.toFixed(decimals);
}

return (
<div className="grid grid-cols-1 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3 grid-flow-row gap-2 sm:max-w-[500px] md:max-w-[700px] lg:max-w-[1000px] max-w-[1150px]">
{books_changed.map((book) => (
Expand All @@ -56,7 +61,7 @@ const sort = (books, selection) => {
<div class="text-lg">{book.title}</div>
<div class="felx items-end">by: {book.author}</div>

<div>${book.price}</div>
<div>${round(book.price, 2)}</div>
</a>
</div>
))}
Expand Down
7 changes: 6 additions & 1 deletion client/src/views/BooksPageGenerator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ const BooksPageGenerator = ({ book, user }) => {
});
}, []);

function round(value, decimals) {
const roundedValue = Math.round(value * 10 ** decimals) / 10 ** decimals;
return roundedValue.toFixed(decimals);
}

function addOrRemoveFromWishlist() {
// don't do anything if not logged-in
if (!user || user.length === 0) return;
Expand Down Expand Up @@ -121,7 +126,7 @@ const BooksPageGenerator = ({ book, user }) => {
<img src={book.imageId} alt="" className="row-span-2 border-2" />
</div>
<div className="pt-12 grid grid-auto-rows">
<ul className="text-bold text-xl">${book.price}</ul>
<ul className="text-bold text-xl">${round(book.price, 2)}</ul>
<ReactStars
count={5}
value={book.stars}
Expand Down