databag/app/mobile/src/session/Session.jsx

284 lines
11 KiB
React
Raw Normal View History

2022-09-16 20:06:52 +00:00
import { View, TouchableOpacity, Text } from 'react-native';
2022-09-19 06:50:57 +00:00
import { useState } from 'react';
2022-09-16 22:00:29 +00:00
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
2022-09-18 06:24:37 +00:00
import { createDrawerNavigator } from '@react-navigation/drawer';
2022-09-17 06:54:57 +00:00
import { createStackNavigator } from '@react-navigation/stack';
2022-09-16 20:06:52 +00:00
import { NavigationContainer } from '@react-navigation/native';
2022-09-16 22:00:29 +00:00
import Ionicons from '@expo/vector-icons/AntDesign';
2022-09-16 20:06:52 +00:00
import { useSession } from './useSession.hook';
2022-09-16 22:00:29 +00:00
import { styles } from './Session.styled';
import Colors from 'constants/Colors';
2022-09-17 06:54:57 +00:00
import { Profile } from './profile/Profile';
import { Channels } from './channels/Channels';
import { Cards } from './cards/Cards';
2022-09-23 22:15:04 +00:00
import { Registry } from './registry/Registry';
2022-09-19 00:04:17 +00:00
import { Contact } from './contact/Contact';
import { Details } from './details/Details';
import { Conversation } from './conversation/Conversation';
2022-09-19 05:42:27 +00:00
import { Welcome } from './welcome/Welcome';
const ConversationStack = createStackNavigator();
const ProfileStack = createStackNavigator();
const ContactStack = createStackNavigator();
const ProfileDrawer = createDrawerNavigator();
const ContactDrawer = createDrawerNavigator();
const DetailDrawer = createDrawerNavigator();
const CardDrawer = createDrawerNavigator();
2022-09-23 22:15:04 +00:00
const RegistryDrawer = createDrawerNavigator();
const Tab = createBottomTabNavigator();
2022-09-07 07:32:06 +00:00
export function Session() {
2022-09-16 20:06:52 +00:00
const { state, actions } = useSession();
2022-09-19 06:50:57 +00:00
const openCards = (nav) => {
nav.openDrawer();
}
2022-09-19 00:04:17 +00:00
const closeCards = (nav) => {}
2022-09-19 06:50:57 +00:00
const openProfile = (nav) => {
nav.openDrawer();
}
2022-09-19 00:04:17 +00:00
const closeProfile = (nav) => {}
const openContact = (nav, cardId) => {}
const closeContact = (nav) => {}
2022-09-19 05:42:27 +00:00
const openConversation = (nav, cardId, channelId) => {}
2022-09-19 00:04:17 +00:00
const closeConversation = (nav) => {}
2022-09-19 05:42:27 +00:00
const openDetails = (nav, cardId, channeId) => {}
const closeDetails = (nav) => {}
2022-09-19 00:04:17 +00:00
// tabbed containers
2022-09-17 06:54:57 +00:00
const ConversationStackScreen = () => {
return (
<ConversationStack.Navigator screenOptions={({ route }) => ({ headerShown: false })}>
2022-09-19 00:04:17 +00:00
<ConversationStack.Screen name="channels" component={ChannelsTabScreen} />
2022-09-19 05:42:27 +00:00
<ConversationStack.Screen name="conversation" component={ConversationTabScreen} />
2022-09-19 00:04:17 +00:00
<ConversationStack.Screen name="details" component={DetailsTabScreen} />
2022-09-17 06:54:57 +00:00
</ConversationStack.Navigator>
);
}
2022-09-19 00:04:17 +00:00
const ChannelsTabScreen = ({ navigation }) => {
2022-09-19 06:50:57 +00:00
return (
2022-09-21 18:12:46 +00:00
<Channels openConversation={(cardId, channelId) => openConversation(navigation, cardId, channelId)} />
2022-09-19 06:50:57 +00:00
)
2022-09-19 05:42:27 +00:00
}
const ConversationTabScreen = ({ navigation }) => {
return <Conversation closeConversation={() => closeConversation(navigation)} openDetails={() => openDetails(navigation)} />
2022-09-19 00:04:17 +00:00
}
const DetailsTabScreen = ({ navigation }) => {
return <Details closeDetails={() => closeDetails(navigation)} />
}
2022-09-17 06:54:57 +00:00
const ProfileStackScreen = () => {
return (
<ProfileStack.Navigator screenOptions={({ route }) => ({ headerShown: false })}>
2022-09-19 00:04:17 +00:00
<ProfileStack.Screen name="profile" component={Profile} />
2022-09-17 06:54:57 +00:00
</ProfileStack.Navigator>
);
}
const ContactStackScreen = () => {
2022-09-25 00:44:08 +00:00
const [selected, setSelected] = useState(null);
const setCardStack = (navigation, contact) => {
setSelected(contact);
navigation.navigate('contact')
}
const clearCardStack = (navigation) => {
navigation.goBack();
}
2022-09-24 06:31:46 +00:00
const setRegistryStack = (navigation) => {
navigation.navigate('registry');
}
const clearRegistryStack = (navigation) => {
navigation.goBack();
}
2022-09-17 06:54:57 +00:00
return (
<ContactStack.Navigator screenOptions={({ route }) => ({ headerShown: false })}>
<ContactStack.Screen name="cards">
2022-09-25 00:44:08 +00:00
{(props) => <Cards openRegistry={() => setRegistryStack(props.navigation)} openContact={(contact) => setCardStack(props.navigation, contact)} />}
</ContactStack.Screen>
2022-09-25 00:44:08 +00:00
<ContactStack.Screen name="contact">
{(props) => <Contact contact={selected} closeContact={() => clearCardStack(props.navigation)} />}
</ContactStack.Screen>
2022-09-24 06:31:46 +00:00
<ContactStack.Screen name="registry">
2022-09-25 00:44:08 +00:00
{(props) => <Registry closeRegistry={() => clearRegistryStack(props.navigation)} openContact={(contact) => setCardStack(props.navigation, contact)} />}
2022-09-24 06:31:46 +00:00
</ContactStack.Screen>
2022-09-17 06:54:57 +00:00
</ContactStack.Navigator>
);
}
2022-09-19 00:04:17 +00:00
// drawered containers
2022-09-23 22:15:04 +00:00
const CardDrawerContent = ({ navigation, setContact, openRegistry }) => {
return (
2022-09-23 22:37:22 +00:00
<SafeAreaView edges={['top']} style={styles.drawer}>
2022-09-23 22:15:04 +00:00
<Cards navigation={navigation} openContact={setContact} openRegistry={openRegistry} />
</SafeAreaView>
)
}
2022-09-23 22:15:04 +00:00
const RegistryDrawerContent = ({ navigation, setContact }) => {
return (
<SafeAreaView edges={['top', 'bottom']} style={styles.drawer}>
<Registry navigation={navigation} openContact={setContact} />
</SafeAreaView>
);
}
const ProfileDrawerContent = ({ navigation }) => {
2022-09-19 00:04:17 +00:00
return (
2022-09-23 07:56:31 +00:00
<View style={styles.drawer}>
<Profile closeProfile={() => closeProfile(navigation)} />
2022-09-23 07:56:31 +00:00
</View>
)
}
const DetailDrawerContent = ({ navigation }) => {
return (
<SafeAreaView>
<Details closeDetails={() => closeDetails(navigation)} />
2022-09-19 05:42:27 +00:00
</SafeAreaView>
2022-09-19 00:04:17 +00:00
)
}
2022-09-25 05:56:41 +00:00
const ContactDrawerContent = ({ contact, navigation }) => {
const clearContact = () => {
navigation.closeDrawer();
}
2022-09-18 06:24:37 +00:00
return (
2022-09-25 05:56:41 +00:00
<View style={styles.drawer}>
<Contact contact={contact} closeContact={clearContact} />
</View>
2022-09-18 06:24:37 +00:00
)
}
2022-09-23 22:15:04 +00:00
const HomeScreen = ({ cardNav, registryNav, detailNav, contactNav, profileNav }) => {
2022-09-18 06:24:37 +00:00
return (
2022-09-19 05:42:27 +00:00
<View style={styles.home}>
2022-09-23 07:56:31 +00:00
<SafeAreaView edges={['top', 'bottom']} style={styles.sidebar}>
<SafeAreaView edges={['left']} style={styles.options}>
<TouchableOpacity style={styles.option} onPress={() => openProfile(profileNav)}>
2022-09-19 05:42:27 +00:00
<Ionicons style={styles.icon} name={'user'} size={20} />
<Text>Profile</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.option} onPress={() => openCards(cardNav)}>
2022-09-19 05:42:27 +00:00
<Ionicons style={styles.icon} name={'contacts'} size={20} />
<Text>Contacts</Text>
</TouchableOpacity>
2022-09-23 07:56:31 +00:00
</SafeAreaView>
2022-09-21 18:12:46 +00:00
<View style={styles.channels}>
2022-09-19 05:42:27 +00:00
<Channels openConversation={(cardId, channelId) => openConversation(null, cardId, channelId)} />
2022-09-21 18:12:46 +00:00
</View>
</SafeAreaView>
2022-09-19 05:42:27 +00:00
<View style={styles.conversation}>
{ state.conversationId && (
<Conversation closeConversation={() => closeConversation(null)} openDetails={() => openDetails(detailNav)} />
2022-09-19 05:42:27 +00:00
)}
{ !state.conversationId && (
<Welcome />
)}
</View>
</View>
2022-09-18 06:24:37 +00:00
)
}
2022-09-23 22:15:04 +00:00
const CardDrawerScreen = ({ registryNav, detailNav, contactNav, profileNav, setContact }) => {
2022-09-23 22:15:04 +00:00
const openRegistry = () => {
registryNav.openDrawer();
}
2022-09-19 00:04:17 +00:00
return (
<CardDrawer.Navigator screenOptions={{ drawerPosition: 'right', headerShown: false, swipeEnabled: false, drawerType: 'front', drawerStyle: { width: state.baseWidth } }}
2022-09-25 00:44:08 +00:00
drawerContent={(props) => <CardDrawerContent setContact={setContact} openRegistry={openRegistry} {...props} />}>
<CardDrawer.Screen name="home">
2022-09-25 00:44:08 +00:00
{(props) => <HomeScreen cardNav={props.navigation} registryNav={registryNav} detailNav={detailNav} contactNav={contactNav} profileNav={profileNav} setContact={setContact} />}
2022-09-19 00:04:17 +00:00
</CardDrawer.Screen>
</CardDrawer.Navigator>
);
};
2022-09-23 22:15:04 +00:00
const RegistryDrawerScreen = ({ detailNav, contactNav, profileNav, setContact }) => {
return (
<RegistryDrawer.Navigator screenOptions={{ drawerPosition: 'right', headerShown: false, swipeEnabled: false, drawerType: 'front', drawerStyle: { width: state.baseWidth } }}
2022-09-25 00:44:08 +00:00
drawerContent={(props) => <RegistryDrawerContent setContact={setContact} {...props} />}>
2022-09-23 22:15:04 +00:00
<RegistryDrawer.Screen name="card">
2022-09-25 00:44:08 +00:00
{(props) => <CardDrawerScreen registryNav={props.navigation} detailNav={detailNav} contactNav={contactNav} profileNav={profileNav} setContact={setContact} />}
2022-09-23 22:15:04 +00:00
</RegistryDrawer.Screen>
</RegistryDrawer.Navigator>
);
};
const ContactDrawerScreen = ({ detailNav, profileNav }) => {
2022-09-25 00:44:08 +00:00
const [selected, setSelected] = useState(null);
const setContact = (navigation, contact) => {
setSelected(contact);
navigation.openDrawer();
}
return (
<ContactDrawer.Navigator screenOptions={{ drawerPosition: 'right', headerShown: false, swipeEnabled: false, drawerType: 'front', drawerStyle: { width: state.subWidth } }}
2022-09-25 00:44:08 +00:00
drawerContent={(props) => <ContactDrawerContent contact={selected} {...props} />}>
2022-09-23 22:15:04 +00:00
<ContactDrawer.Screen name="registry">
2022-09-25 00:44:08 +00:00
{(props) => <RegistryDrawerScreen detailNav={detailNav} profileNav={profileNav} contactNav={props.navigation} setContact={(contact) => setContact(props.navigation, contact)} />}
</ContactDrawer.Screen>
</ContactDrawer.Navigator>
);
}
const ProfileDrawerScreen = ({ detailNav }) => {
return (
<ProfileDrawer.Navigator screenOptions={{ drawerPosition: 'right', headerShown: false, swipeEnabled: false, drawerType: 'front', drawerStyle: { width: state.subWidth } }}
drawerContent={(props) => <ProfileDrawerContent {...props} />}>
2022-09-23 22:15:04 +00:00
<ProfileDrawer.Screen name="contact">
{(props) => <ContactDrawerScreen detailNav={detailNav} profileNav={props.navigation}/>}
</ProfileDrawer.Screen>
</ProfileDrawer.Navigator>
);
}
return (
2022-09-21 18:12:46 +00:00
<View style={styles.container}>
{ state.tabbed === false && (
<DetailDrawer.Navigator screenOptions={{ drawerPosition: 'right', headerShown: false, swipeEnabled: false, drawerType: 'front', drawerStyle: { width: state.subWidth } }}
drawerContent={(props) => <DetailDrawerContent {...props} />}>
2022-09-23 22:15:04 +00:00
<DetailDrawer.Screen name="profile">
{(props) => <ProfileDrawerScreen detailNav={props.navigation} />}
</DetailDrawer.Screen>
</DetailDrawer.Navigator>
)}
{ state.tabbed === true && (
<Tab.Navigator
screenOptions={({ route }) => ({
tabBarStyle: styles.tabBar,
headerShown: false,
tabBarIcon: ({ focused, color, size }) => {
if (route.name === 'Profile') {
return <Ionicons name={'user'} size={size} color={color} />;
}
if (route.name === 'Conversation') {
return <Ionicons name={'message1'} size={size} color={color} />;
2022-09-19 00:04:17 +00:00
}
if (route.name === 'Contacts') {
return <Ionicons name={'contacts'} size={size} color={color} />;
}
},
tabBarShowLabel: false,
tabBarActiveTintColor: Colors.white,
tabBarInactiveTintColor: Colors.disabled,
})}>
2022-09-21 18:12:46 +00:00
<Tab.Screen name="Conversation">
{(props) => (<SafeAreaView style={styles.tabframe} edges={['top']}><ConversationStackScreen /></SafeAreaView>)}
</Tab.Screen>
2022-09-21 21:06:30 +00:00
<Tab.Screen name="Profile">
{(props) => (<SafeAreaView style={styles.tabframe} edges={['top']}><ProfileStackScreen /></SafeAreaView>)}
</Tab.Screen>
<Tab.Screen name="Contacts">
2022-09-21 18:12:46 +00:00
{(props) => (<SafeAreaView style={styles.tabframe} edges={['top']}><ContactStackScreen /></SafeAreaView>)}
</Tab.Screen>
</Tab.Navigator>
)}
2022-09-21 18:12:46 +00:00
</View>
);
2022-09-07 07:32:06 +00:00
}
2022-09-16 20:06:52 +00:00