mirror of
https://github.com/layer-systems/website.git
synced 2026-06-17 01:58:30 +02:00
refactor: comment out unused imports and effect in NostrSync component
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useNostr } from '@nostrify/react';
|
||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
// import { useEffect } from 'react';
|
||||
// import { useNostr } from '@nostrify/react';
|
||||
// import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
// import { useAppContext } from '@/hooks/useAppContext';
|
||||
|
||||
/**
|
||||
* NostrSync - Syncs user's Nostr data
|
||||
@@ -11,52 +11,52 @@ import { useAppContext } from '@/hooks/useAppContext';
|
||||
* - NIP-65 relay list (kind 10002)
|
||||
*/
|
||||
export function NostrSync() {
|
||||
const { nostr } = useNostr();
|
||||
const { user } = useCurrentUser();
|
||||
const { config, updateConfig } = useAppContext();
|
||||
// const { nostr } = useNostr();
|
||||
// const { user } = useCurrentUser();
|
||||
// const { config, updateConfig } = useAppContext();
|
||||
|
||||
useEffect(() => {
|
||||
if (!user) return;
|
||||
// useEffect(() => {
|
||||
// if (!user) return;
|
||||
|
||||
const syncRelaysFromNostr = async () => {
|
||||
try {
|
||||
const events = await nostr.query(
|
||||
[{ kinds: [10002], authors: [user.pubkey], limit: 1 }],
|
||||
{ signal: AbortSignal.timeout(5000) }
|
||||
);
|
||||
// const syncRelaysFromNostr = async () => {
|
||||
// try {
|
||||
// const events = await nostr.query(
|
||||
// [{ kinds: [10002], authors: [user.pubkey], limit: 1 }],
|
||||
// { signal: AbortSignal.timeout(5000) }
|
||||
// );
|
||||
|
||||
if (events.length > 0) {
|
||||
const event = events[0];
|
||||
// if (events.length > 0) {
|
||||
// const event = events[0];
|
||||
|
||||
// Only update if the event is newer than our stored data
|
||||
if (event.created_at > config.relayMetadata.updatedAt) {
|
||||
const fetchedRelays = event.tags
|
||||
.filter(([name]) => name === 'r')
|
||||
.map(([_, url, marker]) => ({
|
||||
url,
|
||||
read: !marker || marker === 'read',
|
||||
write: !marker || marker === 'write',
|
||||
}));
|
||||
// // Only update if the event is newer than our stored data
|
||||
// if (event.created_at > config.relayMetadata.updatedAt) {
|
||||
// const fetchedRelays = event.tags
|
||||
// .filter(([name]) => name === 'r')
|
||||
// .map(([_, url, marker]) => ({
|
||||
// url,
|
||||
// read: !marker || marker === 'read',
|
||||
// write: !marker || marker === 'write',
|
||||
// }));
|
||||
|
||||
if (fetchedRelays.length > 0) {
|
||||
console.log('Syncing relay list from Nostr:', fetchedRelays);
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
relayMetadata: {
|
||||
relays: fetchedRelays,
|
||||
updatedAt: event.created_at,
|
||||
},
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to sync relays from Nostr:', error);
|
||||
}
|
||||
};
|
||||
// if (fetchedRelays.length > 0) {
|
||||
// console.log('Syncing relay list from Nostr:', fetchedRelays);
|
||||
// updateConfig((current) => ({
|
||||
// ...current,
|
||||
// relayMetadata: {
|
||||
// relays: fetchedRelays,
|
||||
// updatedAt: event.created_at,
|
||||
// },
|
||||
// }));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (error) {
|
||||
// console.error('Failed to sync relays from Nostr:', error);
|
||||
// }
|
||||
// };
|
||||
|
||||
syncRelaysFromNostr();
|
||||
}, [user, config.relayMetadata.updatedAt, nostr, updateConfig]);
|
||||
// syncRelaysFromNostr();
|
||||
// }, [user, config.relayMetadata.updatedAt, nostr, updateConfig]);
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user