refactor relay provider
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { RelayContext } from '@components/relaysProvider';
|
||||
import { UserExtend } from '@components/user/extend';
|
||||
|
||||
import { DEFAULT_RELAYS } from '@stores/constants';
|
||||
|
||||
import { dateToUnix } from '@utils/getDate';
|
||||
|
||||
import * as Dialog from '@radix-ui/react-dialog';
|
||||
@@ -23,7 +25,7 @@ export const NoteComment = ({
|
||||
eventTime: number;
|
||||
eventContent: any;
|
||||
}) => {
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
const pool: any = useContext(RelayContext);
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
const [value, setValue] = useState('');
|
||||
@@ -46,7 +48,7 @@ export const NoteComment = ({
|
||||
event.id = getEventHash(event);
|
||||
event.sig = signEvent(event, activeAccount.privkey);
|
||||
|
||||
pool.publish(event, relays);
|
||||
pool.publish(event, DEFAULT_RELAYS);
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { RelayContext } from '@components/relaysProvider';
|
||||
|
||||
import { DEFAULT_RELAYS } from '@stores/constants';
|
||||
|
||||
import { dateToUnix } from '@utils/getDate';
|
||||
|
||||
import useLocalStorage from '@rehooks/local-storage';
|
||||
@@ -18,7 +20,7 @@ export const NoteReaction = ({
|
||||
eventID: string;
|
||||
eventPubkey: string;
|
||||
}) => {
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
const pool: any = useContext(RelayContext);
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
|
||||
const [isReact, setIsReact] = useState(false);
|
||||
@@ -41,7 +43,7 @@ export const NoteReaction = ({
|
||||
event.id = getEventHash(event);
|
||||
event.sig = signEvent(event, activeAccount.privkey);
|
||||
// publish event to all relays
|
||||
pool.publish(event, relays);
|
||||
pool.publish(event, DEFAULT_RELAYS);
|
||||
// update state to change icon to filled heart
|
||||
setIsReact(true);
|
||||
// update counter
|
||||
|
||||
@@ -2,6 +2,8 @@ import { NoteComment } from '@components/note/meta/comment';
|
||||
import { NoteReaction } from '@components/note/meta/reaction';
|
||||
import { RelayContext } from '@components/relaysProvider';
|
||||
|
||||
import { DEFAULT_RELAYS } from '@stores/constants';
|
||||
|
||||
import useLocalStorage from '@rehooks/local-storage';
|
||||
import { memo, useContext, useEffect, useState } from 'react';
|
||||
|
||||
@@ -16,7 +18,7 @@ export const NoteMetadata = memo(function NoteMetadata({
|
||||
eventTime: any;
|
||||
eventContent: any;
|
||||
}) {
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
const pool: any = useContext(RelayContext);
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
|
||||
const [liked, setLiked] = useState(false);
|
||||
@@ -32,7 +34,7 @@ export const NoteMetadata = memo(function NoteMetadata({
|
||||
kinds: [1, 7],
|
||||
},
|
||||
],
|
||||
relays,
|
||||
DEFAULT_RELAYS,
|
||||
(event: any) => {
|
||||
switch (event.kind) {
|
||||
case 1:
|
||||
@@ -64,7 +66,7 @@ export const NoteMetadata = memo(function NoteMetadata({
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
}, [eventID, eventTime, pool, relays, activeAccount.pubkey]);
|
||||
}, [eventID, eventTime, pool, activeAccount.pubkey]);
|
||||
|
||||
return (
|
||||
<div className="relative z-10 -ml-1 flex items-center gap-8">
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
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';
|
||||
@@ -9,7 +11,7 @@ import useLocalStorage from '@rehooks/local-storage';
|
||||
import { memo, useCallback, useContext, useEffect, useState } from 'react';
|
||||
|
||||
export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) {
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
const pool: any = useContext(RelayContext);
|
||||
|
||||
const [activeAccount]: any = useLocalStorage('account', {});
|
||||
const [event, setEvent] = useState(null);
|
||||
@@ -24,7 +26,7 @@ export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) {
|
||||
kinds: [1],
|
||||
},
|
||||
],
|
||||
relays,
|
||||
DEFAULT_RELAYS,
|
||||
(event: any) => {
|
||||
// update state
|
||||
setEvent(event);
|
||||
@@ -51,7 +53,7 @@ export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) {
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
}, [activeAccount.id, id, pool, relays]);
|
||||
}, [activeAccount.id, id, pool]);
|
||||
|
||||
const checkNoteIsSaved = useCallback(async () => {
|
||||
getNoteByID(id)
|
||||
|
||||
@@ -2,13 +2,15 @@ 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 { memo, useCallback, useContext, useEffect, useState } from 'react';
|
||||
import { navigate } from 'vite-plugin-ssr/client/router';
|
||||
|
||||
export const RootNote = memo(function RootNote({ event }: { event: any }) {
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
const pool: any = useContext(RelayContext);
|
||||
|
||||
const [data, setData] = useState(null);
|
||||
const [content, setContent] = useState('');
|
||||
@@ -36,7 +38,7 @@ export const RootNote = memo(function RootNote({ event }: { event: any }) {
|
||||
kinds: [1],
|
||||
},
|
||||
],
|
||||
relays,
|
||||
DEFAULT_RELAYS,
|
||||
(event: any) => {
|
||||
setData(event);
|
||||
setContent(contentParser(event.content, event.tags));
|
||||
@@ -52,7 +54,7 @@ export const RootNote = memo(function RootNote({ event }: { event: any }) {
|
||||
unsubscribe();
|
||||
};
|
||||
},
|
||||
[pool, relays]
|
||||
[pool]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user