From 1f70aee0407a727dbcd64bd8faa0e3abba9eb41b Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Wed, 28 Sep 2022 10:51:01 -0700 Subject: [PATCH] cleaning up session --- app/mobile/src/session/Session.jsx | 184 ++++++++++-------- app/mobile/src/session/cards/Cards.jsx | 2 +- app/mobile/src/session/cards/Cards.styled.js | 1 + app/mobile/src/session/contact/Contact.jsx | 2 +- .../src/session/contact/Contact.styled.js | 4 + .../src/session/conversation/Conversation.jsx | 52 ++++- .../conversation/Conversation.styled.js | 22 +++ .../conversation/useConversation.hook.js | 17 ++ app/mobile/src/session/details/Details.jsx | 6 +- app/mobile/src/session/registry/Registry.jsx | 2 +- .../src/session/registry/Registry.styled.js | 1 + 11 files changed, 202 insertions(+), 91 deletions(-) create mode 100644 app/mobile/src/session/conversation/Conversation.styled.js create mode 100644 app/mobile/src/session/conversation/useConversation.hook.js diff --git a/app/mobile/src/session/Session.jsx b/app/mobile/src/session/Session.jsx index 83c3b37f..d29b9118 100644 --- a/app/mobile/src/session/Session.jsx +++ b/app/mobile/src/session/Session.jsx @@ -1,5 +1,5 @@ import { View, TouchableOpacity, Text } from 'react-native'; -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context'; import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; import { createDrawerNavigator } from '@react-navigation/drawer'; @@ -16,10 +16,11 @@ import { RegistryTitle, RegistryBody, Registry } from './registry/Registry'; import { useRegistry } from './registry/useRegistry.hook'; import { Contact, ContactTitle } from './contact/Contact'; import { Details } from './details/Details'; -import { Conversation } from './conversation/Conversation'; +import { Conversation, ConversationHeader, ConversationBody } from './conversation/Conversation'; import { Welcome } from './welcome/Welcome'; import { ChannelsTitle, ChannelsBody, Channels } from './channels/Channels'; import { useChannels } from './channels/useChannels.hook'; +import { CommonActions } from '@react-navigation/native'; const ConversationStack = createStackNavigator(); const ProfileStack = createStackNavigator(); @@ -59,7 +60,14 @@ export function Session() { navigation.navigate('conversation'); } const clearConversation = (navigation) => { - navigation.goBack(); + navigation.dispatch( + CommonActions.reset({ + index: 0, + routes: [ + { name: 'channels' }, + ], + }) + ); } const setDetail = (navigation) => { navigation.navigate('details'); @@ -79,21 +87,19 @@ export function Session() { }}> {(props) => setConversation(props.navigation, cardId, channelId)} />} - - {(props) => } + + }}> + {(props) => } - {(props) => } + {(props) =>
clearConversation(props.navigation)} />} ); } - const ConversationTabScreen = ({ navigation, channel, closeConversation, openDetails }) => { - return closeConversation(navigation)} openDetails={() => openDetails(navigation)} /> - } - const DetailsTabScreen = ({ navigation, channel, closeDetails }) => { - return
closeDetails(navigation)} /> - } const ProfileStackScreen = () => { return ( ({ headerShown: true, headerTintColor: Colors.primary })}> @@ -147,57 +153,31 @@ export function Session() { ); } - - // drawered containers - const CardDrawerContent = ({ navigation, setContact, openRegistry }) => { - return ( - - - - ) - } - const RegistryDrawerContent = ({ navigation, setContact }) => { - return ( - - - - ); - } - const ProfileDrawerContent = ({ navigation }) => { - return ( - - closeProfile(navigation)} /> - - ) - } - const DetailDrawerContent = ({ channel, navigation }) => { - return ( - -
{}} /> - - ) - } - const ContactDrawerContent = ({ contact, navigation }) => { - const clearContact = () => { - navigation.closeDrawer(); - } - - return ( - - - - ) - } - - const HomeScreen = ({ cardNav, registryNav, detailNav, contactNav, profileNav, setConversation, setDetail }) => { + const HomeScreen = ({ cardNav, registryNav, detailNav, contactNav, profileNav, setDetails, resetConversation, clearReset }) => { const [channel, setChannel] = useState(null); - const setTopic = (cardId, channelId) => { + const setConversation = (cardId, channelId) => { setChannel({ cardId, channelId }); }; - const clearTopic = () => { + const clearConversation = () => { setChannel(null); }; + const setProfile = () => { + profileNav.openDrawer(); + }; + const setChannelDetails = (channel) => { + setDetails(channel); + detailNav.openDrawer(); + }; + + useEffect(() => { + if (resetConversation) { + detailNav.closeDrawer(); + setChannel(null); + setDetails(null); + clearReset(); + } + }, [resetConversation]); return ( @@ -213,12 +193,12 @@ export function Session() { - + { channel && ( - setDetail(detailNav, channel)} /> + )} { !channel && ( @@ -228,47 +208,85 @@ export function Session() { ) } - const CardDrawerScreen = ({ registryNav, detailNav, contactNav, profileNav, setContact, setDetail }) => { + const CardDrawerScreen = ({ registryNav, detailNav, contactNav, profileNav, setContact, setDetails, clearReset, resetConversation }) => { const openRegistry = () => { registryNav.openDrawer(); - } + }; + setCardContact = (contact) => { + setContact(contact); + contactNav.openDrawer(); + }; + + const params = { + profileNav, + registryNav, + detailNav, + contactNav, + setDetails, + setContact, + clearReset, + resetConversation, + }; return ( }> + drawerContent={(props) => }> - {(props) => } + {(props) => } ); }; - const RegistryDrawerScreen = ({ detailNav, contactNav, profileNav, setContact, setDetail }) => { + const RegistryDrawerScreen = ({ detailNav, contactNav, profileNav, setContact, setDetails, clearReset, resetConversation }) => { + + const setRegistryContact = (contact) => { + setContact(contact); + contactNav.openDrawer(); + }; + + const params = { + profileNav, + detailNav, + contactNav, + setDetails, + setContact, + clearReset, + resetConversation, + }; return ( }> + drawerContent={(props) => }> - {(props) => } + {(props) => } ); }; - const ContactDrawerScreen = ({ detailNav, profileNav, setDetail }) => { + const ContactDrawerScreen = ({ detailNav, profileNav, setDetails, resetConversation, clearReset }) => { const [selected, setSelected] = useState(null); - const setContact = (navigation, contact) => { + const setContact = (contact) => { setSelected(contact); - navigation.openDrawer(); } + const params = { + profileNav, + detailNav, + setDetails, + setContact, + clearReset, + resetConversation, + }; + return ( }> + drawerContent={(props) => }> - {(props) => setContact(props.navigation, contact)} setDetail={setDetail} />} + {(props) => } ); @@ -277,16 +295,30 @@ export function Session() { const DetailDrawerScreen = ({ profileNav }) => { const [selected, setSelected] = useState(null); - const setDetail = (navigation, channel) => { + const [resetConversation, setResetConversation] = useState(false); + const setDetails = (channel) => { setSelected(channel); - navigation.openDrawer(); + }; + const clearConversation = () => { + setResetConversation(true); + } + const clearReset = () => { + setResetConversation(false); + } + + const params = { + profileNav, + setDetails, + clearReset, + resetConversation, }; return ( }> + drawerContent={(props) =>
} + > - {(props) => } + {(props) => } ); @@ -296,7 +328,7 @@ export function Session() { { state.tabbed === false && ( }> + drawerContent={(props) => }> {(props) => } diff --git a/app/mobile/src/session/cards/Cards.jsx b/app/mobile/src/session/cards/Cards.jsx index 6ec93e90..c8eee8f6 100644 --- a/app/mobile/src/session/cards/Cards.jsx +++ b/app/mobile/src/session/cards/Cards.jsx @@ -83,7 +83,7 @@ export function Cards({ openRegistry, openContact }) { )} { !state.tabbed && ( - + { state.sorting && ( diff --git a/app/mobile/src/session/cards/Cards.styled.js b/app/mobile/src/session/cards/Cards.styled.js index 09646ad3..12ea6b75 100644 --- a/app/mobile/src/session/cards/Cards.styled.js +++ b/app/mobile/src/session/cards/Cards.styled.js @@ -7,6 +7,7 @@ export const styles = StyleSheet.create({ height: '100%', display: 'flex', flexDirection: 'column', + backgroundColor: Colors.formBackground, }, title: { display: 'flex', diff --git a/app/mobile/src/session/contact/Contact.jsx b/app/mobile/src/session/contact/Contact.jsx index dcaf14fe..74704d06 100644 --- a/app/mobile/src/session/contact/Contact.jsx +++ b/app/mobile/src/session/contact/Contact.jsx @@ -235,7 +235,7 @@ export function Contact({ contact, closeContact }) { } return ( - + { state.tabbed && ( )} diff --git a/app/mobile/src/session/contact/Contact.styled.js b/app/mobile/src/session/contact/Contact.styled.js index 78125f42..13e8c006 100644 --- a/app/mobile/src/session/contact/Contact.styled.js +++ b/app/mobile/src/session/contact/Contact.styled.js @@ -10,6 +10,10 @@ export const styles = StyleSheet.create({ paddingBottom: 32, alignItems: 'center', justifyContent: 'center', + backgroundColor: Colors.formBackground, + }, + wrapper: { + backgroundColor: Colors.formBackground, }, title: { fontSize: 18, diff --git a/app/mobile/src/session/conversation/Conversation.jsx b/app/mobile/src/session/conversation/Conversation.jsx index 7ce87a63..03a5debe 100644 --- a/app/mobile/src/session/conversation/Conversation.jsx +++ b/app/mobile/src/session/conversation/Conversation.jsx @@ -1,9 +1,36 @@ import { View, TouchableOpacity, Text } from 'react-native'; +import { useConversation } from './useConversation.hook'; +import { styles } from './Conversation.styled'; +import { useNavigation } from '@react-navigation/native'; + +export function ConversationHeader({ channel, closeConversation, openDetails }) { + const navigation = useNavigation(); + const { state, actions } = useConversation(); + + const setDetails = () => { + openDetails(navigation); + }; + const clearConversation = () => { + closeConversation(navigation); + }; -export function Conversation({ channel, closeConversation, openDetails }) { - return ( - + + + CLOSE + + + DETAILS + + + ); +} + +export function ConversationBody({ channel }) { + const { state, actions } = useConversation(); + + return ( + CHANNEL { channel && ( <> @@ -11,13 +38,20 @@ export function Conversation({ channel, closeConversation, openDetails }) { { channel.channelId } )} - - DETAILS - - - CLOSE - ); } +export function Conversation({ channel, closeConversation, openDetails }) { + + return ( + + + + + + + + + ); +} diff --git a/app/mobile/src/session/conversation/Conversation.styled.js b/app/mobile/src/session/conversation/Conversation.styled.js new file mode 100644 index 00000000..6d007bb9 --- /dev/null +++ b/app/mobile/src/session/conversation/Conversation.styled.js @@ -0,0 +1,22 @@ +import { StyleSheet } from 'react-native'; +import { Colors } from 'constants/Colors'; + +export const styles = StyleSheet.create({ + container: { + width: '100%', + height: '100%', + display: 'flex', + flexDirection: 'column', + }, + header: { + width: '100%', + }, + body: { + width: '100%', + }, + title: { + display: 'flex', + flexDirection: 'row', + }, +}) + diff --git a/app/mobile/src/session/conversation/useConversation.hook.js b/app/mobile/src/session/conversation/useConversation.hook.js new file mode 100644 index 00000000..c6da8420 --- /dev/null +++ b/app/mobile/src/session/conversation/useConversation.hook.js @@ -0,0 +1,17 @@ +import { useState, useEffect, useContext } from 'react'; + +export function useConversation() { + + const [state, setState] = useState({ + }); + + const updateState = (value) => { + setState((s) => ({ ...s, ...value })); + } + + const actions = { + }; + + return { state, actions }; +} + diff --git a/app/mobile/src/session/details/Details.jsx b/app/mobile/src/session/details/Details.jsx index 8bc9c534..81626161 100644 --- a/app/mobile/src/session/details/Details.jsx +++ b/app/mobile/src/session/details/Details.jsx @@ -1,6 +1,6 @@ import { View, Text, TouchableOpacity } from 'react-native'; -export function Details({ channel, closeDetails }) { +export function Details({ channel, clearConversation }) { return ( DETAILS @@ -10,8 +10,8 @@ export function Details({ channel, closeDetails }) { { channel.channelId } )} - - CLOSE + + CLEAR ) diff --git a/app/mobile/src/session/registry/Registry.jsx b/app/mobile/src/session/registry/Registry.jsx index 0ae61445..c8dee070 100644 --- a/app/mobile/src/session/registry/Registry.jsx +++ b/app/mobile/src/session/registry/Registry.jsx @@ -26,7 +26,7 @@ export function RegistryTitle({ state, actions }) { + autoCorrect={false} autoCapitalize="none" placeholderTextColor={Colors.disabled} placeholder="Server" /> { state.busy && ( diff --git a/app/mobile/src/session/registry/Registry.styled.js b/app/mobile/src/session/registry/Registry.styled.js index 683d7908..30b424bf 100644 --- a/app/mobile/src/session/registry/Registry.styled.js +++ b/app/mobile/src/session/registry/Registry.styled.js @@ -7,6 +7,7 @@ export const styles = StyleSheet.create({ height: '100%', display: 'flex', flexDirection: 'column', + backgroundColor: Colors.formBackground, }, title: { display: 'flex',