fix render blocking for chat/channel
This commit is contained in:
@@ -7,7 +7,7 @@ import { useCallback, useRef } from 'react';
|
|||||||
import Skeleton from 'react-loading-skeleton';
|
import Skeleton from 'react-loading-skeleton';
|
||||||
import { Virtuoso } from 'react-virtuoso';
|
import { Virtuoso } from 'react-virtuoso';
|
||||||
|
|
||||||
export const ChannelMessages = () => {
|
export default function ChannelMessages() {
|
||||||
const virtuosoRef = useRef(null);
|
const virtuosoRef = useRef(null);
|
||||||
const data = useAtomValue(sortedChannelMessagesAtom);
|
const data = useAtomValue(sortedChannelMessagesAtom);
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ export const ChannelMessages = () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
const COMPONENTS = {
|
const COMPONENTS = {
|
||||||
EmptyPlaceholder: () => <Skeleton />,
|
EmptyPlaceholder: () => <Skeleton />,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { useCallback, useRef } from 'react';
|
|||||||
import Skeleton from 'react-loading-skeleton';
|
import Skeleton from 'react-loading-skeleton';
|
||||||
import { Virtuoso } from 'react-virtuoso';
|
import { Virtuoso } from 'react-virtuoso';
|
||||||
|
|
||||||
export const MessageList = () => {
|
export default function MessageList() {
|
||||||
const virtuosoRef = useRef(null);
|
const virtuosoRef = useRef(null);
|
||||||
const data = useAtomValue(sortedChatMessagesAtom);
|
const data = useAtomValue(sortedChatMessagesAtom);
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ export const MessageList = () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
const COMPONENTS = {
|
const COMPONENTS = {
|
||||||
EmptyPlaceholder: () => <Skeleton />,
|
EmptyPlaceholder: () => <Skeleton />,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { ChannelMessages } from '@components/channels/messages';
|
|
||||||
import { FormChannel } from '@components/form/channel';
|
import { FormChannel } from '@components/form/channel';
|
||||||
import NewsfeedLayout from '@components/layouts/newsfeed';
|
import NewsfeedLayout from '@components/layouts/newsfeed';
|
||||||
import { RelayContext } from '@components/relaysProvider';
|
import { RelayContext } from '@components/relaysProvider';
|
||||||
@@ -12,9 +11,11 @@ import { usePageContext } from '@utils/hooks/usePageContext';
|
|||||||
import useLocalStorage from '@rehooks/local-storage';
|
import useLocalStorage from '@rehooks/local-storage';
|
||||||
import { useSetAtom } from 'jotai';
|
import { useSetAtom } from 'jotai';
|
||||||
import { useResetAtom } from 'jotai/utils';
|
import { useResetAtom } from 'jotai/utils';
|
||||||
import { useContext, useEffect, useRef } from 'react';
|
import { Suspense, lazy, useContext, useRef } from 'react';
|
||||||
import useSWRSubscription from 'swr/subscription';
|
import useSWRSubscription from 'swr/subscription';
|
||||||
|
|
||||||
|
const ChannelMessages = lazy(() => import('@components/channels/messages'));
|
||||||
|
|
||||||
export function Page() {
|
export function Page() {
|
||||||
const pageContext = usePageContext();
|
const pageContext = usePageContext();
|
||||||
const searchParams: any = pageContext.urlParsed.search;
|
const searchParams: any = pageContext.urlParsed.search;
|
||||||
@@ -33,6 +34,11 @@ export function Page() {
|
|||||||
const hided = useRef(new Set());
|
const hided = useRef(new Set());
|
||||||
|
|
||||||
useSWRSubscription(id, () => {
|
useSWRSubscription(id, () => {
|
||||||
|
// reset channel reply
|
||||||
|
resetChannelReply();
|
||||||
|
// reset channel messages
|
||||||
|
resetChannelMessages();
|
||||||
|
// subscribe for new messages
|
||||||
const unsubscribe = pool.subscribe(
|
const unsubscribe = pool.subscribe(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -69,17 +75,12 @@ export function Page() {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// reset channel reply
|
|
||||||
resetChannelReply();
|
|
||||||
// reset channel messages
|
|
||||||
resetChannelMessages();
|
|
||||||
}, [resetChannelReply, resetChannelMessages]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NewsfeedLayout>
|
<NewsfeedLayout>
|
||||||
<div className="flex h-full w-full flex-col justify-between">
|
<div className="flex h-full w-full flex-col justify-between">
|
||||||
<ChannelMessages />
|
<Suspense fallback={<p>Loading...</p>}>
|
||||||
|
<ChannelMessages />
|
||||||
|
</Suspense>
|
||||||
<div className="shrink-0 p-3">
|
<div className="shrink-0 p-3">
|
||||||
<FormChannel eventId={id} />
|
<FormChannel eventId={id} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { MessageList } from '@components/chats/messageList';
|
|
||||||
import FormChat from '@components/form/chat';
|
import FormChat from '@components/form/chat';
|
||||||
import NewsfeedLayout from '@components/layouts/newsfeed';
|
import NewsfeedLayout from '@components/layouts/newsfeed';
|
||||||
import { RelayContext } from '@components/relaysProvider';
|
import { RelayContext } from '@components/relaysProvider';
|
||||||
@@ -11,9 +10,11 @@ import { usePageContext } from '@utils/hooks/usePageContext';
|
|||||||
import useLocalStorage from '@rehooks/local-storage';
|
import useLocalStorage from '@rehooks/local-storage';
|
||||||
import { useSetAtom } from 'jotai';
|
import { useSetAtom } from 'jotai';
|
||||||
import { useResetAtom } from 'jotai/utils';
|
import { useResetAtom } from 'jotai/utils';
|
||||||
import { useContext, useEffect } from 'react';
|
import { Suspense, lazy, useContext } from 'react';
|
||||||
import useSWRSubscription from 'swr/subscription';
|
import useSWRSubscription from 'swr/subscription';
|
||||||
|
|
||||||
|
const MessageList = lazy(() => import('@components/chats/messageList'));
|
||||||
|
|
||||||
export function Page() {
|
export function Page() {
|
||||||
const pageContext = usePageContext();
|
const pageContext = usePageContext();
|
||||||
const searchParams: any = pageContext.urlParsed.search;
|
const searchParams: any = pageContext.urlParsed.search;
|
||||||
@@ -27,6 +28,9 @@ export function Page() {
|
|||||||
const resetChatMessages = useResetAtom(chatMessagesAtom);
|
const resetChatMessages = useResetAtom(chatMessagesAtom);
|
||||||
|
|
||||||
useSWRSubscription(pubkey, () => {
|
useSWRSubscription(pubkey, () => {
|
||||||
|
// clear old messages
|
||||||
|
resetChatMessages();
|
||||||
|
// subscribe for next messages
|
||||||
const unsubscribe = pool.subscribe(
|
const unsubscribe = pool.subscribe(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -51,22 +55,12 @@ export function Page() {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let ignore = false;
|
|
||||||
|
|
||||||
if (!ignore) {
|
|
||||||
resetChatMessages();
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
ignore = true;
|
|
||||||
};
|
|
||||||
}, [resetChatMessages]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NewsfeedLayout>
|
<NewsfeedLayout>
|
||||||
<div className="flex h-full w-full flex-col justify-between">
|
<div className="flex h-full w-full flex-col justify-between">
|
||||||
<MessageList />
|
<Suspense fallback={<p>Loading...</p>}>
|
||||||
|
<MessageList />
|
||||||
|
</Suspense>
|
||||||
<div className="shrink-0 p-3">
|
<div className="shrink-0 p-3">
|
||||||
<FormChat receiverPubkey={pubkey} />
|
<FormChat receiverPubkey={pubkey} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user