import os
index_path = r'z:\source\forgejo\spotnotes.app\static\assets\js\index.js'
with open(index_path, 'r', encoding='utf-8') as f:
content = f.read()
# Add the filter input to the header
header_replace = """
${window.SpotNotes.escapeHtml(currentName)}
${manageShareBtn}
${exportBtn}
${addNoteBtn}
"""
content = content.replace("""
${window.SpotNotes.escapeHtml(currentName)}
${manageShareBtn}
${exportBtn}
${addNoteBtn}
""", header_replace)
# Now, extract the rendering logic into a new function `window.SpotNotes.renderActiveNotesList`
old_render_block = """
// Render Sidebar List
sidebarBody.innerHTML = '';
if (notes.length === 0) {
sidebarBody.innerHTML = '
`;
item.addEventListener('click', () => {
window.SpotNotes.stopTracking();
window.SpotNotes.map.setView([note.lat, note.lng], 16);
});
sidebarBody.appendChild(item);
});
// We do NOT call window.SpotNotes.renderMapMarkers() here, because we only want to filter the sidebar, not the map itself.
// Wait, the task says: "filtering the existing activeNotes array before re-rendering the sidebar list".
// It doesn't strictly say to filter the map markers, but maybe we should?
// Usually a sidebar filter only filters the list if it says "Add a simple, fast text input filter floating above the note list in the sidebar... filtering the existing activeNotes array before re-rendering the sidebar list".
// We will leave the map markers as they are to show all active notes. Or wait, if we only render the list, the map shows everything. Let's just leave the map markers as is (calling renderMapMarkers once on load).
};
"""
content += "\n" + render_function
with open(index_path, 'w', encoding='utf-8') as f:
f.write(content)
print('Filtered active notes logic applied')