This commit is contained in:
Ren Amamiya
2023-08-06 15:11:58 +07:00
parent 71338b3b07
commit 02ff9e3b68
34 changed files with 321 additions and 320 deletions

View File

@@ -1,5 +1,5 @@
// source: https://github.com/nostr-dev-kit/ndk-react/
import NDK from '@nostr-dev-kit/ndk';
import NDK, { NDKCacheAdapter } from '@nostr-dev-kit/ndk';
import { ndkAdapter } from '@nostr-fetch/adapter-ndk';
import { NostrFetcher, normalizeRelayUrlSet } from 'nostr-fetch';
import { useEffect, useState } from 'react';
@@ -16,11 +16,15 @@ export const NDKInstance = () => {
const [fetcher, setFetcher] = useState<NostrFetcher>(undefined);
useEffect(() => {
loadNdk(relays);
}, []);
async function loadNdk(explicitRelayUrls: string[]) {
const cacheAdapter = new TauriAdapter();
loadNdk(relays, cacheAdapter);
return () => {
cacheAdapter.save();
};
}, [relays]);
async function loadNdk(explicitRelayUrls: string[], cacheAdapter: NDKCacheAdapter) {
const ndkInstance = new NDK({ explicitRelayUrls, cacheAdapter });
try {