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

Cart summary #76

Open
wants to merge 8 commits into
base: staging
Choose a base branch
from
Open
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
18 changes: 9 additions & 9 deletions client/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
ignorePatterns: ["dist", ".eslintrc.cjs"],
parser: "@typescript-eslint/parser",
plugins: ["react-refresh"],
rules: {
'react-refresh/only-export-components': [
'warn',
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
},
}
};
9 changes: 9 additions & 0 deletions client/src/Components/CheckOutTotal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function CheckOutTotal() {
return (
<div>
<p>Shipping Cost: $0</p>
<p>Tax: $0 </p>
<p>Total: $0</p>
</div>
);
}
89 changes: 89 additions & 0 deletions client/src/Components/ItemList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { useState } from "react";
import Quantity from "./Quantity";
import RemoveButton from "./RemoveButton";
import styles from "../pages/cart/cart.module.css";

function CartItem({ children }: { children: React.ReactNode }) {
return <div className={styles.cartItem}>{children}</div>;
}

function ItemDetails({ item }: { item: Item }) {
return (
<div className={styles.details}>
<div className={styles.flavor}>
<img src={item.image} alt={item.flavor} />
<span> {item.flavor} </span>
</div>
<p> ${item.price} </p>
</div>
);
}

export type Item = {
id: number;
image: string;
flavor: string;
price: number;
quantity: number;
};

//mock data
const itemList: Item[] = [
{
id: 1,
image:
"https://media.istockphoto.com/id/980474978/vector/strawberry-ice-cream-cone-flat-design-dessert-icon.jpg?s=612x612&w=0&k=20&c=kY7enczOhemyXVu5Jp2pmVbv5SfQPj03zcqb27fJv4I=",
flavor: "strawberry",
price: 0,
quantity: 1,
},
{
id: 2,
image:
"https://img.freepik.com/free-vector/chocolate-ice-creame-waffle-cone-sticker_1308-68693.jpg?w=2000",
flavor: "chocolate",
price: 0,
quantity: 3,
},
{
id: 3,
image:
"https://thumbs.dreamstime.com/b/ice-cream-cone-vector-cartoon-illustration-vanilla-213405239.jpg",
flavor: "vanilla",
price: 0,
quantity: 2,
},
];

export default function ItemList() {
const [items, setItems] = useState(itemList);

function handleDeleteItem(id: Item["id"]) {
setItems((items) => items.filter((item) => item.id !== id));
}

function handleUpdateQuantity(id: Item["id"], newQuantity: Item["quantity"]) {
const updatedItems = items.map((item) => {
if (item.id === id) {
return { ...item, quantity: newQuantity };
}
return item;
});

setItems(updatedItems);
}

return (
<>
{items.map((item) => (
<CartItem key={item.id}>
<ItemDetails item={item} />
<div className={styles.actionBtns}>
<RemoveButton itemId={item.id} onDeleteItem={handleDeleteItem} />
<Quantity item={item} onUpdate={handleUpdateQuantity} />
</div>
</CartItem>
))}
</>
);
}
4 changes: 1 addition & 3 deletions client/src/Components/ProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ type ProductCardProps = {
purchaseHistory: number;
};

export default function ProductCard(
props
: ProductCardProps) {
export default function ProductCard(props: ProductCardProps) {
const [scoopsCounter, setScoopsCounter] = useState<number>(0);
const localStorage = useContext(LocalStorageContext);
console.log({localStorage})
Expand Down
32 changes: 32 additions & 0 deletions client/src/Components/Quantity.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Item } from "./ItemList";
import styles from "../pages/cart/cart.module.css";

export default function Quantity({
item,
onUpdate,
}: {
item: Item;
onUpdate: (id: Item["id"], newQuantity: Item["quantity"]) => void;
}) {
function handleIncrement() {
onUpdate(item.id, item.quantity + 1);
}

function handleDecrement() {
if (item.quantity > 0) {
onUpdate(item.id, item.quantity - 1);
}
}

return (
<div className={styles.quantity}>
<button className={styles.minus} onClick={handleDecrement}>
-
</button>
<span> {item.quantity} </span>
<button className={styles.plus} onClick={handleIncrement}>
+
</button>
</div>
);
}
17 changes: 17 additions & 0 deletions client/src/Components/RemoveButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Button } from "./";
import styles from "../pages/cart/cart.module.css";
import { Item } from "./ItemList";

export default function RemoveButton({
onDeleteItem,
itemId,
}: {
onDeleteItem: (id: Item["id"]) => void;
itemId: Item["id"];
}) {
return (
<Button className={styles.removeBtn} action={() => onDeleteItem(itemId)}>
Remove
</Button>
);
}
11 changes: 11 additions & 0 deletions client/src/Components/SubmitButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function SubmitButton() {
const handleSubmit = () => {
//to be added by Lee: send cart items to db
console.log("order submitted");
};
return (
<div>
<button onClick={handleSubmit}>Submit Order</button>
</div>
);
}
18 changes: 9 additions & 9 deletions client/src/Components/productcard.css
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
.single-product-grid {
display: grid;
grid-template-columns: 1fr .1fr 1fr;
grid-template-areas: "left" "center" "right";
display: grid;
grid-template-columns: 1fr 0.1fr 1fr;
grid-template-areas: "left" "center" "right";
}

