demos for spacedust

notification filtering ui actually works?

+17 -7
+2 -2
atproto-notifications/src/components/Feed.tsx
··· 89 89 // this could be combined with the broadcast thing above, but for now just chain deps 90 90 const [feed, setFeed] = useState([]); 91 91 useEffect(() => { 92 - (async () => setFeed(await getNotifications()))(); 93 - }, [inc]); 92 + (async () => setFeed(await getNotifications(secondary, secondaryFilter)))(); 93 + }, [inc, secondary, secondaryFilter]); 94 94 95 95 if (feed.length === 0) { 96 96 return 'no notifications loaded';
+15 -5
atproto-notifications/src/db.ts
··· 89 89 }); 90 90 } 91 91 92 - export async function getNotifications(limit = 30) { 92 + export async function getNotifications(secondary, secondaryFilter) { 93 + const limit = 30; 93 94 let res = []; 94 - const oc = (await getDB()) 95 + const store = (await getDB()) 95 96 .transaction([NOTIFICATIONS]) 96 - .objectStore(NOTIFICATIONS) 97 - .openCursor(undefined, 'prev'); 97 + .objectStore(NOTIFICATIONS); 98 + 99 + let oc; 100 + if (!!secondary && secondary !== 'all' && !!secondaryFilter) { 101 + console.log('with', secondary, secondaryFilter) 102 + oc = store 103 + .index(secondary) 104 + .openCursor(IDBKeyRange.only(secondaryFilter), 'prev'); 105 + } else { 106 + oc = store.openCursor(null, 'prev'); 107 + } 98 108 return new Promise((resolve, reject) => { 99 109 oc.onerror = () => reject(oc.error); 100 110 oc.onsuccess = ev => { 101 111 const cursor = event.target.result; 102 112 if (cursor) { 103 - res.push([cursor.key, cursor.value]); 113 + res.push([cursor.value.id, cursor.value]); 104 114 if (res.length < limit) cursor.continue(); 105 115 else resolve(res); 106 116 } else {