polish
This commit is contained in:
@@ -47,8 +47,11 @@ export default class TauriAdapter implements NDKCacheAdapter {
|
||||
Promise.all([
|
||||
this.store.set(event.id, JSON.stringify(nostrEvent)),
|
||||
this.store.set(key, event.id),
|
||||
this.store.save(),
|
||||
]).then(() => resolve());
|
||||
});
|
||||
}
|
||||
|
||||
public save() {
|
||||
return this.store.save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -24,8 +24,12 @@ export async function getActiveAccount() {
|
||||
'SELECT * FROM accounts WHERE is_active = 1;'
|
||||
);
|
||||
if (result.length > 0) {
|
||||
result[0].follows = destr(result[0].follows);
|
||||
result[0].network = destr(result[0].network);
|
||||
result[0]['follows'] = result[0].follows
|
||||
? JSON.parse(result[0].follows as unknown as string)
|
||||
: [];
|
||||
result[0]['network'] = result[0].network
|
||||
? JSON.parse(result[0].network as unknown as string)
|
||||
: [];
|
||||
return result[0];
|
||||
} else {
|
||||
return null;
|
||||
@@ -423,10 +427,19 @@ export async function createBlock(
|
||||
) {
|
||||
const db = await connect();
|
||||
const activeAccount = await getActiveAccount();
|
||||
return await db.execute(
|
||||
const insert = await db.execute(
|
||||
'INSERT OR IGNORE INTO blocks (account_id, kind, title, content) VALUES (?, ?, ?, ?);',
|
||||
[activeAccount.id, kind, title, content]
|
||||
);
|
||||
|
||||
if (insert) {
|
||||
const record: Block = await db.select(
|
||||
'SELECT * FROM blocks ORDER BY id DESC LIMIT 1;'
|
||||
);
|
||||
return record[0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// remove block
|
||||
|
||||
Reference in New Issue
Block a user