Skip to content
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
65 changes: 65 additions & 0 deletions src/pages/Cart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React, {useEffect, useState} from 'react';
import Link from 'next/link';

export default function Cart() {
const [cart, setCart] = useState([]);

useEffect(() => {
const stored = localStorage.getItem('cart');
if (stored) setCart(JSON.parse(stored));
}, []);

function removeFromCart(index) {
const newCart = cart.slice();
newCart.splice(index, 1);
setCart(newCart);
localStorage.setItem('cart', JSON.stringify(newCart));
}

return (
<div style={{maxWidth: 600, margin: '0 auto', padding: 24}}>
<h1>Your Cart</h1>
<Link href="/Store" style={{float: 'right', marginBottom: 16}}>
Back to Store
</Link>
{cart.length === 0 ? (
<p>Your cart is empty.</p>
) : (
<ul style={{listStyle: 'none', padding: 0}}>
{cart.map((item, idx) => (
<li
key={idx}
style={{
Comment on lines +22 to +32

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Link href="/Store" style={{float: 'right', marginBottom: 16}}>
Back to Store
</Link>
{cart.length === 0 ? (
<p>Your cart is empty.</p>
) : (
<ul style={{listStyle: 'none', padding: 0}}>
{cart.map((item, idx) => (
<li
key={idx}
style={{
<style jsx global>{`
a:focus, button:focus {
outline: 2px solid #007bff;
outline-offset: 2px;
}
`}</style>
<Link href="/Store" style={{float: 'right', marginBottom: 16}}>
Back to Store
</Link>
{cart.length === 0 ? (
<p>Your cart is empty.</p>
) : (

All interactive elements (buttons and links) lack visible focus indicators. Without proper focus styles, keyboard users won't be able to see which element is currently focused when navigating, making the interface inaccessible for keyboard-only users.

Review by Conductor

Is this review helpful? React 👍 or 👎 to let us know!

display: 'flex',
alignItems: 'center',
marginBottom: 16,
borderBottom: '1px solid #eee',
paddingBottom: 8,
}}>
<img
src={item.image}
alt={item.name}
style={{
width: 48,
height: 48,
objectFit: 'cover',
borderRadius: 4,
marginRight: 16,
}}
/>
Comment on lines +39 to +49

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<img
src={item.image}
alt={item.name}
style={{
width: 48,
height: 48,
objectFit: 'cover',
borderRadius: 4,
marginRight: 16,
}}
/>
<img
src={item.image}
alt={item.name}
width={48}
height={48}
style={{
width: 48,
height: 48,
objectFit: 'cover',
borderRadius: 4,
marginRight: 16,
}}
/>

Images without explicit width and height HTML attributes can cause layout shifts as the browser doesn't know the image dimensions until they load. This negatively impacts Cumulative Layout Shift (CLS), an important Core Web Vitals metric.

Review by Conductor

Is this review helpful? React 👍 or 👎 to let us know!

<div style={{flex: 1}}>
<div style={{fontWeight: 'bold'}}>{item.name}</div>
<div>${item.price.toFixed(2)}</div>
</div>
<button
onClick={() => removeFromCart(idx)}
style={{marginLeft: 8}}>
Remove
</button>
Comment on lines +54 to +58

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<button
onClick={() => removeFromCart(idx)}
style={{marginLeft: 8}}>
Remove
</button>
<button
onClick={() => removeFromCart(idx)}
style={{marginLeft: 8}}
aria-label={`Remove ${item.name} from cart`}>
Remove
</button>

The "Remove" button lacks accessible context for screen reader users. Without additional context, screen reader users won't know which item the button will remove, making the interface confusing and potentially causing unintentional actions.

Review by Conductor

Is this review helpful? React 👍 or 👎 to let us know!

</li>
))}
</ul>
)}
</div>
);
}
79 changes: 79 additions & 0 deletions src/pages/Store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React, {useState, useEffect} from 'react';
import Link from 'next/link';

const products = [
{
id: 1,
name: 'React Conf 2019 Mug',
description: 'A stylish mug from React Conf 2019.',
image: '/images/home/conf2019/nat.jpg',
price: 12.99,
},
{
id: 2,
name: 'React Conf 2019 T-shirt',
description: 'Comfy T-shirt from React Conf 2019.',
image: '/images/home/conf2019/sophie.jpg',
price: 19.99,
},
{
id: 3,
name: 'React Conf 2019 Sticker',
description: 'Sticker pack from React Conf 2019.',
image: '/images/home/conf2019/tae.jpg',
price: 4.99,
},
];

export default function Store() {
const [cart, setCart] = useState([]);

useEffect(() => {
const stored = localStorage.getItem('cart');
if (stored) setCart(JSON.parse(stored));
}, []);

function addToCart(product) {
const newCart = [...cart, product];
setCart(newCart);
localStorage.setItem('cart', JSON.stringify(newCart));
}

return (
<div style={{maxWidth: 800, margin: '0 auto', padding: 24}}>
<h1>Store</h1>
<Link href="/Cart" style={{float: 'right', marginBottom: 16}}>
Go to Cart ({cart.length})
</Link>
<div style={{display: 'flex', gap: 32, flexWrap: 'wrap'}}>
{products.map((product) => (
<div
key={product.id}
style={{
border: '1px solid #eee',
Comment on lines +45 to +53

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Link href="/Cart" style={{float: 'right', marginBottom: 16}}>
Go to Cart ({cart.length})
</Link>
<div style={{display: 'flex', gap: 32, flexWrap: 'wrap'}}>
{products.map((product) => (
<div
key={product.id}
style={{
border: '1px solid #eee',
<Link href="/Cart" className="focusable-element" style={{float: 'right', marginBottom: 16}}>
Go to Cart ({cart.length})
</Link>
<div style={{display: 'flex', gap: 32, flexWrap: 'wrap'}}>
{products.map((product) => (
<div
key={product.id}
style={{
border: '1px solid #eee',
borderRadius: 8,
padding: 16,
width: 220,
}}>

All interactive elements (buttons and links) lack visible focus indicators. This makes it impossible for keyboard users to see which element is currently focused, creating a significant accessibility barrier for people who cannot use a mouse.

Review by Conductor

Is this review helpful? React 👍 or 👎 to let us know!

Comment on lines +45 to +53

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Link href="/Cart" style={{float: 'right', marginBottom: 16}}>
Go to Cart ({cart.length})
</Link>
<div style={{display: 'flex', gap: 32, flexWrap: 'wrap'}}>
{products.map((product) => (
<div
key={product.id}
style={{
border: '1px solid #eee',
<Link href="/Cart" className="focusable-element" style={{float: 'right', marginBottom: 16}}>
Go to Cart ({cart.length})
</Link>
<div style={{display: 'flex', gap: 32, flexWrap: 'wrap'}}>
{products.map((product) => (
<div
key={product.id}
style={{
border: '1px solid #eee',
borderRadius: 8,
padding: 16,
width: 220,
}}>

All interactive elements (buttons and links) lack visible focus indicators. This makes it impossible for keyboard users to see which element is currently focused, creating a significant accessibility barrier for people who cannot use a mouse.

Review by Conductor

Is this review helpful? React 👍 or 👎 to let us know!

Comment on lines +45 to +53

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Link href="/Cart" style={{float: 'right', marginBottom: 16}}>
Go to Cart ({cart.length})
</Link>
<div style={{display: 'flex', gap: 32, flexWrap: 'wrap'}}>
{products.map((product) => (
<div
key={product.id}
style={{
border: '1px solid #eee',
<Link href="/Cart" style={{float: 'right', marginBottom: 16}} className="no-bg-scrollbar" onFocus={(e) => e.target.style.outline = '2px solid #4299e1'} onBlur={(e) => e.target.style.outline = 'none'}>
Go to Cart ({cart.length})
</Link>
<div style={{display: 'flex', gap: 32, flexWrap: 'wrap'}}>
{products.map((product) => (
<div
key={product.id}
style={{
border: '1px solid #eee',
borderRadius: 8,
padding: 16,
width: 220,
}}>

All interactive elements (buttons and links) lack visible focus indicators. This makes it impossible for keyboard users to see which element is currently focused, creating a significant accessibility barrier for people who cannot use a mouse.

Review by Conductor

Is this review helpful? React 👍 or 👎 to let us know!

borderRadius: 8,
padding: 16,
width: 220,
}}>
<img
src={product.image}
alt={product.name}
style={{
width: '100%',
height: 140,
objectFit: 'cover',
borderRadius: 4,
}}
/>
Comment on lines +58 to +67

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<img
src={product.image}
alt={product.name}
style={{
width: '100%',
height: 140,
objectFit: 'cover',
borderRadius: 4,
}}
/>
<img
src={product.image}
alt={product.name}
width="220"
height="140"
style={{
width: '100%',
height: 140,
objectFit: 'cover',
borderRadius: 4,
}}
/>

Images without explicit width and height HTML attributes can cause layout shifts as the browser doesn't know the image dimensions until they load. This negatively impacts Cumulative Layout Shift (CLS), an important Core Web Vitals metric.

Review by Conductor

Is this review helpful? React 👍 or 👎 to let us know!

<h2 style={{fontSize: 20}}>{product.name}</h2>
<p>{product.description}</p>
<p style={{fontWeight: 'bold'}}>${product.price.toFixed(2)}</p>
<button onClick={() => addToCart(product)} style={{marginTop: 8}}>
Add to Cart
</button>
Comment on lines +71 to +73

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<button onClick={() => addToCart(product)} style={{marginTop: 8}}>
Add to Cart
</button>
<button
onClick={() => addToCart(product)}
style={{marginTop: 8}}
aria-label={`Add ${product.name} to Cart`}>
Add to Cart
</button>

The "Add to Cart" button lacks an accessible name that includes the product being added. Screen reader users won't know which product they're adding to the cart, as the button text is the same for all products.

Review by Conductor

Is this review helpful? React 👍 or 👎 to let us know!

</div>
))}
</div>
</div>
);
}