Skip to content

Commit

Permalink
refactor: Convert useIsShowingPlaceholder and useRenderItem to ob…
Browse files Browse the repository at this point in the history
…ject params
  • Loading branch information
lourou committed Oct 4, 2024
1 parent 0744094 commit 65a046a
Showing 1 changed file with 42 additions and 26 deletions.
68 changes: 42 additions & 26 deletions components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,17 @@ const usePeerSocials = () => {
return peerSocials;
};

const useRenderItem = (
xmtpAddress: string,
conversation: any,
framesStore: any,
colorScheme: any
) =>
const useRenderItem = ({
xmtpAddress,
conversation,
framesStore,
colorScheme,
}: {
xmtpAddress: string;
conversation: any;
framesStore: any;
colorScheme: any;
}) => {
useCallback(
({ item }: { item: MessageToDisplay }) => {
return (
Expand All @@ -86,6 +91,7 @@ const useRenderItem = (
},
[colorScheme, xmtpAddress, conversation?.isGroup, framesStore]
);
};

const getItemType = (framesStore: any) => (item: MessageToDisplay) => {
const fromMeString = item.fromMe ? "fromMe" : "notFromMe";
Expand Down Expand Up @@ -255,12 +261,16 @@ const useAnimatedListView = (
}, [conversation]);
};

const useIsShowingPlaceholder = (
listArray: MessageToDisplay[],
isBlockedPeer: boolean,
conversation: XmtpConversationWithUpdate | undefined
): boolean => {
return listArray.length === 0 || isBlockedPeer || !conversation;
const useIsShowingPlaceholder = ({
messages,
isBlockedPeer,
conversation,
}: {
messages: MessageToDisplay[];
isBlockedPeer: boolean;
conversation: XmtpConversationWithUpdate | undefined;
}): boolean => {
return messages.length === 0 || isBlockedPeer || !conversation;
};

export function Chat() {
Expand Down Expand Up @@ -365,17 +375,20 @@ export function Chat() {
]);

const framesStore = useFramesStore().frames;
const showPlaceholder = useIsShowingPlaceholder(
listArray,

const showPlaceholder = useIsShowingPlaceholder({
messages: listArray,
isBlockedPeer,
conversation
);
const renderItem = useRenderItem(
conversation,
});

const renderItem = useRenderItem({
xmtpAddress,
conversation,
framesStore,
colorScheme
);
colorScheme,
});

const keyExtractor = useCallback((item: MessageToDisplay) => item.id, []);

const messageListRef = useRef<
Expand Down Expand Up @@ -520,17 +533,20 @@ export function ChatPreview() {
);

const framesStore = useFramesStore().frames;
const showPlaceholder = useIsShowingPlaceholder(
listArray,

const showPlaceholder = useIsShowingPlaceholder({
messages: listArray,
isBlockedPeer,
conversation
);
const renderItem = useRenderItem(
conversation,
});

const renderItem = useRenderItem({
xmtpAddress,
conversation,
framesStore,
colorScheme
);
colorScheme,
});

const keyExtractor = useCallback((item: MessageToDisplay) => item.id, []);

const messageListRef = useRef<
Expand Down

0 comments on commit 65a046a

Please sign in to comment.