-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major Saving Overhaul (Final Iteration 1)
Ensure restoration of event listeners on loading of network. Fixes issues #30 and #31 This Update mostly contains UI improvements to the saved coordinates container. *could still be added to the actual save data...
- Loading branch information
1 parent
39e021a
commit 5ecb058
Showing
7 changed files
with
371 additions
and
244 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,86 @@ | ||
let selectedCoordinateDiv = null; // Global variable to keep track of the selected div | ||
let selectedCoordinateIndex = null; // Global variable to keep track of the selected index | ||
|
||
function displaySavedCoordinates() { | ||
const savedViews = getSavedViewsFromCache(); | ||
const container = document.getElementById('savedCoordinatesContainer'); | ||
function distributeCoordinates(savedViews) { | ||
const mainCount = Math.round(savedViews.length * 0.50); // 50% for main | ||
const topCount = Math.round(savedViews.length * 0.30); // 35% for top | ||
// For the bottom, we use the remaining views | ||
const bottomCount = savedViews.length - mainCount - topCount; // 15% for bottom | ||
|
||
return { | ||
mainViews: savedViews.slice(0, mainCount), | ||
topViews: savedViews.slice(mainCount, mainCount + topCount), | ||
bottomViews: savedViews.slice(mainCount + topCount) | ||
}; | ||
} | ||
|
||
function appendViewsToContainer(views, containerId, startIndex) { | ||
const container = document.getElementById(containerId); | ||
container.innerHTML = ''; | ||
|
||
savedViews.forEach((view, index) => { | ||
views.forEach((view, index) => { | ||
const globalIndex = startIndex + index; | ||
const coordElement = document.createElement('div'); | ||
coordElement.textContent = `${view.title}`; | ||
coordElement.classList.add('saved-coordinate-item'); | ||
|
||
coordElement.addEventListener('click', () => { | ||
neuriteReturnToSavedView(view); | ||
|
||
// Remove 'selected-coordinate' class from all divs | ||
// Update selected state | ||
document.querySelectorAll('.saved-coordinate-item').forEach(div => { | ||
div.classList.remove('selected-coordinate'); | ||
div.style.transform = ''; // Reset transform | ||
}); | ||
|
||
// Add 'selected-coordinate' class to the clicked div | ||
coordElement.classList.add('selected-coordinate'); | ||
selectedCoordinateIndex = index; | ||
coordElement.style.transform = 'scale(0.95)'; // Scale down for selected | ||
selectedCoordinateIndex = globalIndex; | ||
selectedCoordinateDiv = coordElement; | ||
}); | ||
|
||
// Reset the scale when mouse leaves the selected item | ||
coordElement.addEventListener('mouseleave', () => { | ||
if (coordElement.classList.contains('selected-coordinate')) { | ||
coordElement.style.transform = 'scale(1)'; | ||
} | ||
}); | ||
|
||
container.appendChild(coordElement); | ||
}); | ||
} | ||
|
||
function displaySavedCoordinates() { | ||
const savedViews = getSavedViewsFromCache(); | ||
const { mainViews, topViews, bottomViews } = distributeCoordinates(savedViews); | ||
|
||
appendViewsToContainer(mainViews, 'savedCoordinatesContainer', 0); | ||
appendViewsToContainer(topViews, 'savedCoordinatesContainerTop', mainViews.length); | ||
appendViewsToContainer(bottomViews, 'savedCoordinatesContainerBottom', mainViews.length + topViews.length); | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
// Update the cache | ||
updateSavedViewsCache(); | ||
|
||
displaySavedCoordinates(); | ||
}); | ||
|
||
document.getElementById('deleteCoordinatesBtn').addEventListener('click', function () { | ||
if (selectedCoordinateIndex !== null && savedViews[selectedCoordinateIndex]) { | ||
// Remove the selected view from the array | ||
savedViews.splice(selectedCoordinateIndex, 1); | ||
|
||
// Update the cache | ||
updateSavedViewsCache(); | ||
|
||
// Refresh the display of saved coordinates | ||
displaySavedCoordinates(); | ||
|
||
// Reset the selected coordinate index and div | ||
selectedCoordinateIndex = null; | ||
selectedCoordinateDiv = null; | ||
if (selectedCoordinateIndex !== null) { | ||
neuriteDeleteSavedView(selectedCoordinateIndex); | ||
} else { | ||
alert('No coordinate selected for deletion.'); | ||
} | ||
}); | ||
|
||
document.addEventListener('click', function (event) { | ||
if (!event.target.closest('#savedCoordinatesContainer')) { | ||
if (selectedCoordinateDiv) { | ||
selectedCoordinateDiv.classList.remove('selected-coordinate'); | ||
selectedCoordinateDiv = null; | ||
selectedCoordinateIndex = null; | ||
} | ||
function deselectCoordinate() { | ||
// If there's no selected coordinate, exit the function immediately | ||
if (!selectedCoordinateDiv) { | ||
return; | ||
} | ||
}); | ||
|
||
selectedCoordinateDiv.classList.remove('selected-coordinate'); | ||
selectedCoordinateDiv = null; | ||
selectedCoordinateIndex = null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters