Skip to content

Commit 57c6b96

Browse files
committed
Fix Delete Bug
Bug: The selected item was not being deleted, or a different item was deleted. Fix: - Map Question to correct unique index - Update how index is calculated
1 parent 80d61e2 commit 57c6b96

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

peer-prep/src/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import './App.css';
2-
//import { LoginSignUp } from './Components/LoginSignUp/LoginSignUp';
2+
// import { LoginSignUp } from './Components/LoginSignUp/LoginSignUp';
33
import { Navbar } from './Components/Navbar/Navbar';
44
import { Questions } from './Components/QuestionList/QuestionList';
55

66
function App() {
77
return (
88
<div>
99
<Navbar/>
10-
{/*<LoginSignUp/>*/}
10+
{/* <LoginSignUp/> */}
1111
<Questions/>
1212

1313
</div>

peer-prep/src/Components/QuestionList/QuestionList.jsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,27 @@ export const Questions = () => {
4747
}
4848

4949
const updateLocalDatabase = () => {
50-
// Updating Database in Local Storageß
50+
// Updating Database in Local Storage
5151
updateLocalQuestionDatabase(database);
5252
}
5353

5454
const updateStates = () => {
5555
// Update States
5656
setQs(Array.from(database.database));
57-
setQId(Array.from(database.database).length);
57+
setQId(Array.from(database.database).length == 0 ? 0 : Array.from(database.database).sort((a, b) => a[0] < b[0]).slice(-1)[0][0]);
5858
}
5959

6060
// To load data on mount
6161
useEffect(() => {
62-
setQs(Array.from(database.database));
63-
setQId(Array.from(database.database).length);
62+
updateStates();
6463
}, [])
6564

6665
return (
6766

6867
<div className="q-wrapper">
6968
<div className="accordion">
7069
{qs.map((q, i) => (
71-
<Question key = {q[0]} question = {q[1]} i = {i} deleteQuestion = {deleteQuestion} updateQuestion = {updateQuestion}/>
70+
<Question key = {q[0]} question = {q[1]} i = {q[0]} deleteQuestion = {deleteQuestion} updateQuestion = {updateQuestion}/>
7271
))}
7372
</div>
7473

0 commit comments

Comments
 (0)