From 3d057f942b5b95b6b00bc4f58ca473a638767325 Mon Sep 17 00:00:00 2001 From: marcoelissa Date: Mon, 3 Oct 2022 21:38:41 +0700 Subject: [PATCH] load orbis conversations --- .../FloatingChat/Conversation.module.css | 26 ++- .../Orbis/FloatingChat/Conversation.tsx | 190 +++++++++--------- 2 files changed, 119 insertions(+), 97 deletions(-) diff --git a/src/components/@shared/Orbis/FloatingChat/Conversation.module.css b/src/components/@shared/Orbis/FloatingChat/Conversation.module.css index ea03f70ef..3f3e23acf 100644 --- a/src/components/@shared/Orbis/FloatingChat/Conversation.module.css +++ b/src/components/@shared/Orbis/FloatingChat/Conversation.module.css @@ -1,6 +1,8 @@ .conversationBox { padding: calc(var(--spacer) / 2); height: calc(100% - (var(--spacer) * 3.5)); + display: flex; + flex-direction: column-reverse; overflow-y: auto; } @@ -37,7 +39,7 @@ } .chatBubbleItem { - display: block; + display: flex; } .chatBubbleItem + .chatBubbleItem { @@ -50,23 +52,35 @@ padding: calc(var(--spacer) / 4) calc(var(--spacer) / 2.5); font-size: var(--font-size-base); border-radius: 1rem; + overflow: hidden; + text-overflow: ellipsis; + word-break: break-word; } .chatPrimary { + margin-left: auto; color: var(--brand-white); background-color: var(--color-primary); + border-bottom-right-radius: 0px; } .chatDefault { + border-bottom-left-radius: 0px; background-color: var(--border-color); } -.conversationRecipient .colBubble .chatBubbleItem .chatBubble { - border-top-left-radius: 0; - border-bottom-left-radius: 0px; +.conversationRecipient[data-sender='away'] + + .conversationRecipient[data-sender='away'] + .chatBubble { + border-bottom-left-radius: 0; } -.conversationRecipient .colBubble .chatBubbleItem:first-of-type .chatBubble { +/* .conversationRecipient .colBubble .chatBubbleItem .chatBubble { + border-top-left-radius: 0; + border-bottom-left-radius: 0px; +} */ + +/* .conversationRecipient .colBubble .chatBubbleItem:first-of-type .chatBubble { border-top-left-radius: 1rem; border-bottom-left-radius: 0px; } @@ -80,7 +94,7 @@ .conversationSend .colBubble .chatBubbleItem:first-of-type .chatBubble { border-top-right-radius: 1rem; border-bottom-left-radius: 0px; -} +} */ .chatStamp { font-size: var(--font-size-small); diff --git a/src/components/@shared/Orbis/FloatingChat/Conversation.tsx b/src/components/@shared/Orbis/FloatingChat/Conversation.tsx index cea99a7bb..8389be8d1 100644 --- a/src/components/@shared/Orbis/FloatingChat/Conversation.tsx +++ b/src/components/@shared/Orbis/FloatingChat/Conversation.tsx @@ -1,111 +1,119 @@ -import React, { useEffect } from 'react' +import React, { useEffect, useState } from 'react' +import { useOrbis } from '@context/Orbis' import styles from './Conversation.module.css' +function RenderDecryptedMessage({ + content +}: { + content: OrbisPostContentInterface +}) { + const { orbis } = useOrbis() + const [decrypted, setDecrypted] = useState(null) + + useEffect(() => { + const decryptMessage = async (content: OrbisPostContentInterface) => { + const res = await orbis.decryptMessage(content) + + if (res) { + console.log(res) + } + + setDecrypted(res.result) + } + if (content) { + console.log(content) + decryptMessage(content) + } + }, [content]) + + return <>{decrypted} +} + export default function DmConversation({ - messages, - orbis + messages }: { messages: OrbisPostInterface[] - orbis: OrbisInterface }) { - const dummyData = [ - { - name: 'realdatawhale.eth', - image: '/apple-touch-icon.png', - chat1: 'Hello friend whats up!', - chat2: - 'I have this exact same issue with using brave browser. It wont prompt for metamask instead asking to connect to brave wallet.', - chat3: 'Hello!', - chat4: 'Yeah thats weird!', - chat5: - 'Did you update your profile within Orbis or with an app you built?!', - timestamp: 'Jul 27, 2022, 3:39 AM' - } - ] - - const decryptMessage = async (content: OrbisPostContentInterface) => { - const res = await orbis.decryptMessage(content) - - if (res) { - console.log(res) - } - return <>{res.result} - } + const { account } = useOrbis() useEffect(() => { console.log(messages) - messages.forEach((message) => { - decryptMessage(message?.content) - }) + // messages.forEach((message) => { + // decryptMessage(message?.content) + // }) }, [messages]) return ( - <> - {messages.map((dm, index) => ( -
-
-
- {/* Avatar */} -
-
-
-
- (<>{decryptMessage(dm.content)}) -
-
-
-
- {/* {dm.chat2} */} -
-
{dm.timestamp}
-
-
+
+ {messages.map((message, index) => ( +
+
+ {/* Avatar */}
-
-
-
-
- {/* {dm.chat3} */} -
-
-
-
- {/* {dm.chat4} */} -
-
-
-
- {/* {dm.chat5} */} -
-
{dm.timestamp}
-
-
-
-
-
- {/* Avatar */} -
-
-
-
- {/* {dm.chat1} */} -
-
-
-
- {/* {dm.chat4} */} -
-
-
-
- {/* {dm.chat2} */} -
-
{dm.timestamp}
+
+
+
+
))} - + {/*
+
+
+
+ {dm.chat3} +
+
+
+
+ {dm.chat4} +
+
+
+
+ {dm.chat5} +
+
{dm.timestamp}
+
+
+
+
+
+ Avatar +
+
+
+
+ {dm.chat1} +
+
+
+
+ {dm.chat4} +
+
+
+
+ {dm.chat2} +
+
{dm.timestamp}
+
+
+
*/} +
) }