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

335 lines
14 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-27 19:21:40 +00:00
import { ProfileTitle, Profile } from './profile/Profile';
2022-09-17 06:54:57 +00:00
import { Channels } from './channels/Channels';
2022-09-27 19:21:40 +00:00
import { CardsTitle, CardsBody, Cards } from './cards/Cards';
import { useCards } from './cards/useCards.hook';
import { RegistryTitle, RegistryBody, Registry } from './registry/Registry';
import { useRegistry } from './registry/useRegistry.hook';
import { Contact, ContactTitle } from './contact/Contact';
2022-09-19 00:04:17 +00:00
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 = () => {
2022-09-27 06:12:42 +00:00
const [selected, setSelected] = useState(null);
const setConversation = (navigation, cardId, channelId) => {
setSelected({ cardId, channelId });
navigation.navigate('conversation');
}
const clearConversation = (navigation) => {
navigation.goBack();
}
const setDetail = (navigation) => {
navigation.navigate('details');
}
const clearDetail = (navigation) => {
navigation.goBack();
}
2022-09-17 06:54:57 +00:00
return (
<ConversationStack.Navigator screenOptions={({ route }) => ({ headerShown: false })}>
2022-09-27 06:12:42 +00:00
<ConversationStack.Screen name="channels">
{(props) => <ChannelsTabScreen openConversation={setConversation} navigation={props.navigation} />}
</ConversationStack.Screen>
<ConversationStack.Screen name="conversation">
{(props) => <ConversationTabScreen channel={selected} closeConversation={clearConversation} openDetails={setDetail} navigation={props.navigation} />}
</ConversationStack.Screen>
<ConversationStack.Screen name="details">
{(props) => <DetailsTabScreen channel={selected} closeDetails={clearDetail} navigation={props.navigation} />}
</ConversationStack.Screen>
2022-09-17 06:54:57 +00:00
</ConversationStack.Navigator>
);
}
2022-09-27 06:12:42 +00:00
const ChannelsTabScreen = ({ navigation, openConversation }) => {
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
}
2022-09-27 06:12:42 +00:00
const ConversationTabScreen = ({ navigation, channel, closeConversation, openDetails }) => {
return <Conversation channel={channel} closeConversation={() => closeConversation(navigation)} openDetails={() => openDetails(navigation)} />
2022-09-19 00:04:17 +00:00
}
2022-09-27 06:12:42 +00:00
const DetailsTabScreen = ({ navigation, channel, closeDetails }) => {
return <Details channel={channel} closeDetails={() => closeDetails(navigation)} />
2022-09-19 00:04:17 +00:00
}
2022-09-17 06:54:57 +00:00
const ProfileStackScreen = () => {
return (
2022-09-27 19:21:40 +00:00
<ProfileStack.Navigator screenOptions={({ route }) => ({ headerShown: true })}>
<ProfileStack.Screen name="profile" component={Profile} options={{ headerStyle: { backgroundColor: Colors.titleBackground }, headerTitle: (props) => <ProfileTitle {...props} /> }} />
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-27 19:21:40 +00:00
const registry = useRegistry();
const cards = useCards();
2022-09-17 06:54:57 +00:00
return (
2022-09-27 19:21:40 +00:00
<ContactStack.Navigator screenOptions={({ route }) => ({ headerShow: true })}>
<ContactStack.Screen name="cards" options={{
headerStyle: { backgroundColor: Colors.titleBackground },
headerBackTitleVisible: false,
headerTitle: (props) => { console.log(props); return <CardsTitle state={cards.state} actions={cards.actions} openRegistry={setRegistryStack} /> }
}}>
{(props) => <CardsBody state={cards.state} actions={cards.actions} openContact={(contact) => setCardStack(props.navigation, contact)} />}
</ContactStack.Screen>
2022-09-27 19:21:40 +00:00
<ContactStack.Screen name="contact" options={{
headerStyle: { backgroundColor: Colors.titleBackground },
headerBackTitleVisible: false,
headerTitle: (props) => <ContactTitle contact={selected} {...props} />
}}>
2022-09-25 00:44:08 +00:00
{(props) => <Contact contact={selected} closeContact={() => clearCardStack(props.navigation)} />}
</ContactStack.Screen>
2022-09-27 19:21:40 +00:00
<ContactStack.Screen name="registry" options={{
headerStyle: { backgroundColor: Colors.titleBackground },
headerBackTitleVisible: false,
headerTitle: (props) => <RegistryTitle state={registry.state} actions={registry.actions} contact={selected} {...props} />
}}>
{(props) => <RegistryBody state={registry.state} actions={registry.actions} 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>
)
}
2022-09-27 06:12:42 +00:00
const DetailDrawerContent = ({ channel, navigation }) => {
return (
<SafeAreaView>
2022-09-27 06:12:42 +00:00
<Details channel={channel} closeDetails={() => {}} />
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-27 06:12:42 +00:00
const HomeScreen = ({ cardNav, registryNav, detailNav, contactNav, profileNav, setConversation, setDetail }) => {
const [channel, setChannel] = useState(null);
const setTopic = (cardId, channelId) => {
setChannel({ cardId, channelId });
};
const clearTopic = () => {
setChannel(null);
};
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-27 06:12:42 +00:00
<Channels openConversation={setTopic} />
2022-09-21 18:12:46 +00:00
</View>
</SafeAreaView>
2022-09-19 05:42:27 +00:00
<View style={styles.conversation}>
2022-09-27 06:12:42 +00:00
{ channel && (
<Conversation channel={channel} closeConversation={clearTopic} openDetails={() => setDetail(detailNav, channel)} />
2022-09-19 05:42:27 +00:00
)}
2022-09-27 06:12:42 +00:00
{ !channel && (
2022-09-19 05:42:27 +00:00
<Welcome />
)}
</View>
</View>
2022-09-18 06:24:37 +00:00
)
}
2022-09-27 06:12:42 +00:00
const CardDrawerScreen = ({ registryNav, detailNav, contactNav, profileNav, setContact, setDetail }) => {
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-27 06:12:42 +00:00
{(props) => <HomeScreen cardNav={props.navigation} registryNav={registryNav} detailNav={detailNav} contactNav={contactNav} profileNav={profileNav} setContact={setContact} setDetail={setDetail} />}
2022-09-19 00:04:17 +00:00
</CardDrawer.Screen>
</CardDrawer.Navigator>
);
};
2022-09-27 06:12:42 +00:00
const RegistryDrawerScreen = ({ detailNav, contactNav, profileNav, setContact, setDetail }) => {
2022-09-23 22:15:04 +00:00
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-27 06:12:42 +00:00
{(props) => <CardDrawerScreen registryNav={props.navigation} detailNav={detailNav} contactNav={contactNav} profileNav={profileNav} setContact={setContact} setDetail={setDetail} />}
2022-09-23 22:15:04 +00:00
</RegistryDrawer.Screen>
</RegistryDrawer.Navigator>
);
};
2022-09-27 06:12:42 +00:00
const ContactDrawerScreen = ({ detailNav, profileNav, setDetail }) => {
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-27 06:12:42 +00:00
{(props) => <RegistryDrawerScreen detailNav={detailNav} profileNav={profileNav} contactNav={props.navigation} setContact={(contact) => setContact(props.navigation, contact)} setDetail={setDetail} />}
</ContactDrawer.Screen>
</ContactDrawer.Navigator>
);
}
2022-09-27 06:12:42 +00:00
const DetailDrawerScreen = ({ profileNav }) => {
const [selected, setSelected] = useState(null);
const setDetail = (navigation, channel) => {
setSelected(channel);
navigation.openDrawer();
};
return (
2022-09-27 06:12:42 +00:00
<DetailDrawer.Navigator screenOptions={{ drawerPosition: 'right', headerShown: false, swipeEnabled: false, drawerType: 'front', drawerStyle: { width: state.subWidth } }}
drawerContent={(props) => <DetailDrawerContent channel={selected} {...props} />}>
<DetailDrawer.Screen name="contact">
{(props) => <ContactDrawerScreen profileNav={profileNav} detailNav={props.navigation} setDetail={setDetail} />}
</DetailDrawer.Screen>
</DetailDrawer.Navigator>
);
}
return (
2022-09-21 18:12:46 +00:00
<View style={styles.container}>
{ state.tabbed === false && (
2022-09-27 06:12:42 +00:00
<ProfileDrawer.Navigator screenOptions={{ drawerPosition: 'right', headerShown: false, swipeEnabled: false, drawerType: 'front', drawerStyle: { width: state.subWidth } }}
drawerContent={(props) => <ProfileDrawerContent {...props} />}>
<ProfileDrawer.Screen name="detail">
{(props) => <DetailDrawerScreen profileNav={props.navigation}/>}
</ProfileDrawer.Screen>
</ProfileDrawer.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-27 19:21:40 +00:00
<Tab.Screen name="Profile" component={ProfileStackScreen} />
<Tab.Screen name="Contacts" component={ContactStackScreen} />
</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