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
+3 -2
View File
@@ -1,6 +1,7 @@
import { ImagePicker } from '@components/form/imagePicker';
import { RelayContext } from '@components/relaysProvider';
import { DEFAULT_RELAYS } from '@stores/constants';
import { noteContentAtom } from '@stores/note';
import { dateToUnix } from '@utils/getDate';
@@ -12,7 +13,7 @@ import { getEventHash, signEvent } from 'nostr-tools';
import { useContext } from 'react';
export default function FormBase() {
const [pool, relays]: any = useContext(RelayContext);
const pool: any = useContext(RelayContext);
const [value, setValue] = useAtom(noteContentAtom);
const resetValue = useResetAtom(noteContentAtom);
@@ -31,7 +32,7 @@ export default function FormBase() {
event.sig = signEvent(event, activeAccount.privkey);
// publish note
pool.publish(event, relays);
pool.publish(event, DEFAULT_RELAYS);
// reset form
resetValue();
// send notification
+3 -3
View File
@@ -3,7 +3,7 @@ import { RelayContext } from '@components/relaysProvider';
import { UserMini } from '@components/user/mini';
import { channelContentAtom, channelReplyAtom } from '@stores/channel';
import { FULL_RELAYS } from '@stores/constants';
import { MESSAGE_RELAYS } from '@stores/constants';
import { dateToUnix } from '@utils/getDate';
@@ -15,7 +15,7 @@ import { getEventHash, signEvent } from 'nostr-tools';
import { useCallback, useContext } from 'react';
export const FormChannel = ({ eventId }: { eventId: string | string[] }) => {
const [pool]: any = useContext(RelayContext);
const pool: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
const [value, setValue] = useAtom(channelContentAtom);
@@ -48,7 +48,7 @@ export const FormChannel = ({ eventId }: { eventId: string | string[] }) => {
event.sig = signEvent(event, activeAccount.privkey);
// publish note
pool.publish(event, FULL_RELAYS);
pool.publish(event, MESSAGE_RELAYS);
// reset state
resetValue();
// reset channel reply
+3 -3
View File
@@ -2,7 +2,7 @@ import { ImagePicker } from '@components/form/imagePicker';
import { RelayContext } from '@components/relaysProvider';
import { chatContentAtom } from '@stores/chat';
import { FULL_RELAYS } from '@stores/constants';
import { MESSAGE_RELAYS } from '@stores/constants';
import { dateToUnix } from '@utils/getDate';
@@ -13,7 +13,7 @@ import { getEventHash, nip04, signEvent } from 'nostr-tools';
import { useCallback, useContext } from 'react';
export default function FormChat({ receiverPubkey }: { receiverPubkey: string }) {
const [pool]: any = useContext(RelayContext);
const pool: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
const [value, setValue] = useAtom(chatContentAtom);
@@ -39,7 +39,7 @@ export default function FormChat({ receiverPubkey }: { receiverPubkey: string })
event.id = getEventHash(event);
event.sig = signEvent(event, activeAccount.privkey);
// publish note
pool.publish(event, FULL_RELAYS);
pool.publish(event, MESSAGE_RELAYS);
// reset state
resetValue();
})
+5 -9
View File
@@ -1,6 +1,7 @@
import { ImageWithFallback } from '@components/imageWithFallback';
import { RelayContext } from '@components/relaysProvider';
import { DEFAULT_RELAYS } from '@stores/constants';
import { dateToUnix } from '@utils/getDate';
import useLocalStorage from '@rehooks/local-storage';
@@ -8,7 +9,7 @@ import { getEventHash, signEvent } from 'nostr-tools';
import { useContext, useState } from 'react';
export default function FormComment({ eventID }: { eventID: any }) {
const [pool, relays]: any = useContext(RelayContext);
const pool: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
const [value, setValue] = useState('');
@@ -27,7 +28,7 @@ export default function FormComment({ eventID }: { eventID: any }) {
event.sig = signEvent(event, activeAccount.privkey);
// publish note
pool.publish(event, relays);
pool.publish(event, DEFAULT_RELAYS);
// send notification
// sendNotification('Comment has been published successfully');
};
@@ -37,12 +38,7 @@ export default function FormComment({ eventID }: { eventID: any }) {
<div className="flex gap-1">
<div>
<div className="relative h-11 w-11 shrink-0 overflow-hidden rounded-md border border-white/10">
<ImageWithFallback
src={profile?.picture}
alt={activeAccount.pubkey}
fill={true}
className="rounded-md object-cover"
/>
<img src={profile?.picture} alt={activeAccount.pubkey} className="h-11 w-11 rounded-md object-cover" />
</div>
</div>
<div className="relative h-24 w-full flex-1 overflow-hidden before:pointer-events-none before:absolute before:-inset-1 before:rounded-[11px] before:border before:border-fuchsia-500 before:opacity-0 before:ring-2 before:ring-fuchsia-500/20 before:transition after:pointer-events-none after:absolute after:inset-px after:rounded-[7px] after:shadow-highlight after:shadow-white/5 after:transition focus-within:before:opacity-100 focus-within:after:shadow-fuchsia-500/100 dark:focus-within:after:shadow-fuchsia-500/20">