fix: Notification from unknown actor causes app crash

This commit is contained in:
Tom Moor
2023-05-22 09:31:18 -04:00
parent d587360f4b
commit 3c5dc10446
4 changed files with 43 additions and 39 deletions

View File

@@ -46,7 +46,7 @@ function NotificationListItem({ notification, onNavigate }: Props) {
<Flex column> <Flex column>
<Text as="div" size="small"> <Text as="div" size="small">
<Text as="span" weight="bold"> <Text as="span" weight="bold">
{notification.actor.name} {notification.actor?.name ?? t("Unknown")}
</Text>{" "} </Text>{" "}
{notification.eventText(t)}{" "} {notification.eventText(t)}{" "}
<Text as="span" weight="bold"> <Text as="span" weight="bold">

View File

@@ -12,6 +12,7 @@ import useStores from "~/hooks/useStores";
import { hover } from "~/styles"; import { hover } from "~/styles";
import Desktop from "~/utils/Desktop"; import Desktop from "~/utils/Desktop";
import Empty from "../Empty"; import Empty from "../Empty";
import ErrorBoundary from "../ErrorBoundary";
import Flex from "../Flex"; import Flex from "../Flex";
import NudeButton from "../NudeButton"; import NudeButton from "../NudeButton";
import PaginatedList from "../PaginatedList"; import PaginatedList from "../PaginatedList";
@@ -47,45 +48,47 @@ function Notifications(
}, [notifications.approximateUnreadCount]); }, [notifications.approximateUnreadCount]);
return ( return (
<Flex style={{ width: "100%" }} column> <ErrorBoundary>
<Header justify="space-between"> <Flex style={{ width: "100%" }} column>
<Text weight="bold" as="span"> <Header justify="space-between">
{t("Notifications")} <Text weight="bold" as="span">
</Text> {t("Notifications")}
<Text color="textSecondary" as={Flex} gap={8}> </Text>
{notifications.approximateUnreadCount > 0 && ( <Text color="textSecondary" as={Flex} gap={8}>
<Tooltip delay={500} tooltip={t("Mark all as read")}> {notifications.approximateUnreadCount > 0 && (
<Button action={markNotificationsAsRead} context={context}> <Tooltip delay={500} tooltip={t("Mark all as read")}>
<MarkAsReadIcon /> <Button action={markNotificationsAsRead} context={context}>
<MarkAsReadIcon />
</Button>
</Tooltip>
)}
<Tooltip delay={500} tooltip={t("Settings")}>
<Button action={navigateToNotificationSettings} context={context}>
<SettingsIcon />
</Button> </Button>
</Tooltip> </Tooltip>
)} </Text>
<Tooltip delay={500} tooltip={t("Settings")}> </Header>
<Button action={navigateToNotificationSettings} context={context}> <React.Suspense fallback={null}>
<SettingsIcon /> <Scrollable ref={ref} flex topShadow>
</Button> <PaginatedList
</Tooltip> fetch={notifications.fetchPage}
</Text> items={notifications.orderedData}
</Header> renderItem={(item: Notification) => (
<React.Suspense fallback={null}> <NotificationListItem
<Scrollable ref={ref} flex topShadow> key={item.id}
<PaginatedList notification={item}
fetch={notifications.fetchPage} onNavigate={onRequestClose}
items={notifications.orderedData} />
renderItem={(item: Notification) => ( )}
<NotificationListItem />
key={item.id} </Scrollable>
notification={item} </React.Suspense>
onNavigate={onRequestClose} {isEmpty && (
/> <EmptyNotifications>{t("No notifications yet")}.</EmptyNotifications>
)} )}
/> </Flex>
</Scrollable> </ErrorBoundary>
</React.Suspense>
{isEmpty && (
<EmptyNotifications>{t("No notifications yet")}.</EmptyNotifications>
)}
</Flex>
); );
} }

View File

@@ -25,7 +25,7 @@ class Notification extends BaseModel {
@observable @observable
archivedAt: Date | null; archivedAt: Date | null;
actor: User; actor?: User;
documentId?: string; documentId?: string;

View File

@@ -205,6 +205,7 @@
"Sorry, an error occurred.": "Sorry, an error occurred.", "Sorry, an error occurred.": "Sorry, an error occurred.",
"Click to retry": "Click to retry", "Click to retry": "Click to retry",
"Back": "Back", "Back": "Back",
"Unknown": "Unknown",
"Mark all as read": "Mark all as read", "Mark all as read": "Mark all as read",
"No notifications yet": "No notifications yet", "No notifications yet": "No notifications yet",
"Documents": "Documents", "Documents": "Documents",