${filtered ? 'Nothing matches' : 'Your feed is empty'}${filtered ? 'Try a different search or tag.' : 'Type a thought above and hit Enter. Add #tags to file it.'}
No archived notesUse the box icon on a note to archive it. It leaves your feed but stays searchable.
'
+ : `
${filtered ? 'Nothing matches' : 'Your feed is empty'}${filtered ? 'Try a different search or tag.' : 'Type a thought above and hit Enter. Add #tags to file it.'}
`;
} else {
let html = '', lastDay = '';
for (const n of state.notes) {
@@ -849,6 +858,7 @@ function renderStatus(loading) {
if (q) bits.push(`${q} note${q > 1 ? 's' : ''} waiting to sync`);
if (state.tag) bits.push(`Showing `);
else if (state.pinned) bits.push('Showing pinned notes ');
+ else if (state.archived) bits.push('Showing archived notes ');
if (state.query && !loading) bits.push(`${state.notes.length}${state.hasMore ? '+' : ''} result${state.notes.length === 1 ? '' : 's'}`);
el.innerHTML = bits.join(' ');
el.classList.toggle('hidden', !bits.length);
@@ -856,8 +866,9 @@ function renderStatus(loading) {
function renderTags() {
const total = state.tags.reduce((a, t) => a + Number(t.count), 0);
- let html = ``;
+ let html = ``;
html += ``;
+ html += ``;
for (const t of state.tags) {
html += ``;
}
@@ -943,7 +954,7 @@ document.addEventListener('click', async (e) => {
const tagBtn = e.target.closest('[data-tag]');
if (tagBtn && !e.target.closest('.board-picker')) { setFilter({ tag: tagBtn.dataset.tag }); return; }
const f = e.target.closest('[data-filter]');
- if (f) { setFilter(f.dataset.filter === 'pinned' ? { pinned: true } : {}); return; }
+ if (f) { setFilter(f.dataset.filter === 'pinned' ? { pinned: true } : f.dataset.filter === 'archived' ? { archived: true } : {}); return; }
const actEl = e.target.closest('[data-act]');
if (!actEl) return;
const act = actEl.dataset.act;
@@ -969,11 +980,36 @@ document.addEventListener('click', async (e) => {
state.editing = null; rerender();
} else if (act === 'save') {
await saveEdit(note);
+ } else if (act === 'archive') {
+ archiveNote(note, !note.archived_at);
} else if (act === 'delete') {
deleteNote(note);
}
});
+async function archiveNote(note, archive, quiet = false) {
+ const prev = note.archived_at;
+ const archived_at = archive ? new Date().toISOString() : null;
+ note.archived_at = archived_at;
+ const idx = state.notes.findIndex((n) => n.id === note.id);
+ if (idx >= 0 && !matchesFilter(note)) state.notes.splice(idx, 1);
+ if (archive) for (const k in state.boardNotes) state.boardNotes[k] = state.boardNotes[k].filter((n) => n.id !== note.id);
+ rerender();
+ const { error } = await sb.from('notes').update({ archived_at }).eq('id', note.id);
+ if (error) {
+ note.archived_at = prev;
+ toast('Couldn\'t ' + (archive ? 'archive' : 'unarchive') + ': ' + error.message);
+ loadNotes(true); if (state.view === 'board') loadBoard();
+ return;
+ }
+ scheduleTagRefresh();
+ if (state.view === 'board' && !archive) loadBoard();
+ if (!quiet) toast(archive ? 'Note archived' : 'Note moved back to your feed', 'Undo', async () => {
+ await archiveNote(note, !archive, true);
+ if (matchesFilter(note) && !state.notes.some((n) => n.id === note.id)) loadNotes(true);
+ });
+}
+
document.addEventListener('keydown', (e) => {
if (e.target.id === 'edit-text') {
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) { e.preventDefault(); const n = findNote(state.editing); if (n) saveEdit(n); }
@@ -1005,7 +1041,7 @@ function deleteNote(note) {
undone = true;
await del;
const { _queued, ...row } = note;
- const { data, error } = await sb.from('notes').insert({ id: row.id, body: row.body, tags: row.tags, source: row.source, pinned: row.pinned, attachments: row.attachments, created_at: row.created_at }).select().single();
+ const { data, error } = await sb.from('notes').insert({ id: row.id, body: row.body, tags: row.tags, source: row.source, pinned: row.pinned, attachments: row.attachments, archived_at: row.archived_at ?? null, created_at: row.created_at }).select().single();
if (error) { toast('Couldn\'t restore: ' + error.message); return; }
state.notes.splice(Math.max(0, idx), 0, data); renderFeed(); scheduleTagRefresh();
if (state.view === 'board') loadBoard();
@@ -1027,8 +1063,8 @@ function openLightbox(src) {
// ------------------------------------------------------------------
// Filters, search, views
// ------------------------------------------------------------------
-function setFilter({ tag = null, pinned = false }) {
- state.tag = tag; state.pinned = pinned;
+function setFilter({ tag = null, pinned = false, archived = false }) {
+ state.tag = tag; state.pinned = pinned; state.archived = archived;
if (state.view !== 'feed') switchView('feed');
renderTags(); loadNotes(true);
window.scrollTo({ top: 0, behavior: 'smooth' });
@@ -1084,7 +1120,7 @@ $('#menu').addEventListener('click', async (e) => {
async function exportNotes() {
const all = []; let from = 0;
for (;;) {
- const { data, error } = await sb.from('notes').select('id,body,tags,source,pinned,attachments,created_at,updated_at').order('created_at').range(from, from + 999);
+ const { data, error } = await sb.from('notes').select('id,body,tags,source,pinned,attachments,archived_at,created_at,updated_at').order('created_at').range(from, from + 999);
if (error) { toast('Export failed: ' + error.message); return; }
all.push(...data); if (data.length < 1000) break; from += 1000;
}
@@ -1102,7 +1138,7 @@ async function exportNotes() {
async function loadBoard() {
const cols = state.settings?.board_tags || [];
if (cols.length < 2) { state.boardPicking = true; state.pickTags = [...cols]; renderBoard(); return; }
- const results = await Promise.all(cols.map((t) => sb.from('notes').select('id,body,tags,source,pinned,attachments,created_at').contains('tags', [t]).order('pinned', { ascending: false }).order('created_at', { ascending: false }).limit(100)));
+ const results = await Promise.all(cols.map((t) => sb.from('notes').select('id,body,tags,source,pinned,attachments,created_at').contains('tags', [t]).is('archived_at', null).order('pinned', { ascending: false }).order('created_at', { ascending: false }).limit(100)));
cols.forEach((t, i) => { state.boardNotes[t] = results[i].data || []; });
renderBoard();
}
diff --git a/supabase/migrations/20261004230000_archive_notes.sql b/supabase/migrations/20261004230000_archive_notes.sql
new file mode 100644
index 0000000..ca4f648
--- /dev/null
+++ b/supabase/migrations/20261004230000_archive_notes.sql
@@ -0,0 +1,15 @@
+alter table public.notes add column archived_at timestamptz;
+create index notes_user_archived on public.notes (user_id, archived_at);
+
+-- Tag counts reflect what's in the feed: archived notes are not counted.
+create or replace function public.tag_counts()
+returns table (tag text, count bigint) language sql stable security invoker set search_path = '' as $$
+ select t, count(*) from public.notes n, unnest(n.tags) t
+ where n.user_id = (select auth.uid()) and n.archived_at is null
+ group by t order by count(*) desc, t;
+$$;
+
+create or replace function public.archived_count()
+returns bigint language sql stable security invoker set search_path = '' as $$
+ select count(*) from public.notes n where n.user_id = (select auth.uid()) and n.archived_at is not null;
+$$;
diff --git a/sw.js b/sw.js
index 3461a67..2963fc4 100644
--- a/sw.js
+++ b/sw.js
@@ -1,6 +1,6 @@
// Network-first service worker: always try GitHub Pages for the latest
// version, fall back to the cached copy when offline.
-var CACHE = 'brainfeed-v4';
+var CACHE = 'brainfeed-v5';
var ASSETS = [
'./',
'./index.html',