import React, { useState, useEffect, useCallback } from "react"; import { View, StyleSheet } from "react-native"; import { IconButton, Menu, Divider } from "react-native-paper"; import { MaterialCommunityIcons, Entypo } from "@expo/vector-icons"; import { useNavigation, DrawerActions, CommonActions, } from "@react-navigation/native"; import { useAlertState, useNavState, navActions, useNotificationsState, useAggregatedMessagesState, } from "~/stores"; import ColoredDotLevel from "~/components/ColoredDotLevel"; import ColoredDot from "~/components/ColoredDot"; import { createStyles } from "~/theme"; const quickNavIconSize = 18; export default function HeaderRight(props) { const navigation = useNavigation(); const { routeName } = useNavState(["routeName"]); const { maxAlertingLevel, navAlertCur } = useAlertState([ "maxAlertingLevel", "navAlertCur", ]); const { newCount } = useNotificationsState(["newCount"]); const { messagesList } = useAggregatedMessagesState(["messagesList"]); const hasUnreadMessagesForCurrentAlert = navAlertCur && navAlertCur.alert && messagesList.some( (msg) => !msg.isRead && msg.alertId === navAlertCur.alert.id, ); const { iconStyle } = props; const drawerExists = !navigation.canGoBack(); const [dotMenuVisible, setDotMenuVisible] = useState(false); const openDotMenu = () => setDotMenuVisible(true); const closeDotMenu = () => setDotMenuVisible(false); const styles = useStyles(); const navigateTo = useCallback( (navOpts) => navigation.dispatch({ ...CommonActions.navigate(navOpts), }), [navigation], ); const { nextNavigation } = useNavState(["nextNavigation"]); useEffect(() => { if (nextNavigation === null) { return; } navActions.setNextNavigation(null); // console.log({ nextNavigation }); navigateTo(...nextNavigation); }, [navigateTo, navigation, nextNavigation]); return ( { navigateTo({ name: "SendAlert", params: { screen: "SendAlertTab", }, }); }} icon={() => ( )} /> { navigateTo({ name: "AlertAgg", params: { screen: "AlertAggTab", params: { screen: "AlertAggList", }, }, }); }} icon={() => ( <> )} /> { navigateTo({ name: "AlertCur", params: { screen: "AlertCurTab", }, }); }} icon={() => ( <> {hasUnreadMessagesForCurrentAlert && } )} /> {drawerExists && ( ( <> {newCount > 0 && } )} onPress={() => { navigation.dispatch(DrawerActions.toggleDrawer()); }} /> )} {!drawerExists && ( { return ( ( )} onPress={() => { openDotMenu(); }} /> ); })()} > { navigateTo({ name: "Profile" }); }} /> { navigateTo({ name: "Relatives" }); }} /> { navigateTo({ name: "Params" }); }} /> { navigateTo({ name: "Links" }); }} /> { navigateTo({ name: "NumberLinks" }); }} /> { navigateTo({ name: "HelpSignal" }); }} /> { navigateTo({ name: "Sheets" }); }} /> { navigateTo({ name: "About" }); }} /> )} ); } const useStyles = createStyles(({ wp, hp, scaleText, theme: { colors } }) => ({ container: { flexDirection: "row", alignItems: "center", flex: 1, backgroundColor: "transparent", elevation: 0, }, buttonSelected: { backgroundColor: "rgba(30,30,30,0.2)", }, buttonIcon: {}, buttonIconSelected: {}, button: { marginHorizontal: 0, // borderRadius: 0, }, quickNavButton: { // backgroundColor: 'red', padding: 0, }, quickNavIcon: {}, menuButton: { // marginLeft: 2, }, menuIcon: {}, }));