mirror of
https://github.com/luminous-devs/lume.git
synced 2024-09-19 11:43:30 +00:00
clean up
This commit is contained in:
parent
c1d818c69d
commit
3ad1fff4f8
@ -4,6 +4,6 @@ import { createContext, useMemo } from 'react';
|
||||
export const RelayContext = createContext({});
|
||||
|
||||
export default function RelayProvider({ relays, children }: { relays: any; children: React.ReactNode }) {
|
||||
const value = useMemo(() => new RelayPool(relays, { useEventCache: true, logSubscriptions: false }), [relays]);
|
||||
const value = useMemo(() => new RelayPool(relays, { useEventCache: false, logSubscriptions: false }), [relays]);
|
||||
return <RelayContext.Provider value={value}>{children}</RelayContext.Provider>;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import { RelayContext } from '@components/contexts/relay';
|
||||
import { Content } from '@components/note/content';
|
||||
|
||||
import useLocalStorage from '@rehooks/local-storage';
|
||||
import { memo, useCallback, useContext, useMemo, useState } from 'react';
|
||||
import { memo, useCallback, useContext, useEffect, useState } from 'react';
|
||||
|
||||
export const RootNote = memo(function RootNote({ id }: { id: string }) {
|
||||
const { db }: any = useContext(DatabaseContext);
|
||||
@ -26,7 +26,7 @@ export const RootNote = memo(function RootNote({ id }: { id: string }) {
|
||||
const getData = useCallback(async () => {
|
||||
const result = await db.select(`SELECT * FROM cache_notes WHERE id = "${id}"`);
|
||||
return result[0];
|
||||
}, []);
|
||||
}, [db, id]);
|
||||
|
||||
const fetchEvent = useCallback(() => {
|
||||
relayPool.subscribe(
|
||||
@ -53,7 +53,7 @@ export const RootNote = memo(function RootNote({ id }: { id: string }) {
|
||||
);
|
||||
}, [id, insertDB, relayPool, relays]);
|
||||
|
||||
useMemo(() => {
|
||||
useEffect(() => {
|
||||
getData()
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
|
@ -8,16 +8,7 @@ import { useLocalStorage, writeStorage } from '@rehooks/local-storage';
|
||||
import Image from 'next/image';
|
||||
import { useRouter } from 'next/router';
|
||||
import { generatePrivateKey, getEventHash, getPublicKey, nip19, signEvent } from 'nostr-tools';
|
||||
import {
|
||||
JSXElementConstructor,
|
||||
ReactElement,
|
||||
ReactFragment,
|
||||
ReactPortal,
|
||||
useCallback,
|
||||
useContext,
|
||||
useMemo,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { JSXElementConstructor, ReactElement, ReactFragment, ReactPortal, useContext, useMemo, useState } from 'react';
|
||||
import { Config, names, uniqueNamesGenerator } from 'unique-names-generator';
|
||||
|
||||
const config: Config = {
|
||||
@ -42,6 +33,7 @@ export default function Page() {
|
||||
const npub = nip19.npubEncode(pubKey);
|
||||
const nsec = nip19.nsecEncode(privKey);
|
||||
|
||||
// toggle privatek key
|
||||
const showPrivateKey = () => {
|
||||
if (type === 'password') {
|
||||
setType('text');
|
||||
@ -49,7 +41,6 @@ export default function Page() {
|
||||
setType('password');
|
||||
}
|
||||
};
|
||||
|
||||
// auto-generated profile
|
||||
const data = useMemo(
|
||||
() => ({
|
||||
@ -61,16 +52,16 @@ export default function Page() {
|
||||
}),
|
||||
[name]
|
||||
);
|
||||
|
||||
const insertDB = useCallback(async () => {
|
||||
// insert to database
|
||||
const insertDB = async () => {
|
||||
await db.execute(
|
||||
`INSERT INTO accounts (id, privkey, npub, nsec, metadata) VALUES ("${pubKey}", "${privKey}", "${npub}", "${nsec}", '${JSON.stringify(
|
||||
data
|
||||
)}')`
|
||||
);
|
||||
}, [data, db, npub, nsec, privKey, pubKey]);
|
||||
|
||||
const createAccount = async () => {
|
||||
};
|
||||
// build event and broadcast to all relays
|
||||
const createAccount = () => {
|
||||
setLoading(true);
|
||||
|
||||
// build event
|
||||
@ -83,7 +74,7 @@ export default function Page() {
|
||||
};
|
||||
event.id = getEventHash(event);
|
||||
event.sig = signEvent(event, privKey);
|
||||
|
||||
// insert to database then broadcast
|
||||
insertDB()
|
||||
.then(() => {
|
||||
// publish to relays
|
||||
|
@ -78,7 +78,6 @@ export default function Page() {
|
||||
const arr = follows.includes(pubkey) ? follows.filter((i) => i !== pubkey) : [...follows, pubkey];
|
||||
setFollows(arr);
|
||||
};
|
||||
|
||||
// insert follow to database
|
||||
const insertDB = async () => {
|
||||
// self follow
|
||||
@ -92,7 +91,6 @@ export default function Page() {
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
// build event tags
|
||||
const createTags = () => {
|
||||
const tags = [];
|
||||
@ -103,7 +101,6 @@ export default function Page() {
|
||||
|
||||
return tags;
|
||||
};
|
||||
|
||||
// commit and publish to relays
|
||||
const createFollows = () => {
|
||||
setLoading(true);
|
||||
|
@ -45,7 +45,6 @@ export default function Page() {
|
||||
},
|
||||
[db, privkey, pubkey]
|
||||
);
|
||||
|
||||
// save follows to database
|
||||
const insertFollows = useCallback(
|
||||
async (follows) => {
|
||||
@ -60,13 +59,13 @@ export default function Page() {
|
||||
},
|
||||
[db, pubkey]
|
||||
);
|
||||
|
||||
// submit then redirect to home
|
||||
const submit = () => {
|
||||
router.push('/');
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
relayPool.subscribe(
|
||||
const unsubscribe = relayPool.subscribe(
|
||||
[
|
||||
{
|
||||
authors: [pubkey],
|
||||
@ -89,6 +88,10 @@ export default function Page() {
|
||||
console.log(events, relayURL);
|
||||
}
|
||||
);
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
}, [insertAccount, insertFollows, pubkey, relayPool, relays]);
|
||||
|
||||
return (
|
||||
|
Loading…
Reference in New Issue
Block a user