Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Headers and New Conversation #1237

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 0 additions & 68 deletions components/Conversation/ConversationTitleDumb.tsx

This file was deleted.

94 changes: 94 additions & 0 deletions components/Conversation/GroupConversationTitle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import React, { memo, useCallback, useMemo } from "react";
import { ConversationTitleDumb } from "../../features/conversations/components/ConversationTitleDumb";
import { useGroupNameQuery } from "@queries/useGroupNameQuery";
import { ConversationTopic } from "@xmtp/react-native-sdk";
import { useCurrentAccount } from "@data/store/accountsStore";
import { NativeStackNavigationProp } from "@react-navigation/native-stack";
import { NavigationParamList } from "@screens/Navigation/Navigation";
import { ImageStyle, Platform } from "react-native";
import { useRouter } from "@navigation/useNavigation";
import { useGroupPhotoQuery } from "@queries/useGroupPhotoQuery";
import Avatar from "@components/Avatar";
import { AvatarSizes } from "@styles/sizes";
import { ThemedStyle, useAppTheme } from "@theme/useAppTheme";
import { GroupAvatarDumb } from "@components/GroupAvatar";
import { useConversationTitleLongPress } from "../../features/conversations/hooks/useConversationTitleLongPress";
import { useGroupMembersAvatarData } from "../../features/conversations/hooks/useGroupMembersAvatarData";

type GroupConversationTitleProps = {
topic: ConversationTopic;
};

type UseUserInteractionProps = {
topic: ConversationTopic;
navigation: NativeStackNavigationProp<NavigationParamList>;
};

const useUserInteraction = ({ navigation, topic }: UseUserInteractionProps) => {
const onPress = useCallback(() => {
// textInputRef?.current?.blur();
navigation.push("Group", { topic });
}, [navigation, topic]);

const onLongPress = useConversationTitleLongPress(topic);

return { onPress, onLongPress };
};

export const GroupConversationTitle = memo(
({ topic }: GroupConversationTitleProps) => {
const currentAccount = useCurrentAccount()!;

const { data: groupName, isLoading: groupNameLoading } = useGroupNameQuery(
currentAccount,
topic!
);

const { data: groupPhoto, isLoading: groupPhotoLoading } =
useGroupPhotoQuery(currentAccount, topic!);

const { data: memberData } = useGroupMembersAvatarData({ topic });

const navigation = useRouter();

const { themed } = useAppTheme();

const { onPress, onLongPress } = useUserInteraction({
topic,
navigation,
});

const displayAvatar = !groupPhotoLoading && !groupNameLoading;

const avatarComponent = useMemo(() => {
if (displayAvatar) return null;
Comment on lines +61 to +64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix inverted displayAvatar logic

The displayAvatar condition appears to be inverted. Currently, it returns null when loading is complete, which seems incorrect.

-    const displayAvatar = !groupPhotoLoading && !groupNameLoading;
+    const displayAvatar = groupPhotoLoading || groupNameLoading;

     const avatarComponent = useMemo(() => {
-      if (displayAvatar) return null;
+      if (!displayAvatar) return null;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const displayAvatar = !groupPhotoLoading && !groupNameLoading;
const avatarComponent = useMemo(() => {
if (displayAvatar) return null;
const displayAvatar = groupPhotoLoading || groupNameLoading;
const avatarComponent = useMemo(() => {
if (!displayAvatar) return null;

return groupPhoto ? (
<Avatar
uri={groupPhoto}
size={AvatarSizes.conversationTitle}
style={themed($avatar)}
/>
) : (
<GroupAvatarDumb
members={memberData}
size={AvatarSizes.conversationTitle}
style={themed($avatar)}
/>
);
}, [displayAvatar, groupPhoto, memberData, themed]);

return (
<ConversationTitleDumb
title={groupName ?? undefined}
onLongPress={onLongPress}
onPress={onPress}
avatarComponent={avatarComponent}
/>
);
}
);

const $avatar: ThemedStyle<ImageStyle> = (theme) => ({
marginRight: Platform.OS === "android" ? theme.spacing.lg : theme.spacing.xxs,
marginLeft: Platform.OS === "ios" ? theme.spacing.zero : -theme.spacing.xxs,
});
Loading