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

214 lines
7.9 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-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';
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 [ contactDrawer, setContactDrawer ] = useState(null);
2022-09-16 20:06:52 +00:00
const Tab = createBottomTabNavigator();
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) => {
setContactDrawer('profile');
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 ConversationStack = createStackNavigator();
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 (
<SafeAreaView style={styles.channels} edges={['top']}>
<Channels openConversation={(cardId, channelId) => openConversation(navigation, cardId, channelId)} />
</SafeAreaView>
)
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 ProfileStack = createStackNavigator();
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 ContactStack = createStackNavigator();
const ContactStackScreen = () => {
return (
<ContactStack.Navigator screenOptions={({ route }) => ({ headerShown: false })}>
2022-09-19 00:04:17 +00:00
<ContactStack.Screen name="cards" component={ContactsTabScreen} />
<ContactStack.Screen name="card" component={ContactTabScreen} />
2022-09-17 06:54:57 +00:00
</ContactStack.Navigator>
);
}
2022-09-19 00:04:17 +00:00
const ContactsTabScreen = ({ navigation }) => {
return <Cards openContact={(cardId) => openContact(navigation, cardId)} />
}
const ContactTabScreen = ({ navigation }) => {
return <Contact closeContact={() => closeContact(navigation)} />
}
// drawered containers
const CardDrawer = createDrawerNavigator();
2022-09-19 05:42:27 +00:00
const CardDrawerContent = ({ contactNav, navigation }) => {
2022-09-19 00:04:17 +00:00
return (
2022-09-19 05:42:27 +00:00
<SafeAreaView>
<Cards openContact={(cardId) => openContact(contactNav, cardId)} />
</SafeAreaView>
2022-09-19 00:04:17 +00:00
)
}
const ContactDrawer = createDrawerNavigator();
const ContactDrawerContent = ({ navigation }) => {
2022-09-18 06:24:37 +00:00
return (
2022-09-19 05:42:27 +00:00
<SafeAreaView>
2022-09-19 06:50:57 +00:00
{ contactDrawer === 'profile' && (
2022-09-19 05:42:27 +00:00
<Profile closeProfile={() => closeProfile(navigation)} />
)}
2022-09-19 06:50:57 +00:00
{ contactDrawer === 'contacts' && (
2022-09-19 05:42:27 +00:00
<Contact closeContact={() => closeContact(navigation)} />
)}
2022-09-19 06:50:57 +00:00
{ contactDrawer === 'details' && (
2022-09-19 05:42:27 +00:00
<Details closeDetails={() => closeDetails(navigation)} />
)}
</SafeAreaView>
2022-09-18 06:24:37 +00:00
)
}
2022-09-19 05:42:27 +00:00
const HomeScreen = ({ contactNav, navigation }) => {
2022-09-18 06:24:37 +00:00
return (
2022-09-19 05:42:27 +00:00
<View style={styles.home}>
<View style={styles.sidebar}>
2022-09-19 06:50:57 +00:00
<SafeAreaView edges={['top', 'left']} style={styles.options}>
<TouchableOpacity style={styles.option} onPress={() => openProfile(contactNav)}>
2022-09-19 05:42:27 +00:00
<Ionicons style={styles.icon} name={'user'} size={20} />
<Text>Profile</Text>
</TouchableOpacity>
2022-09-19 06:50:57 +00:00
<TouchableOpacity style={styles.option} onPress={() => openCards(navigation)}>
2022-09-19 05:42:27 +00:00
<Ionicons style={styles.icon} name={'contacts'} size={20} />
<Text>Contacts</Text>
</TouchableOpacity>
</SafeAreaView>
2022-09-19 06:50:57 +00:00
<SafeAreaView edges={['left', 'bottom']} style={styles.channels}>
2022-09-19 05:42:27 +00:00
<Channels openConversation={(cardId, channelId) => openConversation(null, cardId, channelId)} />
</SafeAreaView>
</View>
<View style={styles.conversation}>
{ state.conversationId && (
<Conversation closeConversation={() => closeConversation(null)} openDetails={() => openDetails(contactNav)} />
)}
{ !state.conversationId && (
<Welcome />
)}
</View>
</View>
2022-09-18 06:24:37 +00:00
)
}
2022-09-19 00:04:17 +00:00
const CardDrawerScreen = ({ navigation }) => {
return (
<CardDrawer.Navigator screenOptions={{
drawerPosition: 'right',
headerShown: false,
swipeEnabled: false,
drawerType: 'front',
drawerStyle: {
width: state.cardWidth,
},
}}
2022-09-19 05:42:27 +00:00
drawerContent={(props) => <CardDrawerContent contactNav={navigation} {...props} />}>
2022-09-19 00:04:17 +00:00
<CardDrawer.Screen name="Root">
2022-09-19 05:42:27 +00:00
{(props) => <HomeScreen contactNav={navigation} {...props} />}
2022-09-19 00:04:17 +00:00
</CardDrawer.Screen>
</CardDrawer.Navigator>
);
};
return (
2022-09-16 22:00:29 +00:00
<SafeAreaProvider>
<NavigationContainer>
2022-09-18 06:24:37 +00:00
{ state.tabbed === false && (
2022-09-19 00:04:17 +00:00
<ContactDrawer.Navigator
screenOptions={{
2022-09-18 06:24:37 +00:00
headerShown: false,
swipeEnabled: false,
drawerType: 'front',
drawerPosition: 'right',
2022-09-19 00:04:17 +00:00
drawerStyle: {
width: state.profileWidth,
}
}}
drawerContent={(props) => <ContactDrawerContent {...props} />}>
<ContactDrawer.Screen name="Home" component={CardDrawerScreen} />
</ContactDrawer.Navigator>
2022-09-18 06:24:37 +00:00
)}
{ state.tabbed === true && (
2022-09-17 07:22:12 +00:00
<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} />;
}
if (route.name === 'Contacts') {
return <Ionicons name={'contacts'} size={size} color={color} />;
}
},
tabBarShowLabel: false,
tabBarActiveTintColor: Colors.white,
tabBarInactiveTintColor: Colors.disabled,
2022-09-18 06:24:37 +00:00
})}>
2022-09-17 07:22:12 +00:00
<Tab.Screen name="Conversation" component={ConversationStackScreen} />
<Tab.Screen name="Profile" component={ProfileStackScreen} />
<Tab.Screen name="Contacts" component={ContactStackScreen} />
</Tab.Navigator>
)}
2022-09-16 22:00:29 +00:00
</NavigationContainer>
</SafeAreaProvider>
);
2022-09-07 07:32:06 +00:00
}
2022-09-16 20:06:52 +00:00