eletrotupi / tcc/ frontend/app/notifications.tsxb3ead45a73252ca3006b75f6c77a3d72e8055586
2.0 KB | 68 lines Raw
1
import { ActivityIndicator, FlatList, StyleSheet, View } from "react-native";
2

3
import { EmptyState } from "@/components/ui/EmptyState";
4
import { SectionHeader } from "@/components/ui/Sections";
5
import { NotificationRow } from "@/components/notifications/NotificationRow";
6
import { useNotificationsInfinite } from "@/hooks";
7
import { Colors, Spacing } from "@/constants/theme";
8

9
export default function NotificationsInbox() {
10
  const {
11
    data,
12
    isLoading,
13
    fetchNextPage,
14
    hasNextPage,
15
    isFetchingNextPage,
16
  } = useNotificationsInfinite();
17

18
  const notifications = data?.pages.flatMap((page) => page.notifications) ?? [];
19

20
  return (
21
    <View style={styles.container}>
22
      <FlatList
23
        testID="notifications-list"
24
        data={notifications}
25
        keyExtractor={(notification) => String(notification.id)}
26
        renderItem={({ item }) => <NotificationRow notification={item} />}
27
        ListHeaderComponent={
28
          notifications.length > 0 ? <SectionHeader title="Recentes" /> : null
29
        }
30
        contentContainerStyle={styles.content}
31
        onEndReachedThreshold={0.5}
32
        onEndReached={() => {
33
          if (hasNextPage && !isFetchingNextPage) fetchNextPage();
34
        }}
35
        ListEmptyComponent={
36
          isLoading ? (
37
            <ActivityIndicator style={styles.footer} color={Colors.light.tint} />
38
          ) : (
39
            <EmptyState
40
              title="Nenhuma notificação"
41
              subtitle="Avisaremos você quando algo chegar."
42
              icon="notifications-off-outline"
43
            />
44
          )
45
        }
46
        ListFooterComponent={
47
          isFetchingNextPage ? (
48
            <ActivityIndicator style={styles.footer} color={Colors.light.tint} />
49
          ) : null
50
        }
51
      />
52
    </View>
53
  );
54
}
55

56
const styles = StyleSheet.create({
57
  container: {
58
    flex: 1,
59
    backgroundColor: Colors.light.background,
60
  },
61
  content: {
62
    paddingHorizontal: Spacing.containerPadding,
63
    paddingVertical: Spacing.sectionGap,
64
  },
65
  footer: {
66
    paddingVertical: Spacing.cardGap,
67
  },
68
});