Skip to content

Commit adec29f

Browse files
committed
fix: client side notification for offline uploads
1 parent e945a7f commit adec29f

File tree

1 file changed

+8
-2
lines changed
  • examples/SampleApp/src/components/ToastComponent

1 file changed

+8
-2
lines changed

examples/SampleApp/src/components/ToastComponent/Toast.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Dimensions, StyleSheet, Text, TouchableOpacity, View } from 'react-nati
22
import Animated, { Easing, SlideInDown, SlideOutDown } from 'react-native-reanimated';
33
import { SafeAreaView, useSafeAreaInsets } from 'react-native-safe-area-context';
44
import { useInAppNotificationsState, useTheme } from 'stream-chat-react-native';
5-
import type { Notification } from 'stream-chat';
5+
import type { Notification, NotificationState } from 'stream-chat';
66

77
const { width } = Dimensions.get('window');
88

@@ -15,16 +15,22 @@ const severityIconMap: Record<Notification['severity'], string> = {
1515

1616
export const Toast = () => {
1717
const { closeInAppNotification, notifications } = useInAppNotificationsState();
18+
1819
const { top } = useSafeAreaInsets();
1920
const {
2021
theme: {
2122
colors: { overlay, white_smoke },
2223
},
2324
} = useTheme();
2425

26+
// When offline, we upload pending attachments by cleaning up the previous upload, this results in a cancelled/aborted error from the server, so we filter out those notifications.
27+
const filteredNotifications = notifications.filter(
28+
(notification: NotificationState) => notification.metadata?.reason !== 'canceled',
29+
);
30+
2531
return (
2632
<SafeAreaView style={[styles.container, { top }]} pointerEvents='box-none'>
27-
{notifications.map((notification) => (
33+
{filteredNotifications.map((notification) => (
2834
<Animated.View
2935
key={notification.id}
3036
entering={SlideInDown.easing(Easing.bezierFn(0.25, 0.1, 0.25, 1.0))}

0 commit comments

Comments
 (0)