mirror of
https://github.com/cse110-fa22-group29/cse110-fa22-group29.git
synced 2024-11-10 05:34:44 +00:00
delete tag bug
This commit is contained in:
parent
847e8a1aa1
commit
1cdaa63935
@ -92,7 +92,8 @@ function initFormHandler() {
|
|||||||
tagAddBtn.addEventListener("click", ()=> {
|
tagAddBtn.addEventListener("click", ()=> {
|
||||||
let tagField = document.getElementById("tag-form");
|
let tagField = document.getElementById("tag-form");
|
||||||
if (tagField.value.length > 0) {
|
if (tagField.value.length > 0) {
|
||||||
if (!tagSet.has(tagField.value.toLowerCase())){
|
let tagSetVal = tagField.value.toLowerCase();
|
||||||
|
if (!tagSet.has(tagSetVal)){
|
||||||
let tagLabel = document.createElement("label");
|
let tagLabel = document.createElement("label");
|
||||||
tagLabel.innerHTML = tagField.value;
|
tagLabel.innerHTML = tagField.value;
|
||||||
tagLabel.setAttribute("class","tag");
|
tagLabel.setAttribute("class","tag");
|
||||||
|
@ -99,14 +99,15 @@ function setupUpdate(){
|
|||||||
while (tagContainer.firstChild) {
|
while (tagContainer.firstChild) {
|
||||||
tagContainer.removeChild(tagContainer.firstChild);
|
tagContainer.removeChild(tagContainer.firstChild);
|
||||||
}
|
}
|
||||||
|
let tagSetVal = currReview["tags"][i].toLowerCase()
|
||||||
for (let i = 0; i < currReview["tags"].length; i++) {
|
for (let i = 0; i < currReview["tags"].length; i++) {
|
||||||
tagSet.add(currReview["tags"][i].toLowerCase());
|
tagSet.add(tagSetVal);
|
||||||
let newTag = document.createElement("label");
|
let newTag = document.createElement("label");
|
||||||
newTag.setAttribute("class","tag");
|
newTag.setAttribute("class","tag");
|
||||||
newTag.innerHTML = currReview["tags"][i];
|
newTag.innerHTML = currReview["tags"][i];
|
||||||
newTag.addEventListener("click",()=> {
|
newTag.addEventListener("click",()=> {
|
||||||
tagContainer.removeChild(newTag);
|
tagContainer.removeChild(newTag);
|
||||||
tagSet.delete(currReview["tags"][i].toLowerCase());
|
tagSet.delete(tagSetVal);
|
||||||
});
|
});
|
||||||
tagContainer.append(newTag);
|
tagContainer.append(newTag);
|
||||||
}
|
}
|
||||||
@ -195,14 +196,15 @@ function setupUpdate(){
|
|||||||
tagAddBtn.addEventListener("click", ()=> {
|
tagAddBtn.addEventListener("click", ()=> {
|
||||||
let tagField = document.getElementById("tag-form");
|
let tagField = document.getElementById("tag-form");
|
||||||
if (tagField.value.length > 0) {
|
if (tagField.value.length > 0) {
|
||||||
if (!tagSet.has(tagField.value.toLowerCase())){
|
let tagSetVal = tagField.value.toLowerCase();
|
||||||
|
if (!tagSet.has(tagSetVal)){
|
||||||
let tagLabel = document.createElement("label");
|
let tagLabel = document.createElement("label");
|
||||||
tagLabel.innerHTML = tagField.value;
|
tagLabel.innerHTML = tagField.value;
|
||||||
tagLabel.setAttribute("class","tag");
|
tagLabel.setAttribute("class","tag");
|
||||||
tagSet.add(tagField.value.toLowerCase());
|
tagSet.add(tagSetVal);
|
||||||
tagLabel.addEventListener("click",()=> {
|
tagLabel.addEventListener("click",()=> {
|
||||||
tagContainer.removeChild(tagLabel);
|
tagContainer.removeChild(tagLabel);
|
||||||
tagSet.delete(tagField.value.toLowerCase());
|
tagSet.delete(tagSetVal);
|
||||||
});
|
});
|
||||||
|
|
||||||
tagContainer.append(tagLabel);
|
tagContainer.append(tagLabel);
|
||||||
|
@ -81,8 +81,8 @@ export function deleteReviewFromStorage(ID){
|
|||||||
function deleteTagsFromStorage(ID, deletedTags) {
|
function deleteTagsFromStorage(ID, deletedTags) {
|
||||||
for(let i in deletedTags){
|
for(let i in deletedTags){
|
||||||
//get local storage of each tag and remove id from tag list
|
//get local storage of each tag and remove id from tag list
|
||||||
let tagName = "!"+ deletedTags[i];
|
let tagName = "!"+ deletedTags[i].toLowerCase();
|
||||||
let tagArr = JSON.parse(localStorage.getItem(tagName.toLowerCase()));
|
let tagArr = JSON.parse(localStorage.getItem(tagName));
|
||||||
for(let j in tagArr){
|
for(let j in tagArr){
|
||||||
if(tagArr[j] == ID){
|
if(tagArr[j] == ID){
|
||||||
tagArr.splice(j,1);
|
tagArr.splice(j,1);
|
||||||
@ -90,9 +90,9 @@ function deleteTagsFromStorage(ID, deletedTags) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(tagArr.length != 0){
|
if(tagArr.length != 0){
|
||||||
localStorage.setItem(tagName.toLowerCase(), JSON.stringify(tagArr));
|
localStorage.setItem(tagName, JSON.stringify(tagArr));
|
||||||
} else {
|
} else {
|
||||||
localStorage.removeItem(tagName.toLowerCase());
|
localStorage.removeItem(tagName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,13 +104,13 @@ function deleteTagsFromStorage(ID, deletedTags) {
|
|||||||
*/
|
*/
|
||||||
function addTagsToStorage(ID, addedTags) {
|
function addTagsToStorage(ID, addedTags) {
|
||||||
for(let i in addedTags){
|
for(let i in addedTags){
|
||||||
let tagName = "!" + addedTags[i];
|
let tagName = "!" + addedTags[i].toLowerCase();
|
||||||
let tagArr = JSON.parse(localStorage.getItem(tagName.toLowerCase()));
|
let tagArr = JSON.parse(localStorage.getItem(tagName));
|
||||||
if(!tagArr){
|
if(!tagArr){
|
||||||
tagArr = [];
|
tagArr = [];
|
||||||
}
|
}
|
||||||
tagArr.push(ID);
|
tagArr.push(ID);
|
||||||
localStorage.setItem(tagName.toLowerCase(), JSON.stringify(tagArr));
|
localStorage.setItem(tagName, JSON.stringify(tagArr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user