From 340e453b3e62405884e3fd5730d2e798a36daaf4 Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Sun, 23 Apr 2023 15:10:07 +0700 Subject: [PATCH] updated create channel modal --- src/components/channels/channelList.tsx | 15 +--- .../channels/createChannelModal.tsx | 85 +++++++++++++------ src/components/layouts/channel.tsx | 31 +++++++ src/pages/create-channel/index.page.tsx | 9 -- src/pages/index.page.tsx | 4 +- 5 files changed, 95 insertions(+), 49 deletions(-) create mode 100644 src/components/layouts/channel.tsx delete mode 100644 src/pages/create-channel/index.page.tsx diff --git a/src/components/channels/channelList.tsx b/src/components/channels/channelList.tsx index ae9e990f..0e9b3dfb 100644 --- a/src/components/channels/channelList.tsx +++ b/src/components/channels/channelList.tsx @@ -1,26 +1,15 @@ import { ChannelListItem } from '@components/channels/channelListItem'; +import { CreateChannelModal } from '@components/channels/createChannelModal'; import { DEFAULT_CHANNELS } from '@stores/constants'; -import { Plus } from 'iconoir-react'; - export default function ChannelList() { return (
{DEFAULT_CHANNELS.map((item) => ( ))} - -
- -
-
-
Add a new channel
-
-
+
); } diff --git a/src/components/channels/createChannelModal.tsx b/src/components/channels/createChannelModal.tsx index 11cedf09..839fc1d8 100644 --- a/src/components/channels/createChannelModal.tsx +++ b/src/components/channels/createChannelModal.tsx @@ -1,6 +1,9 @@ import { RelayContext } from '@components/relaysProvider'; +import { FULL_RELAYS } from '@stores/constants'; + import { dateToUnix } from '@utils/getDate'; +import { createChannel } from '@utils/storage'; import * as Dialog from '@radix-ui/react-dialog'; import useLocalStorage from '@rehooks/local-storage'; @@ -10,7 +13,7 @@ import { useContext, useState } from 'react'; import { useForm } from 'react-hook-form'; export const CreateChannelModal = () => { - const [pool, relays]: any = useContext(RelayContext); + const [pool]: any = useContext(RelayContext); const [open, setOpen] = useState(false); const [activeAccount]: any = useLocalStorage('account', {}); @@ -21,7 +24,7 @@ export const CreateChannelModal = () => { formState: { isDirty, isValid }, } = useForm(); - const onSubmit = (data) => { + const onSubmit = (data: any) => { const event: any = { content: JSON.stringify(data), created_at: dateToUnix(), @@ -33,7 +36,9 @@ export const CreateChannelModal = () => { event.sig = signEvent(event, activeAccount.privkey); // publish channel - pool.publish(event, relays); + pool.publish(event, FULL_RELAYS); + // insert to database + createChannel(event.id, event.content, event.created_at); // close modal setOpen(false); // reset form @@ -53,43 +58,48 @@ export const CreateChannelModal = () => { - +
-
-
-
-
# Create channel
- - - +
+
+
+
+
+ Create channel +
+ + + +
+

+ Channels are freedom square, everyone can speech freely, no one can stop you or deceive what to + speech +

-
-
+
+
-
- +
{
- +