import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk'; import { LRUCache } from 'lru-cache'; import { useState } from 'react'; import { toast } from 'sonner'; import { useNDK } from '@libs/ndk/provider'; import { useStorage } from '@libs/storage/provider'; import { CheckCircleIcon, LoaderIcon } from '@shared/icons'; import { useOnboarding } from '@stores/onboarding'; export function Circle() { const { db } = useStorage(); const { ndk } = useNDK(); const [circle, setCircle] = useOnboarding((state) => [ state.circle, state.toggleCircle, ]); const [loading, setLoading] = useState(false); const enableLinks = async () => { setLoading(true); const users = ndk.getUser({ pubkey: db.account.pubkey }); const follows = await users.follows(); if (follows.size === 0) { setLoading(false); return toast('You need to follow at least 1 account'); } const lru = new LRUCache({ max: 300 }); const followsAsArr = []; // add user's follows to lru follows.forEach((user) => { lru.set(user.pubkey, user.pubkey); followsAsArr.push(user.pubkey); }); // get follows from follows const events = await ndk.fetchEvents({ kinds: [NDKKind.Contacts], authors: followsAsArr, limit: 300, }); events.forEach((event: NDKEvent) => { event.tags.forEach((tag) => { if (tag[0] === 'p') lru.set(tag[1], tag[1]); }); }); // get lru values const circleList = [...lru.values()] as string[]; // update db await db.updateAccount('follows', JSON.stringify(followsAsArr)); await db.updateAccount('circles', JSON.stringify(circleList)); db.account.follows = followsAsArr; db.account.circles = circleList; // clear lru lru.clear(); // done await db.createSetting('circles', '1'); setCircle(); }; return (
Enable Circle

Beside newsfeed from your follows, you will see more content from all people that followed by your follows.

{circle ? (
) : ( )}
); }