migrated channel messages to jotai state (same as chat)

This commit is contained in:
Ren Amamiya
2023-04-16 17:31:31 +07:00
parent 00e28529dd
commit a573f9e4eb
3 changed files with 33 additions and 8 deletions

View File

@@ -1,11 +1,17 @@
import ChannelMessageItem from '@components/channels/messages/item';
import { Placeholder } from '@components/note/placeholder';
import { sortedChannelMessagesAtom } from '@stores/channel';
import { useAtomValue } from 'jotai';
import { useCallback, useRef } from 'react';
import { Virtuoso } from 'react-virtuoso';
export const ChannelMessages = ({ data }: { data: any }) => {
export const ChannelMessages = () => {
const virtuosoRef = useRef(null);
const data = useAtomValue(sortedChannelMessagesAtom);
const itemContent: any = useCallback(
(index: string | number) => {
return <ChannelMessageItem data={data[index]} />;
@@ -25,6 +31,7 @@ export const ChannelMessages = ({ data }: { data: any }) => {
<Virtuoso
ref={virtuosoRef}
data={data}
components={COMPONENTS}
itemContent={itemContent}
computeItemKey={computeItemKey}
initialTopMostItemIndex={data.length - 1}
@@ -37,3 +44,8 @@ export const ChannelMessages = ({ data }: { data: any }) => {
</div>
);
};
const COMPONENTS = {
EmptyPlaceholder: () => <Placeholder />,
ScrollSeekPlaceholder: () => <Placeholder />,
};