link deletion works now

This commit is contained in:
2025-07-11 16:16:20 -04:00
parent 9f3825e863
commit baeb777d2d
+29 -34
View File
@@ -739,7 +739,7 @@
"beforeend", "beforeend",
` `
${i == 0 ? "" : `<br />`} ${i == 0 ? "" : `<br />`}
<div id="${this.id}-section-listing-${i}" class="sectionListingContainer"> <div id="${this.id}-section-listing--${i}" class="sectionListingContainer">
<span class=${this.id + "-section"}> <span class=${this.id + "-section"}>
${sectionData[i].label == "" ? "uncategorized links: " : "<u>section</u>: " + sectionData[i].label} ${sectionData[i].label == "" ? "uncategorized links: " : "<u>section</u>: " + sectionData[i].label}
</span> </span>
@@ -768,13 +768,13 @@
for (let s = 0; s < sectionData.length; s++) { for (let s = 0; s < sectionData.length; s++) {
for (let l = 0; l < sectionData[s].links.length; l++) { for (let l = 0; l < sectionData[s].links.length; l++) {
let targetSection = document.getElementById( let targetSection = document.getElementById(
this.id + "-section-listing-" + s this.id + "-section-listing--" + s
); );
targetSection.insertAdjacentHTML( targetSection.insertAdjacentHTML(
"afterend", "afterend",
` `
<div id="${this.id}-section-${s}-link-listing-${l}" class="linkListingContainer"> <div id="${this.id}-section-listing--${s}--${l}" class="linkListingContainer">
<span class="${this.id}-link"> <span class="${this.id}-link">
${sectionData[s].links[l].label} ${sectionData[s].links[l].label}
@@ -1320,6 +1320,8 @@
this.id + "-section-" + s this.id + "-section-" + s
); );
console.log(s, l);
targetSection.insertAdjacentHTML( targetSection.insertAdjacentHTML(
"beforeend", "beforeend",
` `
@@ -2015,17 +2017,17 @@
} }
function reorderSection(buttonPressed, direction) { function reorderSection(buttonPressed, direction) {
let temp = buttonPressed.parentElement.parentElement.id.split("-"); let temp = buttonPressed.parentElement.parentElement.id.split("--");
let sectionId = parseInt(temp[temp.length - 1]); let container = containerDataMap.get(temp[0].split("-")[0]);
let container = containerDataMap.get(temp[0]); const sectionIndex = parseInt(temp[temp.length - 1]);
let copy = container.sections[sectionId]; let copy = container.sections[sectionIndex];
if (direction == "up" && sectionId != 0) { if (direction == "up" && sectionIndex != 0) {
container.sections[sectionId] = container.sections[sectionId - 1]; container.sections[sectionIndex] = container.sections[sectionIndex - 1];
container.sections[sectionId - 1] = copy; container.sections[sectionIndex - 1] = copy;
} else if (direction == "down" && (sectionId + 1) != Object.keys(container.sections).length) { } else if (direction == "down" && (sectionIndex + 1) != Object.keys(container.sections).length) {
container.sections[sectionId] = container.sections[sectionId + 1]; container.sections[sectionIndex] = container.sections[sectionIndex + 1];
container.sections[sectionId + 1] = copy; container.sections[sectionIndex + 1] = copy;
} }
container.loadBookmarks(); container.loadBookmarks();
@@ -2033,12 +2035,13 @@
} }
function deleteSection(buttonPressed) { function deleteSection(buttonPressed) {
let temp = buttonPressed.parentElement.parentElement.id.split("-"); let temp = buttonPressed.parentElement.parentElement.id.split("--");
let sectionId = parseInt(temp[temp.length - 1]); let container = containerDataMap.get(temp[0].split("-")[0]);
let container = containerDataMap.get(buttonPressed.parentElement.parentElement.id.split("-section")[0]); const sectionIndex = parseInt(temp[temp.length - 1]);
// delete section
let numSections = Object.keys(container.sections).length; let numSections = Object.keys(container.sections).length;
for (let i = sectionId; i < numSections; i++) { for (let i = sectionIndex; i < numSections; i++) {
container.sections[i] = container.sections[i+1]; container.sections[i] = container.sections[i+1];
} }
// trim last section index that is no longer needed // trim last section index that is no longer needed
@@ -2050,25 +2053,17 @@
} }
function deleteLink(buttonPressed) { function deleteLink(buttonPressed) {
// remove the link from local array let temp = buttonPressed.parentElement.parentElement.id.split("--");
const linkIndex = buttonPressed.parentElement.id.replace("link-", ""); let container = containerDataMap.get(temp[0].split("-")[0]);
links.splice(linkIndex, 1); const sectionIndex = parseInt(temp[temp.length - 2]);
const linkIndex = parseInt(temp[temp.length - 1]);
// determine whether to remove link"s section (if no more links) // delete link
let removeSection = true; container.sections[sectionIndex].links.splice(linkIndex, 1);
const linkSection = buttonPressed.parentElement.parentElement.id;
for (let i = 0; i < links.length; i++) {
if (links[i].section == linkSection) {
removeSection = false;
break;
}
}
// remove section (if needed) + save // refresh screen
if (removeSection) { container.loadBookmarks();
sections.splice(sections.indexOf(linkSection), 1); container.loadBookmarkListings();
}
loadSections();
} }
/****************** /******************