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

fix: Adding logs #1391

Merged
merged 1 commit into from
Dec 19, 2024
Merged
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
9 changes: 6 additions & 3 deletions containers/GroupScreenMembersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import TableView, {
import { captureErrorWithFriendlyToast } from "@/utils/capture-error";
import { useInboxProfilesSocials } from "@/hooks/useInboxProfilesSocials";
import { IProfileSocials } from "@/features/profiles/profile-types";
import { useGroupMembersConversationScreenQuery } from "@/queries/useGroupMembersQuery";

type GroupScreenMembersTableProps = {
topic: ConversationTopic | undefined;
topic: ConversationTopic;
group: GroupWithCodecsType | undefined | null;
};

Expand All @@ -37,9 +38,11 @@ export const GroupScreenMembersTable: FC<GroupScreenMembersTableProps> = memo(
const colorScheme = useColorScheme();
const currentAccount = useCurrentAccount() as string;
const styles = useStyles();

const { data: members } = useGroupMembersConversationScreenQuery(
currentAccount,
topic
);
Comment on lines +41 to +44
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for query failures

The query implementation is good, but there's no handling of query errors which could affect the component's functionality.

-    const { data: members } = useGroupMembersConversationScreenQuery(
+    const { data: members, error } = useGroupMembersConversationScreenQuery(
       currentAccount,
       topic
     );
+    
+    useEffect(() => {
+      if (error) {
+        logger.error('Failed to fetch group members', { error, topic });
+        captureErrorWithFriendlyToast(error);
+      }
+    }, [error, topic]);
📝 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 { data: members } = useGroupMembersConversationScreenQuery(
currentAccount,
topic
);
const { data: members, error } = useGroupMembersConversationScreenQuery(
currentAccount,
topic
);
useEffect(() => {
if (error) {
logger.error('Failed to fetch group members', { error, topic });
captureErrorWithFriendlyToast(error);
}
}, [error, topic]);

const {
members,
promoteToSuperAdmin,
promoteToAdmin,
revokeAdmin,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import logger from "@/utils/logger";
import { useInboxProfileSocialsQueries } from "@queries/useInboxProfileSocialsQuery";
import {
getPreferredInboxAddress,
getPreferredInboxAvatar,
getPreferredInboxName,
} from "@utils/profile";
import { GroupWithCodecsType } from "@utils/xmtpRN/client";
import type { InboxId, Member } from "@xmtp/react-native-sdk";
import { Group, type InboxId, type Member } from "@xmtp/react-native-sdk";
import { useEffect, useMemo, useState } from "react";

export const useGroupConversationListAvatarInfo = (
Expand All @@ -21,6 +22,12 @@ export const useGroupConversationListAvatarInfo = (
return;
}
const fetchMembers = async () => {
if (typeof group.members !== "function") {
logger.error(
`Group members is not a function instance of group is ${group instanceof Group}`
);
return;
}
const members = await group.members();
setMembers(members || []);
};
Expand Down
Loading