Skip to content

Commit 9e5c5cb

Browse files
committed
refactor: simplify App component by using an array for items and update class instantiation with TODOs for method implementations
1 parent e643640 commit 9e5c5cb

2 files changed

Lines changed: 59 additions & 277 deletions

File tree

extra/02.inventory-manager/src/app.tsx

Lines changed: 39 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,38 @@
11
import './app.css'
2-
import {
3-
Clothing,
4-
ConsoleLogger,
5-
Electronics,
6-
InMemoryLogger,
7-
InventoryManager,
8-
Perishable,
9-
} from './classes'
102

11-
function App() {
12-
const laptop = new Electronics({
13-
id: 'elect-001',
3+
// 🐨 Replace these placeholders with class instances from ./classes.
4+
// 🐨 Use Electronics, Clothing, and Perishable for the three items.
5+
const items = [
6+
{
147
name: 'Laptop',
15-
quantity: 3,
16-
basePrice: 999.99,
17-
brand: 'Nova',
18-
model: 'X1',
19-
serialNumber: 'SN-12345',
20-
warrantyMonths: 24,
21-
location: 'Aisle 4',
22-
})
23-
24-
const hoodie = new Clothing({
25-
id: 'cloth-042',
8+
description: 'TODO: implement Electronics.getDescription',
9+
tracking: 'TODO: implement Electronics.getTrackingInfo',
10+
price: 'TODO: implement Electronics.calculatePrice',
11+
todo: 'TODO: replace with Electronics class',
12+
},
13+
{
2614
name: 'Hoodie',
27-
quantity: 12,
28-
basePrice: 39.99,
29-
size: 'M',
30-
color: 'Slate',
31-
})
32-
33-
const apples = new Perishable({
34-
id: 'per-019',
15+
description: 'TODO: implement Clothing.getDescription',
16+
tracking: null,
17+
price: 'TODO: implement Clothing.calculatePrice',
18+
todo: 'TODO: replace with Clothing class',
19+
},
20+
{
3521
name: 'Apples',
36-
quantity: 20,
37-
basePrice: 1.25,
38-
expirationDate: '2026-02-12',
39-
})
22+
description: 'TODO: implement Perishable.getDescription',
23+
tracking: null,
24+
price: null,
25+
todo: 'TODO: replace with Perishable class',
26+
},
27+
]
4028

41-
const consoleLogger = new ConsoleLogger()
42-
const memoryLogger = new InMemoryLogger()
43-
const manager = new InventoryManager(consoleLogger)
44-
const logPreview = manager.receiveStock(laptop, 0)
45-
memoryLogger.log('TODO: implement InMemoryLogger.getLogs')
29+
// 🐨 Use InventoryManager + ConsoleLogger to generate a real log message.
30+
const logPreview = 'TODO: implement InventoryManager.receiveStock'
4631

32+
// 🐨 Use InMemoryLogger and display the number of logs stored.
33+
const memoryLogCount = 'TODO: implement InMemoryLogger.getLogs'
34+
35+
function App() {
4736
return (
4837
<div className="app">
4938
<header className="app-header">
@@ -56,34 +45,25 @@ function App() {
5645
<section className="panel">
5746
<h2>Items</h2>
5847
<div className="grid">
59-
<div className="card">
60-
<h3>{laptop.name}</h3>
61-
<p>{laptop.getDescription()}</p>
62-
<p>Tracking: {laptop.getTrackingInfo()}</p>
63-
<p>Price (2): ${laptop.calculatePrice(2)}</p>
64-
<p className="todo">TODO: implement Electronics methods</p>
65-
</div>
66-
<div className="card">
67-
<h3>{hoodie.name}</h3>
68-
<p>{hoodie.getDescription()}</p>
69-
<p>Price (3): ${hoodie.calculatePrice(3)}</p>
70-
<p className="todo">TODO: implement Clothing methods</p>
71-
</div>
72-
<div className="card">
73-
<h3>{apples.name}</h3>
74-
<p>{apples.getDescription()}</p>
75-
<p className="todo">TODO: implement Perishable description</p>
76-
</div>
48+
{items.map((item) => (
49+
<div className="card" key={item.name}>
50+
<h3>{item.name}</h3>
51+
<p>{item.description}</p>
52+
{item.tracking ? <p>Tracking: {item.tracking}</p> : null}
53+
{item.price ? <p>Price: {item.price}</p> : null}
54+
<p className="todo">{item.todo}</p>
55+
</div>
56+
))}
7757
</div>
7858
</section>
7959

8060
<section className="panel">
8161
<h2>Inventory Actions</h2>
8262
<div className="card">
8363
<p>Logger preview: {logPreview}</p>
84-
<p>Memory log count: {memoryLogger.getLogs().length}</p>
64+
<p>Memory log count: {memoryLogCount}</p>
8565
<p className="todo">
86-
TODO: implement InventoryManager and logger behaviors
66+
TODO: wire up ConsoleLogger, InMemoryLogger, and InventoryManager
8767
</p>
8868
</div>
8969
</section>

0 commit comments

Comments
 (0)