// In-memory state for this page
let privateNotes = [];
// Fetch private notes with Bearer token from Clerk
async function loadPrivateNotes(token) {
const res = await fetch('/api/private-notes', {
headers: { Authorization: `Bearer ${token}` },
});
privateNotes = await res.json();
renderPrivateNotes();
}
// Render private note cards and update count badge
function renderPrivateNotes() {
const grid = document.getElementById('private-notes-grid');
grid.innerHTML = '';
if (!privateNotes.length) {
grid.innerHTML = '<div class="empty-state">No private notes yet.</div>';
document.getElementById('private-count').textContent = '0';
return;
}
for (const note of privateNotes) {
grid.appendChild(privateNoteCard(note));
}
document.getElementById('private-count').textContent = String(privateNotes.length);
}
// Create a private note then refresh the grid
async function createPrivateNote(title, content, token) {
await fetch('/api/private-notes', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({ title, content, isPublic: false }),
});
await loadPrivateNotes(token);
}