mirror of
https://github.com/Qortal/qortal-mobile.git
synced 2025-06-15 12:31:21 +00:00
fix scrolldown when new msg
This commit is contained in:
parent
451b16ebf2
commit
4972496998
@ -75,7 +75,9 @@ export const ChatGroup = ({selectedGroup, secretKey, setSecretKey, getSecretKey,
|
|||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
groupId: selectedGroup
|
groupId: selectedGroup
|
||||||
}).then((res)=> {
|
}).then((res)=> {
|
||||||
getTimestampEnterChatParent();
|
setTimeout(() => {
|
||||||
|
getTimestampEnterChatParent();
|
||||||
|
}, 200);
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.error("Failed to add timestamp:", error.message || "An error occurred");
|
console.error("Failed to add timestamp:", error.message || "An error occurred");
|
||||||
});
|
});
|
||||||
|
@ -13,6 +13,7 @@ export const ChatList = ({ initialMessages, myAddress, tempMessages, chatId, onR
|
|||||||
const [showScrollButton, setShowScrollButton] = useState(false);
|
const [showScrollButton, setShowScrollButton] = useState(false);
|
||||||
const hasLoadedInitialRef = useRef(false);
|
const hasLoadedInitialRef = useRef(false);
|
||||||
const [showScrollDownButton, setShowScrollDownButton] = useState(false);
|
const [showScrollDownButton, setShowScrollDownButton] = useState(false);
|
||||||
|
const lastSeenUnreadMessageTimestamp = useRef(null);
|
||||||
|
|
||||||
const scrollingIntervalRef = useRef(null);
|
const scrollingIntervalRef = useRef(null);
|
||||||
|
|
||||||
@ -84,7 +85,9 @@ export const ChatList = ({ initialMessages, myAddress, tempMessages, chatId, onR
|
|||||||
setMessages(totalMessages);
|
setMessages(totalMessages);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const hasUnreadMessages = totalMessages.some((msg) => msg.unread && !msg?.chatReference && !msg?.isTemp);
|
const hasUnreadMessages = totalMessages.some(
|
||||||
|
(msg) => msg.unread && !msg?.chatReference && !msg?.isTemp && (!msg?.chatReference && msg?.timestamp > lastSeenUnreadMessageTimestamp.current || 0)
|
||||||
|
);
|
||||||
if (parentRef.current) {
|
if (parentRef.current) {
|
||||||
const { scrollTop, scrollHeight, clientHeight } = parentRef.current;
|
const { scrollTop, scrollHeight, clientHeight } = parentRef.current;
|
||||||
const atBottom = scrollTop + clientHeight >= scrollHeight - 10; // Adjust threshold as needed
|
const atBottom = scrollTop + clientHeight >= scrollHeight - 10; // Adjust threshold as needed
|
||||||
@ -127,6 +130,7 @@ export const ChatList = ({ initialMessages, myAddress, tempMessages, chatId, onR
|
|||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
setShowScrollButton(false)
|
setShowScrollButton(false)
|
||||||
|
lastSeenUnreadMessageTimestamp.current = Date.now()
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// const scrollToBottom = (initialMsgs) => {
|
// const scrollToBottom = (initialMsgs) => {
|
||||||
@ -353,7 +357,7 @@ export const ChatList = ({ initialMessages, myAddress, tempMessages, chatId, onR
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{showScrollButton && (
|
{showScrollButton && (
|
||||||
<button
|
<button
|
||||||
onClick={() => scrollToBottom()}
|
onClick={() => scrollToBottom()}
|
||||||
style={{
|
style={{
|
||||||
@ -373,7 +377,7 @@ export const ChatList = ({ initialMessages, myAddress, tempMessages, chatId, onR
|
|||||||
Scroll to Unread Messages
|
Scroll to Unread Messages
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
{showScrollDownButton && (
|
{showScrollDownButton && !showScrollButton && (
|
||||||
<button
|
<button
|
||||||
onClick={() => scrollToBottom()}
|
onClick={() => scrollToBottom()}
|
||||||
style={{
|
style={{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user