refactor relay provider

This commit is contained in:
Ren Amamiya
2023-04-24 08:17:26 +07:00
parent f671521356
commit d52410b857
27 changed files with 113 additions and 87 deletions

View File

@@ -2,6 +2,8 @@ import { NoteMetadata } from '@components/note/metadata';
import { RelayContext } from '@components/relaysProvider';
import { UserExtend } from '@components/user/extend';
import { DEFAULT_RELAYS } from '@stores/constants';
import { contentParser } from '@utils/parser';
import { createNote, getNoteByID } from '@utils/storage';
import { getParentID } from '@utils/transform';
@@ -10,7 +12,7 @@ import useLocalStorage from '@rehooks/local-storage';
import { memo, useCallback, useContext, useEffect, useState } from 'react';
export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
const [pool, relays]: any = useContext(RelayContext);
const pool: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
const [event, setEvent] = useState(null);
@@ -25,7 +27,7 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
kinds: [1],
},
],
relays,
DEFAULT_RELAYS,
(event: any) => {
// update state
setEvent(event);
@@ -53,7 +55,7 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
return () => {
unsubscribe();
};
}, [activeAccount.id, id, pool, relays]);
}, [activeAccount.id, id, pool]);
const checkNoteIsSaved = useCallback(async () => {
getNoteByID(id)