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,7 +2,7 @@ import { AvatarUploader } from '@components/avatarUploader';
import { RelayContext } from '@components/relaysProvider';
import { defaultChannelsAtom } from '@stores/channel';
import { DEFAULT_AVATAR, FULL_RELAYS } from '@stores/constants';
import { DEFAULT_AVATAR, MESSAGE_RELAYS } from '@stores/constants';
import { dateToUnix } from '@utils/getDate';
import { createChannel } from '@utils/storage';
@@ -17,7 +17,7 @@ import { useForm } from 'react-hook-form';
import { navigate } from 'vite-plugin-ssr/client/router';
export const CreateChannelModal = () => {
const [pool]: any = useContext(RelayContext);
const pool: any = useContext(RelayContext);
const [open, setOpen] = useState(false);
const [activeAccount]: any = useLocalStorage('account', {});
const [image, setImage] = useState(DEFAULT_AVATAR);
@@ -47,7 +47,7 @@ export const CreateChannelModal = () => {
event.sig = signEvent(event, activeAccount.privkey);
// publish channel
pool.publish(event, FULL_RELAYS);
pool.publish(event, MESSAGE_RELAYS);
// insert to database
createChannel(event.id, event.content, event.created_at);
// update jotai state

View File

@@ -1,5 +1,7 @@
import { RelayContext } from '@components/relaysProvider';
import { MESSAGE_RELAYS } from '@stores/constants';
import { dateToUnix } from '@utils/getDate';
import * as AlertDialog from '@radix-ui/react-alert-dialog';
@@ -10,7 +12,7 @@ import { getEventHash, signEvent } from 'nostr-tools';
import { useCallback, useContext } from 'react';
export const HideMessageButton = ({ id }: { id: string }) => {
const [pool, relays]: any = useContext(RelayContext);
const pool: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
const hideMessage = useCallback(() => {
@@ -25,8 +27,8 @@ export const HideMessageButton = ({ id }: { id: string }) => {
event.sig = signEvent(event, activeAccount.privkey);
// publish note
pool.publish(event, relays);
}, [id, activeAccount.privkey, activeAccount.pubkey, pool, relays]);
pool.publish(event, MESSAGE_RELAYS);
}, [id, activeAccount.privkey, activeAccount.pubkey, pool, MESSAGE_RELAYS]);
return (
<AlertDialog.Root>

View File

@@ -1,5 +1,7 @@
import { RelayContext } from '@components/relaysProvider';
import { MESSAGE_RELAYS } from '@stores/constants';
import { dateToUnix } from '@utils/getDate';
import * as AlertDialog from '@radix-ui/react-alert-dialog';
@@ -7,13 +9,13 @@ import * as Tooltip from '@radix-ui/react-tooltip';
import useLocalStorage from '@rehooks/local-storage';
import { MicMute } from 'iconoir-react';
import { getEventHash, signEvent } from 'nostr-tools';
import { useCallback, useContext } from 'react';
import { useContext } from 'react';
export const MuteButton = ({ pubkey }: { pubkey: string }) => {
const [pool, relays]: any = useContext(RelayContext);
const pool: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
const muteUser = useCallback(() => {
const muteUser = () => {
const event: any = {
content: '',
created_at: dateToUnix(),
@@ -25,8 +27,8 @@ export const MuteButton = ({ pubkey }: { pubkey: string }) => {
event.sig = signEvent(event, activeAccount.privkey);
// publish note
pool.publish(event, relays);
}, [pubkey, activeAccount.privkey, activeAccount.pubkey, pool, relays]);
pool.publish(event, MESSAGE_RELAYS);
};
return (
<AlertDialog.Root>