minor updates channel

This commit is contained in:
Ren Amamiya 2023-04-20 14:14:35 +07:00
parent 9c43f56aaa
commit ff7a75b2ce
4 changed files with 17 additions and 18 deletions

View File

@ -1,16 +1,18 @@
'use client';
import { ChannelMessages } from '@components/channels/messages/index';
import FormChannelMessage from '@components/form/channelMessage';
import { FormChannel } from '@components/form/channel';
import { RelayContext } from '@components/relaysProvider';
import { channelMessagesAtom, channelReplyAtom } from '@stores/channel';
import { FULL_RELAYS } from '@stores/constants';
import { dateToUnix, hoursAgo } from '@utils/getDate';
import useLocalStorage from '@rehooks/local-storage';
import { useSetAtom } from 'jotai';
import { useResetAtom } from 'jotai/utils';
import { Suspense, useContext, useEffect, useRef } from 'react';
import { useContext, useEffect, useRef } from 'react';
export default function Page({ params }: { params: { id: string } }) {
const [pool]: any = useContext(RelayContext);
@ -20,6 +22,7 @@ export default function Page({ params }: { params: { id: string } }) {
const resetChannelMessages = useResetAtom(channelMessagesAtom);
const resetChannelReply = useResetAtom(channelReplyAtom);
const now = useRef(new Date());
const muted = useRef(new Set());
const hided = useRef(new Set());
@ -34,12 +37,12 @@ export default function Page({ params }: { params: { id: string } }) {
{
authors: [activeAccount.pubkey],
kinds: [43, 44],
since: 0,
since: dateToUnix(hoursAgo(24, now.current)),
},
{
'#e': [params.id],
kinds: [42],
since: 0,
since: dateToUnix(hoursAgo(24, now.current)),
},
],
FULL_RELAYS,
@ -67,11 +70,9 @@ export default function Page({ params }: { params: { id: string } }) {
return (
<div className="flex h-full w-full flex-col justify-between">
<Suspense fallback={<>Loading...</>}>
<ChannelMessages />
</Suspense>
<ChannelMessages />
<div className="shrink-0 p-3">
<FormChannelMessage eventId={params.id} />
<FormChannel eventId={params.id} />
</div>
</div>
);

View File

@ -125,7 +125,7 @@ export default function Page() {
undefined,
() => {
updateLastLogin(dateToUnix(now.current));
//timeout.current = setTimeout(() => router.replace('/nostr/newsfeed/following'), 5000);
timeout.current = setTimeout(() => router.replace('/nostr/newsfeed/following'), 5000);
},
{
unsubscribeOnEose: true,

View File

@ -3,6 +3,7 @@ import { RelayContext } from '@components/relaysProvider';
import { UserMini } from '@components/user/mini';
import { channelReplyAtom } from '@stores/channel';
import { FULL_RELAYS } from '@stores/constants';
import { dateToUnix } from '@utils/getDate';
@ -13,7 +14,7 @@ import { useResetAtom } from 'jotai/utils';
import { getEventHash, signEvent } from 'nostr-tools';
import { useCallback, useContext, useState } from 'react';
export default function FormChannelMessage({ eventId }: { eventId: string | string[] }) {
export const FormChannel = ({ eventId }: { eventId: string | string[] }) => {
const [pool, relays]: any = useContext(RelayContext);
const [value, setValue] = useState('');
@ -46,7 +47,7 @@ export default function FormChannelMessage({ eventId }: { eventId: string | stri
event.sig = signEvent(event, activeAccount.privkey);
// publish note
pool.publish(event, relays);
pool.publish(event, FULL_RELAYS);
// reset state
setValue('');
// reset channel reply
@ -110,10 +111,7 @@ export default function FormChannelMessage({ eventId }: { eventId: string | stri
/>
<div className="absolute bottom-2 w-full px-2">
<div className="flex w-full items-center justify-between bg-zinc-800">
<div className="flex items-center gap-2 divide-x divide-zinc-700">
<ImagePicker />
<div className="flex items-center gap-2 pl-2"></div>
</div>
<div className="flex items-center gap-2 divide-x divide-zinc-700"></div>
<div className="flex items-center gap-2">
<button
onClick={() => submitEvent()}
@ -127,4 +125,4 @@ export default function FormChannelMessage({ eventId }: { eventId: string | stri
</div>
</div>
);
}
};

View File

@ -6,9 +6,9 @@ export const DEFAULT_CHANNELS = [
{
event_id: 'e3cadf5beca1b2af1cddaa41a633679bedf263e3de1eb229c6686c50d85df753',
metadata: {
name: 'lume-general',
name: 'Lume General',
picture: 'https://void.cat/d/UNyxBmAh1MUx5gQTX95jyf.webp',
about: 'General channel for Lume',
about: 'General discussion about the Lume client',
},
created_at: 1681898574,
},