Skip to content

Commit

Permalink
Re-release ass 1
Browse files Browse the repository at this point in the history
  • Loading branch information
bokuanT committed Nov 16, 2023
1 parent 2eddadd commit 6ce2b6e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ npm install -g http-server
2. Navigate to the root directory and start the server with:
```
http-server
```
```

3. Access peerprep on http://localhost:8080/
26 changes: 9 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ document.addEventListener('DOMContentLoaded', function() {
var questionCategory = document.getElementById('questionCategory').value;

// Set question id
const questionId = getNextId();
const questionId = 0; // This will be updated in populateTable()

// Get question difficulty
var questionDifficulty = document.getElementById('questionComplexity').value;
Expand Down Expand Up @@ -77,7 +77,6 @@ document.addEventListener('DOMContentLoaded', function() {

// Clear the table (assuming you have a function to do this)
populateTable();
resetIds();
alert('All questions cleared successfully');
});

Expand All @@ -86,15 +85,14 @@ document.addEventListener('DOMContentLoaded', function() {

// Add a click event listener to the table body for event delegation
tableBody.addEventListener('click', function(event) {
console.log("here");
if (event.target.classList.contains('delete')) {
console.log("there");
// Get all questions from local storage
var questions = JSON.parse(localStorage.getItem(ALL_QUESTIONS));

// Get the id of the question to be deleted
const idToDelete = parseInt(event.target.getAttribute('data-id'), 10);

console.log(idToDelete)
console.log(questions)
// Delete the question from the array
const updatedQuestions = questions.filter(question => question.id !== idToDelete);

Expand Down Expand Up @@ -152,7 +150,10 @@ function populateTable() {

// Update the table body with the questions
if (questions !== null) {
var id = 1;
questions.forEach(question => {
question.id = id;
id++;
var row = document.createElement('tr');
row.innerHTML = `
<td>${question.id}</td>
Expand All @@ -166,6 +167,8 @@ function populateTable() {
tableBody.appendChild(row);
});
}
// Update local storage
localStorage.setItem(ALL_QUESTIONS, JSON.stringify(questions));
}

function displayDetails(question) {
Expand All @@ -183,16 +186,5 @@ function displayDetails(question) {
document.getElementById('detailsModal').style.display = "block";
}

function getNextId() {
var lastId = localStorage.getItem('LAST_ID') || 0;
var newId = parseInt(lastId) + 1;
localStorage.setItem('LAST_ID', newId);
return newId;
}

function resetIds() {
localStorage.setItem('LAST_ID', 0);
}
// Populate the table initially
populateTable();

populateTable();

0 comments on commit 6ce2b6e

Please sign in to comment.