eletrotupi / tcc/ commit / bb83acf

frontend: derive the push token instead of syncing it in an effect

Pedro Lucas Porcellis porcellis@eletrotupi.com · 12 days ago bb83acf206c8fc02747310d3c1fff53cd3adff61 Browse files
Parents 2d27b55
Changed files
1
Additions
+1
Deletions
-7
frontend/app/notifications.tsx
1 1
import {
2 2
  View,
3 3
  StyleSheet,
4 4
  ScrollView,
5 5
  KeyboardAvoidingView,
32 32
};
33 33

34 34
export default function NotificationsPage() {
35 35
  const { user } = useAuth();
36 36
  const params = useLocalSearchParams<NotificationParams>();
37 -
  const [expoPushToken, setExpoPushToken] = useState(user?.pushToken);
37 +
  const expoPushToken = user?.pushToken;
38 38
  const [liveNotification, setLiveNotification] = useState<ReceivedNotification | null>(null);
39 -

40 -
  useEffect(() => {
41 -
    if (user) {
42 -
      setExpoPushToken(user.pushToken);
43 -
    }
44 -
  }, [user]);
45 39

46 40
  useEffect(() => {
47 41
    const sub = Notifications.addNotificationReceivedListener((n) => {
48 42
      setLiveNotification({
49 43
        title: n.request.content.title ?? undefined,
124 118
  header: {
125 119
    alignItems: "flex-start",
126 120
    marginBottom: 40,
127 121
  },
128 122
});