.left {
grid-area: "left"
grid-area: "left";
}

.center {
grid-area: "center";
grid-area: "center";
}

.right {
grid-area: "right";
text-align: left;
overflow-wrap: break-word;
}
grid-area: "right";
text-align: left;
overflow-wrap: break-word;
}
9 changes: 3 additions & 6 deletions client/src/assets/images/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import Arrow from './assets/images/arrow.png'
import Strawberry from './assets/images/toppings/strawberry.png'
import Arrow from "./assets/images/arrow.png";
import Strawberry from "./assets/images/toppings/strawberry.png";

export {
Arrow,
Strawberry
};
export { Arrow, Strawberry };
8 changes: 4 additions & 4 deletions client/src/components/ArrowButton.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.arrow-button {
width: 50px;
height: 50px;
margin-right: 10px;
}
width: 50px;
height: 50px;
margin-right: 10px;
}
17 changes: 11 additions & 6 deletions client/src/components/ArrowButton.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import Arrow from "../assets/images/arrow.png"
import Arrow from "../assets/images/arrow.png";

import "./ArrowButton.css";

interface ArrowProps {
rotation: number // 0 points left, 90 points up, 180 points right, 270 points down
handleClick: (direction: string) => void
rotation: number; // 0 points left, 90 points up, 180 points right, 270 points down
eyeriss42 marked this conversation as resolved.
Show resolved Hide resolved
handleClick: (direction: string) => void;
}

function ArrowButton(props: ArrowProps) {

return (
<img className='arrow-button' src={Arrow} style={{ transform: `rotate(${props.rotation}deg)` }}
onClick={() => props.handleClick(`${props.rotation < 180 ? 'left' : 'right'}`)} />
<img
className="arrow-button"
src={Arrow}
style={{ transform: `rotate(${props.rotation}deg)` }}
onClick={() =>
props.handleClick(`${props.rotation < 180 ? "left" : "right"}`)
}
/>
);
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/components/FlavorThumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function FlavorThumbnail({ flavor }: { flavor: Flavor }) {
<img
className={styles.image}
src={flavor.image}
alt={`Photo of ${flavor.name}`}
alt={`Photo of ${flavor.name} ice cream`}
/>
<p className={styles.text}>
<strong>{flavor.name}</strong>
Expand Down
20 changes: 10 additions & 10 deletions client/src/components/Suggestions.css
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
.suggestion-list {
text-align: center;
padding: 0;
margin-block: 5;
text-align: center;
padding: 0;
margin-block: 5;
}

.suggestion-item {
width: 20%;
display: inline-block;
padding: 10px;
vertical-align: top;
width: 20%;
display: inline-block;
padding: 10px;
vertical-align: top;
}

.suggestion-image {
max-width: 100%;
height: auto;
}
max-width: 100%;
height: auto;
}
2 changes: 1 addition & 1 deletion client/src/components/Suggestions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "./Suggestions.css";
import "./suggestions.css";

type SuggestionItemProps = {
id: number;
Expand Down
8 changes: 4 additions & 4 deletions client/src/components/ToppingButton.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.topping-img {
width: 50px;
height: 50px;
margin-right: 10px;
}
width: 50px;
height: 50px;
margin-right: 10px;
}
33 changes: 19 additions & 14 deletions client/src/components/ToppingButton.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
import { useState } from "react";

import "./ToppingButton.css";
import "./toppingbutton.css";

interface ToppingButtonProps {
url: string,
selected: boolean
url: string;
selected: boolean;
}

ToppingButton.defaultProps = {
selected: false
}
selected: false,
};

function ToppingButton(props: ToppingButtonProps) {
const [selected, setSelected] = useState(false);
return (
<div key={props.url}>
<div onClick={() => setSelected(!selected)}>
<img className='topping-img' src={props.url} alt="" onClick={() => console.log(props.url)} />
<p style={{ marginTop: '0px' }}>{selected ? '✅' : '🥄'}</p>
</div>
</div>
);
const [selected, setSelected] = useState(false);
return (
<div key={props.url}>
<div onClick={() => setSelected(!selected)}>
<img
className="topping-img"
src={props.url}
alt=""
onClick={() => console.log(props.url)}
/>
<p style={{ marginTop: "0px" }}>{selected ? "✅" : "🥄"}</p>
</div>
</div>
);
}

export default ToppingButton;
4 changes: 2 additions & 2 deletions client/src/components/ToppingsBar.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.toppingbar-title {
text-align: 'center';
}
text-align: center;
}
Loading