1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

fix load older messages on DM scroll

This commit is contained in:
marcoelissa 2022-11-20 17:11:46 +07:00
parent 728f79cf69
commit 8285249822
5 changed files with 38 additions and 32 deletions

View File

@ -8,9 +8,9 @@
padding: calc(var(--spacer) / 4); padding: calc(var(--spacer) / 4);
text-align: center; text-align: center;
color: var(--color-secondary); color: var(--color-secondary);
-webkit-animation: pulse 2s ease-in-out 0s infinite forwards; -webkit-animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
-moz-animation: pulse 2s ease-in-out 0s infinite forwards; -moz-animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
animation: pulse 2s ease-in-out 0s infinite forwards; animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
} }
.connectLit { .connectLit {
@ -66,6 +66,10 @@
max-width: 80%; max-width: 80%;
} }
.pulse {
animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
.chatBubble { .chatBubble {
display: inline-block; display: inline-block;
background-color: var(--color-primary); background-color: var(--color-primary);
@ -113,13 +117,7 @@
} }
@keyframes pulse { @keyframes pulse {
0% {
opacity: 1;
}
50% { 50% {
opacity: 0; opacity: 0.5;
}
100% {
opacity: 1;
} }
} }

View File

@ -17,7 +17,7 @@ export default function DmConversation() {
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(false)
const [messages, setMessages] = useState<IOrbisMessage[]>([]) const [messages, setMessages] = useState<IOrbisMessage[]>([])
const [currentPage, setCurrentPage] = useState(0) const [currentPage, setCurrentPage] = useState(0)
const [hasMore, setHasMore] = useState(false) const [hasMore, setHasMore] = useState(true)
const [newMessages, setNewMessages] = useState(0) const [newMessages, setNewMessages] = useState(0)
const scrollToBottom = (smooth = false) => { const scrollToBottom = (smooth = false) => {
@ -42,6 +42,7 @@ export default function DmConversation() {
} }
if (data) { if (data) {
console.log(data.length)
data.reverse() data.reverse()
if (!polling) { if (!polling) {
setHasMore(data.length >= 50) setHasMore(data.length >= 50)
@ -61,9 +62,12 @@ export default function DmConversation() {
setIsLoading(false) setIsLoading(false)
} }
useInterval(async () => { useInterval(
await getMessages(true) async () => {
}, 7000) getMessages(true)
},
!isLoading ? 15000 : false
)
const showTime = (index: number): boolean => { const showTime = (index: number): boolean => {
const nextMessage = messages[index + 1] const nextMessage = messages[index + 1]
@ -82,7 +86,7 @@ export default function DmConversation() {
const onScrollMessages = throttle(() => { const onScrollMessages = throttle(() => {
const el = messagesWrapper.current const el = messagesWrapper.current
if (hasMore && el.scrollTop === 0) { if (hasMore && el.scrollTop <= 50) {
getMessages() getMessages()
} }
@ -91,6 +95,14 @@ export default function DmConversation() {
) { ) {
setNewMessages(0) setNewMessages(0)
} }
// Remove scroll listener
messagesWrapper.current.removeEventListener('scroll', onScrollMessages)
// Readd scroll listener
setTimeout(() => {
messagesWrapper.current.addEventListener('scroll', onScrollMessages)
}, 100)
}, 1000) }, 1000)
useEffect(() => { useEffect(() => {
@ -105,13 +117,12 @@ export default function DmConversation() {
useEffect(() => { useEffect(() => {
const el = messagesWrapper.current const el = messagesWrapper.current
messagesWrapper.current.addEventListener('scroll', onScrollMessages)
el.addEventListener('scroll', onScrollMessages)
return () => { return () => {
el.removeEventListener('scroll', onScrollMessages) el.removeEventListener('scroll', onScrollMessages)
} }
}, [messagesWrapper]) }, [messages])
return ( return (
<div className={styles.conversation}> <div className={styles.conversation}>
@ -139,6 +150,10 @@ export default function DmConversation() {
<div <div
key={index} key={index}
className={`${styles.message} ${ className={`${styles.message} ${
message.stream_id.startsWith('new_post--')
? styles.pulse
: ''
} ${
account?.did === message.creator_details.did account?.did === message.creator_details.did
? styles.right ? styles.right
: styles.left : styles.left

View File

@ -33,7 +33,7 @@ export default function DecryptedMessage({
}, [content, orbis]) }, [content, orbis])
return ( return (
<span className={loading && styles.decrypting}> <span className={loading ? styles.decrypting : ''}>
{!loading ? decrypted : '---'} {!loading ? decrypted : '---'}
</span> </span>
) )

View File

@ -49,6 +49,8 @@ export default function Postbox({
reply_to: replyTo ? replyTo.stream_id : undefined reply_to: replyTo ? replyTo.stream_id : undefined
} }
const timestamp = Math.floor(Date.now() / 1000)
const _callbackContent: IOrbisMessage = { const _callbackContent: IOrbisMessage = {
conversation_id: conversationId, conversation_id: conversationId,
content, content,
@ -62,12 +64,10 @@ export default function Postbox({
reply_to: replyTo ? replyTo.stream_id : null, reply_to: replyTo ? replyTo.stream_id : null,
reply_to_creator_details: replyTo ? replyTo.creator_details : null, reply_to_creator_details: replyTo ? replyTo.creator_details : null,
reply_to_details: replyTo ? replyTo.content : null, reply_to_details: replyTo ? replyTo.content : null,
stream_id: 'new_post', stream_id: 'new_post--' + timestamp,
timestamp: Math.floor(Date.now() / 1000) timestamp
} }
console.log(_callbackContent)
if (callback) callback(_callbackContent) if (callback) callback(_callbackContent)
postBoxArea.current.innerText = '' postBoxArea.current.innerText = ''

View File

@ -27,12 +27,7 @@ export default function AccountHeader({
accountId: string accountId: string
}): ReactElement { }): ReactElement {
const { profile, ownAccount } = useProfile() const { profile, ownAccount } = useProfile()
const { const { account: orbisAccount, createConversation, getDid } = useOrbis()
account: orbisAccount,
hasLit,
createConversation,
getDid
} = useOrbis()
const [isShowMore, setIsShowMore] = useState(false) const [isShowMore, setIsShowMore] = useState(false)
const [userDid, setUserDid] = useState<string | undefined>() const [userDid, setUserDid] = useState<string | undefined>()
@ -70,9 +65,7 @@ export default function AccountHeader({
> >
Send Direct Message Send Direct Message
</Button> </Button>
{userDid !== undefined && userDid === null && ( {userDid === null && <span>User has no Ceramic Network DID</span>}
<span>User has no Ceramic Network DID</span>
)}
{!orbisAccount && <span>Please connect your wallet</span>} {!orbisAccount && <span>Please connect your wallet</span>}
</div> </div>
)} )}