From 0f60c385ad8441254bd8216df08c9b9e066a9824 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Wed, 28 Sep 2022 12:41:00 -0700 Subject: [PATCH] rendering conversation header --- app/mobile/src/session/Session.jsx | 10 +- .../src/session/conversation/Conversation.jsx | 27 ++++-- .../conversation/Conversation.styled.js | 23 +++++ .../conversation/useConversation.hook.js | 94 ++++++++++++++++++- app/mobile/src/session/details/Details.jsx | 13 +++ .../src/session/details/Details.styled.js | 28 ++++++ .../src/session/profile/Profile.styled.js | 1 + 7 files changed, 182 insertions(+), 14 deletions(-) create mode 100644 app/mobile/src/session/details/Details.styled.js diff --git a/app/mobile/src/session/Session.jsx b/app/mobile/src/session/Session.jsx index d29b9118..b2386218 100644 --- a/app/mobile/src/session/Session.jsx +++ b/app/mobile/src/session/Session.jsx @@ -15,7 +15,7 @@ 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'; -import { Details } from './details/Details'; +import { Details, DetailsHeader, DetailsBody } from './details/Details'; import { Conversation, ConversationHeader, ConversationBody } from './conversation/Conversation'; import { Welcome } from './welcome/Welcome'; import { ChannelsTitle, ChannelsBody, Channels } from './channels/Channels'; @@ -94,8 +94,12 @@ export function Session() { }}> {(props) => } - - {(props) =>
clearConversation(props.navigation)} />} + + }}> + {(props) => clearConversation(props.navigation)} />} ); diff --git a/app/mobile/src/session/conversation/Conversation.jsx b/app/mobile/src/session/conversation/Conversation.jsx index 03a5debe..d01b4103 100644 --- a/app/mobile/src/session/conversation/Conversation.jsx +++ b/app/mobile/src/session/conversation/Conversation.jsx @@ -1,11 +1,14 @@ import { View, TouchableOpacity, Text } from 'react-native'; +import { useLayoutEffect } from 'react'; import { useConversation } from './useConversation.hook'; import { styles } from './Conversation.styled'; import { useNavigation } from '@react-navigation/native'; +import Ionicons from '@expo/vector-icons/AntDesign'; +import Colors from 'constants/Colors'; export function ConversationHeader({ channel, closeConversation, openDetails }) { const navigation = useNavigation(); - const { state, actions } = useConversation(); + const { state, actions } = useConversation(channel?.cardId, channel?.channelId); const setDetails = () => { openDetails(navigation); @@ -16,26 +19,26 @@ export function ConversationHeader({ channel, closeConversation, openDetails }) return ( - - CLOSE - - - DETAILS + + { state.subject } + + + ); } export function ConversationBody({ channel }) { - const { state, actions } = useConversation(); + const { state, actions } = useConversation(channel?.cardId, channel?.channelId); return ( CHANNEL { channel && ( <> - { channel.cardId } - { channel.channelId } + { channel?.cardId } + { channel?.channelId } )} @@ -44,10 +47,14 @@ export function ConversationBody({ channel }) { export function Conversation({ channel, closeConversation, openDetails }) { + const { state, actions } = useConversation(channel?.cardId, channel?.channelId); return ( - + { state.subject } + + + diff --git a/app/mobile/src/session/conversation/Conversation.styled.js b/app/mobile/src/session/conversation/Conversation.styled.js index 6d007bb9..5d399ee7 100644 --- a/app/mobile/src/session/conversation/Conversation.styled.js +++ b/app/mobile/src/session/conversation/Conversation.styled.js @@ -7,9 +7,16 @@ export const styles = StyleSheet.create({ height: '100%', display: 'flex', flexDirection: 'column', + borderLeftWidth: 1, + borderColor: Colors.divider, }, header: { width: '100%', + display: 'flex', + flexDirection: 'row', + borderBottomWidth: 1, + borderColor: Colors.divider, + padding: 8, }, body: { width: '100%', @@ -17,6 +24,22 @@ export const styles = StyleSheet.create({ title: { display: 'flex', flexDirection: 'row', + alignItems: 'center', + justifyContent: 'center', + }, + subject: { + width: '100%', + flexGrow: 1, + flexShrink: 1, + textAlign: 'center', + paddingLeft: 16, + }, + subjectText: { + fontSize: 18, + textAlign: 'center', + }, + action: { + paddingLeft: 8, }, }) diff --git a/app/mobile/src/session/conversation/useConversation.hook.js b/app/mobile/src/session/conversation/useConversation.hook.js index c6da8420..a2f337f6 100644 --- a/app/mobile/src/session/conversation/useConversation.hook.js +++ b/app/mobile/src/session/conversation/useConversation.hook.js @@ -1,14 +1,106 @@ import { useState, useEffect, useContext } from 'react'; +import { CardContext } from 'context/CardContext'; +import { ChannelContext } from 'context/ChannelContext'; +import { ProfileContext } from 'context/ProfileContext'; -export function useConversation() { +export function useConversation(cardId, channelId) { const [state, setState] = useState({ + subject: null, + logo: null, }); + const card = useContext(CardContext); + const channel = useContext(ChannelContext); + const profile = useContext(ProfileContext); + const updateState = (value) => { setState((s) => ({ ...s, ...value })); } + const getCard = (guid) => { + let contact = null + card.state.cards.forEach((card, cardId, map) => { + if (card?.profile?.guid === guid) { + contact = card; + } + }); + return contact; + } + + useEffect(() => { +console.log(cardId, channelId); + let item; + if (cardId) { + const entry = card.state.cards.get(cardId); + if (entry) { + item = entry.channels.get(channelId); + } + } + else { + item = channel.state.channels.get(channelId); + } + + let contacts = []; + if (item.cardId) { + contacts.push(card.state.cards.get(item.cardId)); + } + if (item?.detail?.members) { + const profileGuid = profile.state.profile.guid; + item.detail.members.forEach(guid => { + if (profileGuid !== guid) { + const contact = getCard(guid); + contacts.push(contact); + } + }) + } + + let logo = null; + if (contacts.length === 0) { + logo = 'solution'; + } + else if (contacts.length === 1) { + if (contacts[0]?.profile?.imageSet) { + logo = card.actions.getCardLogo(contacts[0].cardId, contacts[0].profileRevision); + } + else { + logo = 'avatar'; + } + } + else { + logo = 'appstore'; + } + + let subject = null; + if (item?.detail?.data) { + try { + subject = JSON.parse(item?.detail?.data).subject; + } + catch (err) { + console.log(err); + } + } + if (!subject) { + if (contacts.length) { + let names = []; + for (let contact of contacts) { + if (contact?.profile?.name) { + names.push(contact.profile.name); + } + else if (contact?.profile?.handle) { + names.push(contact?.profile?.handle); + } + } + subject = names.join(', '); + } + else { + subject = "Notes"; + } + } + + updateState({ subject, logo }); + }, [cardId, channelId, profile, card, channel]); + const actions = { }; diff --git a/app/mobile/src/session/details/Details.jsx b/app/mobile/src/session/details/Details.jsx index 81626161..39da2915 100644 --- a/app/mobile/src/session/details/Details.jsx +++ b/app/mobile/src/session/details/Details.jsx @@ -1,4 +1,17 @@ import { View, Text, TouchableOpacity } from 'react-native'; +import { styles } from './Details.styled'; + +export function DetailsHeader({ channel }) { + return Details +} + +export function DetailsBody({ channel, clearConversation }) { + return ( + + CLEAR + + ) +} export function Details({ channel, clearConversation }) { return ( diff --git a/app/mobile/src/session/details/Details.styled.js b/app/mobile/src/session/details/Details.styled.js new file mode 100644 index 00000000..32276520 --- /dev/null +++ b/app/mobile/src/session/details/Details.styled.js @@ -0,0 +1,28 @@ +import { StyleSheet } from 'react-native'; +import { Colors } from 'constants/Colors'; + +export const styles = StyleSheet.create({ + container: { + width: '100%', + height: '100%', + display: 'flex', + flexDirection: 'column', + borderLeftWidth: 1, + borderColor: Colors.divider, + }, + header: { + width: '100%', + display: 'flex', + flexDirection: 'row', + borderBottomWidth: 1, + borderColor: Colors.divider, + padding: 8, + }, + body: { + width: '100%', + }, + title: { + fontSize: 18, + }, +}) + diff --git a/app/mobile/src/session/profile/Profile.styled.js b/app/mobile/src/session/profile/Profile.styled.js index 0815427d..02280261 100644 --- a/app/mobile/src/session/profile/Profile.styled.js +++ b/app/mobile/src/session/profile/Profile.styled.js @@ -13,6 +13,7 @@ export const styles = StyleSheet.create({ }, drawer: { paddingTop: 16, + backgroundColor: Colors.formBackground, }, titleText: { fontSize: 18,