Skip to content

Commit 8a78f73

Browse files
committed
Refactoring
1 parent 47ab165 commit 8a78f73

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/controllers/CattleController.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ export class CattleController {
3333
}
3434

3535
updateCattle(id, updates) {
36+
for (let i = 0; i < this.cattle.length; i++) {
37+
if (this.cattle[i].id === id) {
38+
this.cattle[i].status = updates.status;
39+
}
40+
}
41+
3642
const index = this.cattle.findIndex(cow => cow.id === id);
3743
if (index === -1) {
3844
throw new Error('Cattle not found');
3945
}
40-
4146
const cattle = this.cattle[index];
42-
if (updates.status) {
43-
cattle.status = updates.status;
44-
}
45-
46-
this.cattle[index] = cattle;
4747
return cattle;
4848
}
4949
}

src/views/CattleCard.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129

130130
.edit-status-form .submit-button {
131131
background-color: #4CAF50;
132-
color: white;
132+
color: #FFF;
133133
}
134134

135135
.edit-status-form .cancel-button {

src/views/CattleList.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ function CattleList({ cattle = [], controller, onCattleUpdate }) {
1515
setShowAddForm(false)
1616
}
1717

18-
const handleStatusUpdate = (id, updates) => {
19-
const updatedCattle = controller.updateCattle(id, updates)
20-
onCattleUpdate(cattle.map(cow =>
21-
cow.id === id ? updatedCattle : cow
18+
let handleStatusUpdate = (id, updates) => {
19+
let updatedCow = controller.updateCattle(id, updates)
20+
onCattleUpdate(cattle.map(
21+
cow =>
22+
cow.id === id ? updatedCow : cow
2223
))
2324
}
2425

0 commit comments

Comments
 (0)