diff --git a/app/(auth)/_layout.tsx b/app/(auth)/_layout.tsx index a89c336..aa94045 100644 --- a/app/(auth)/_layout.tsx +++ b/app/(auth)/_layout.tsx @@ -1,9 +1,19 @@ import React from "react"; -import {Drawer} from "expo-router/drawer"; -import {useSignOut} from "@/hooks/firebase/useSignOut"; -import {DrawerContentScrollView, DrawerNavigationOptions, DrawerNavigationProp} from "@react-navigation/drawer"; -import {Button, ButtonSize, Text, TouchableOpacity, View,} from "react-native-ui-lib"; -import {ImageBackground, StyleSheet} from "react-native"; +import { Drawer } from "expo-router/drawer"; +import { useSignOut } from "@/hooks/firebase/useSignOut"; +import { + DrawerContentScrollView, + DrawerNavigationOptions, + DrawerNavigationProp, +} from "@react-navigation/drawer"; +import { + Button, + ButtonSize, + Text, + TouchableOpacity, + View, +} from "react-native-ui-lib"; +import { ImageBackground, StyleSheet } from "react-native"; import DrawerButton from "@/components/shared/DrawerButton"; import NavGroceryIcon from "@/assets/svgs/NavGroceryIcon"; import NavToDosIcon from "@/assets/svgs/NavToDosIcon"; @@ -11,165 +21,191 @@ import NavBrainDumpIcon from "@/assets/svgs/NavBrainDumpIcon"; import NavCalendarIcon from "@/assets/svgs/NavCalendarIcon"; import NavSettingsIcon from "@/assets/svgs/NavSettingsIcon"; import ViewSwitch from "@/components/pages/(tablet_pages)/ViewSwitch"; -import {useSetAtom} from "jotai"; +import { useSetAtom } from "jotai"; import { - isFamilyViewAtom, - settingsPageIndex, - toDosPageIndex, - userSettingsView, + isFamilyViewAtom, + settingsPageIndex, + toDosPageIndex, + userSettingsView, } from "@/components/pages/calendar/atoms"; import Ionicons from "@expo/vector-icons/Ionicons"; import * as Device from "expo-device"; -import {DeviceType} from "expo-device"; +import { DeviceType } from "expo-device"; import FeedbackNavIcon from "@/assets/svgs/FeedbackNavIcon"; import DrawerIcon from "@/assets/svgs/DrawerIcon"; -import {RouteProp} from "@react-navigation/core"; +import { RouteProp } from "@react-navigation/core"; +import RefreshButton from "@/components/shared/RefreshButton"; +import { useCalSync } from "@/hooks/useCalSync"; type DrawerParamList = { - index: undefined; - calendar: undefined; - todos: undefined; + index: undefined; + calendar: undefined; + todos: undefined; }; type NavigationProp = DrawerNavigationProp; interface ViewSwitchProps { - navigation: NavigationProp; + navigation: NavigationProp; } interface HeaderRightProps { - routeName: keyof DrawerParamList; - navigation: NavigationProp; + routeName: keyof DrawerParamList; + navigation: NavigationProp; } -const MemoizedViewSwitch = React.memo(({navigation}) => ( - - - +const MemoizedViewSwitch = React.memo(({ navigation }) => ( + )); -const HeaderRight = React.memo(({routeName, navigation}) => { +const HeaderRight = React.memo( + ({ routeName, navigation }) => { const showViewSwitch = ["calendar", "todos", "index"].includes(routeName); if (Device.deviceType !== DeviceType.TABLET || !showViewSwitch) { - return null; + return null; } - return ; -}); + return ; + } +); export default function TabLayout() { - const {mutateAsync: signOut} = useSignOut(); - const setIsFamilyView = useSetAtom(isFamilyViewAtom); - const setPageIndex = useSetAtom(settingsPageIndex); - const setUserView = useSetAtom(userSettingsView); - const setToDosIndex = useSetAtom(toDosPageIndex); + const { mutateAsync: signOut } = useSignOut(); + const setIsFamilyView = useSetAtom(isFamilyViewAtom); + const setPageIndex = useSetAtom(settingsPageIndex); + const setUserView = useSetAtom(userSettingsView); + const setToDosIndex = useSetAtom(toDosPageIndex); + const { resyncAllCalendars, isSyncing } = useCalSync(); - const screenOptions = ({ - navigation, - route, - }: { - navigation: DrawerNavigationProp; - route: RouteProp; - }): DrawerNavigationOptions => ({ - headerShown: true, - headerTitleAlign: Device.deviceType === DeviceType.TABLET ? "left" : "center", - headerTitleStyle: { - fontFamily: "Manrope_600SemiBold", - fontSize: Device.deviceType === DeviceType.TABLET ? 22 : 17, - }, - headerLeft: () => ( - { + try { + await resyncAllCalendars(); + } catch (error) { + console.error("Refresh failed:", error); + } + }, [resyncAllCalendars]); + + const screenOptions = ({ + navigation, + route, + }: { + navigation: DrawerNavigationProp; + route: RouteProp; + }): DrawerNavigationOptions => ({ + headerShown: true, + headerTitleAlign: + Device.deviceType === DeviceType.TABLET ? "left" : "center", + headerTitleStyle: { + fontFamily: "Manrope_600SemiBold", + fontSize: Device.deviceType === DeviceType.TABLET ? 22 : 17, + }, + headerLeft: () => ( + + + + ), + headerRight: () => { + const showViewSwitch = ["calendar", "todos", "index"].includes( + route.name + ); + const isCalendarPage = ["calendar", "index"].includes(route.name); + + if (Device.deviceType !== DeviceType.TABLET || !showViewSwitch) { + return isCalendarPage ? ( + + + + ) : null; + } + + return ( + + {isCalendarPage && ( + + )} + + + ); + }, + drawerStyle: { + width: Device.deviceType === DeviceType.TABLET ? "30%" : "90%", + backgroundColor: "#f9f8f7", + height: "100%", + }, + }); + + return ( + { + return ( + + + + Welcome to Cally + + - - - ), - headerRight: () => { - const showViewSwitch = ["calendar", "todos", "index"].includes(route.name); - - if (Device.deviceType !== DeviceType.TABLET || !showViewSwitch) { - return null; - } - - return ; - }, - drawerStyle: { - width: Device.deviceType === DeviceType.TABLET ? "30%" : "90%", - backgroundColor: "#f9f8f7", - height: "100%", - }, - }) - - return ( - { - return ( - - - - Welcome to Cally - - - - { - props.navigation.navigate("calendar"); - setPageIndex(0); - setToDosIndex(0); - setUserView(true); - setIsFamilyView(false); - }} - icon={} - /> - { - props.navigation.navigate("grocery"); - setPageIndex(0); - setToDosIndex(0); - setUserView(true); - setIsFamilyView(false); - }} - icon={} - /> - { - props.navigation.navigate("feedback"); - setPageIndex(0); - setToDosIndex(0); - setUserView(true); - setIsFamilyView(false); - }} - icon={} - /> - - - {/* + { + props.navigation.navigate("calendar"); + setPageIndex(0); + setToDosIndex(0); + setUserView(true); + setIsFamilyView(false); + }} + icon={} + /> + { + props.navigation.navigate("grocery"); + setPageIndex(0); + setToDosIndex(0); + setUserView(true); + setIsFamilyView(false); + }} + icon={} + /> + { + props.navigation.navigate("feedback"); + setPageIndex(0); + setToDosIndex(0); + setUserView(true); + setIsFamilyView(false); + }} + icon={} + /> + + + {/* } />*/} - { - props.navigation.navigate("todos"); - setPageIndex(0); - setToDosIndex(0); - setUserView(true); - setIsFamilyView(false); - }} - icon={} - /> - { - props.navigation.navigate("brain_dump"); - setPageIndex(0); - setToDosIndex(0); - setUserView(true); - setIsFamilyView(false); - }} - icon={} - /> - { - props.navigation.navigate("notifications"); - setPageIndex(0); - setToDosIndex(0); - setUserView(true); - setIsFamilyView(false); - }} - icon={ - - } - /> - - -