From 5273c2387a21eb154f9b73ce9082ed5e6957aeed Mon Sep 17 00:00:00 2001 From: Stef Coenen Date: Tue, 17 Dec 2024 21:11:30 +0100 Subject: [PATCH] Added error boundaries to community nav; (#487) --- .../Community/CommunityChannelNav.tsx | 110 ++++++++---------- .../src/templates/Community/CommunityHome.tsx | 8 +- .../PushNotificationsService.ts | 2 +- 3 files changed, 58 insertions(+), 62 deletions(-) diff --git a/packages/apps/community-app/src/templates/Community/CommunityChannelNav.tsx b/packages/apps/community-app/src/templates/Community/CommunityChannelNav.tsx index e3c0c0a22..8365813a2 100644 --- a/packages/apps/community-app/src/templates/Community/CommunityChannelNav.tsx +++ b/packages/apps/community-app/src/templates/Community/CommunityChannelNav.tsx @@ -6,6 +6,7 @@ import { COMMUNITY_ROOT_PATH, ConnectionImage, ConnectionName, + ErrorBoundary, t, useDotYouClientContext, } from '@homebase-id/common-app'; @@ -134,55 +135,52 @@ export const CommunityChannelNav = ({ isOnline }: { isOnline: boolean }) => {

{t('Channels')}

- - {pinnedChannels?.map((channel) => ( - - ))} - - {unpinnedChannels - ?.slice(0, isExpanded ? undefined : maxChannels - (pinnedChannels?.length || 0)) - .map((channel) => ( + + {pinnedChannels?.map((channel) => ( ))} - {communityChannels?.length && communityChannels?.length > 7 ? ( - setIsExpanded((val) => !val)} - > - {isExpanded ? t('See less') : t('See more')} - - - ) : null} + {unpinnedChannels + ?.slice(0, isExpanded ? undefined : maxChannels - (pinnedChannels?.length || 0)) + .map((channel) => ( + + ))} + + {communityChannels?.length && communityChannels?.length > 7 ? ( + setIsExpanded((val) => !val)} + > + {isExpanded ? t('See less') : t('See more')} + + + ) : null} +

{t('Direct messages')}

- {members?.map((recipient) => ( - - ))} + + {members?.map((recipient) => ( + + ))} +
@@ -252,20 +250,18 @@ const LaterItem = ({ odinId, communityId }: { odinId: string; communityId: strin const VISITS_STORAGE_KEY = 'community-sidebar-visited'; const ChannelItem = ({ - odinId, - communityId, channel, setUnreadCount, }: { - odinId: string; - communityId: string; channel: ChannelWithRecentMessage; setUnreadCount: (identifier: string, count: number) => void; }) => { + const { odinKey, communityKey } = useParams(); + const loggedOnIdentity = useDotYouClientContext().getLoggedInIdentity(); const channelId = channel.fileMetadata.appData.uniqueId; - const href = `${COMMUNITY_ROOT_PATH}/${odinId}/${communityId}/${channelId}`; + const href = `${COMMUNITY_ROOT_PATH}/${odinKey}/${communityKey}/${channelId}`; const isActive = !!useMatch({ path: href, end: false }); const vists = tryJsonParse(sessionStorage.getItem(VISITS_STORAGE_KEY) || '[]') || []; @@ -285,12 +281,16 @@ const ChannelItem = ({ const { single: { data: metadata }, update: { mutate: updateMetadata }, - } = useCommunityMetadata({ odinId, communityId }); + } = useCommunityMetadata({ odinId: odinKey, communityId: communityKey }); const isPinned = channelId && metadata?.fileMetadata.appData.content?.pinnedChannels?.includes(channelId); - const { data: messages } = useCommunityMessages({ odinId, communityId, channelId }).all; + const { data: messages } = useCommunityMessages({ + odinId: odinKey, + communityId: communityKey, + channelId, + }).all; const unreadMessagesCount = useMemo( () => @@ -316,7 +316,7 @@ const ChannelItem = ({ return ( # {channel.fileMetadata.appData.content?.title?.toLowerCase()} @@ -362,29 +362,23 @@ const ChannelItem = ({ }; const DirectMessageItem = ({ - odinId, - communityId, recipient, setUnreadCount, }: { - odinId: string; - communityId: string; recipient: string; setUnreadCount: (identifier: string, count: number) => void; }) => { + const { odinKey, communityKey } = useParams(); const dotYouClient = useDotYouClientContext(); const identity = dotYouClient.getHostIdentity(); - const href = `${COMMUNITY_ROOT_PATH}/${odinId}/${communityId}/direct/${recipient}`; + const href = `${COMMUNITY_ROOT_PATH}/${odinKey}/${communityKey}/direct/${recipient}`; const isActive = !!useMatch({ path: href }); const [conversationId, setConversationId] = useState(); useEffect(() => { - if (recipient === identity) { - setConversationId(ConversationWithYourselfId); - } else { - getNewXorId(identity as string, recipient).then((xorId) => setConversationId(xorId)); - } + if (recipient === identity) setConversationId(ConversationWithYourselfId); + else getNewXorId(identity as string, recipient).then((xorId) => setConversationId(xorId)); }, [recipient]); const { data: conversationMetadata } = useConversationMetadata({ conversationId }).single; @@ -410,9 +404,7 @@ const DirectMessageItem = ({ : 0; }, [messages, conversationMetadata]); - useEffect(() => { - setUnreadCount(recipient, unreadCount || 0); - }, [unreadCount]); + useEffect(() => setUnreadCount(recipient, unreadCount || 0), [unreadCount]); return ( { />
- + + + {isCreateNew ? ( ) : ( <> - + + + {children ? <>{children} : null} )} diff --git a/packages/libs/js-lib/src/core/NotificationData/PushNotificationsService.ts b/packages/libs/js-lib/src/core/NotificationData/PushNotificationsService.ts index d99a78028..cb9d1c763 100644 --- a/packages/libs/js-lib/src/core/NotificationData/PushNotificationsService.ts +++ b/packages/libs/js-lib/src/core/NotificationData/PushNotificationsService.ts @@ -1,6 +1,6 @@ import { AxiosRequestConfig } from 'axios'; import { DotYouClient, NumberCursoredResult, PushNotificationOptions } from '../core'; -import { stringGuidsEqual, stringifyToQueryParams } from '../../helpers/helpers'; +import { stringifyToQueryParams } from '../../helpers/helpers'; export interface PushNotification { id: string;