mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-10 23:01:10 +00:00
fix(dm): prevent repeated peek animation on re-renders
Use module-level variables to track if the peek animation has played for ConversationList and MessageThread, ensuring it only runs once per page session to avoid annoying scrolling behavior. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
d018e21ad4
commit
ffa6b7076d
2 files changed
+19
-8
No files matched your search
@@ -1,5 +1,7 @@
|
||||
import { ContactRow } from "./ContactRow.js";
|
||||
|
||||
let hasPeekAnimationPlayed = false;
|
||||
|
||||
function createElement(doc, tag, className, text) {
|
||||
const element = doc.createElement(tag);
|
||||
if (className) {
|
||||
@@ -93,12 +95,13 @@ export function ConversationList({
|
||||
});
|
||||
|
||||
// Peek animation
|
||||
if (conversations.length > 0) {
|
||||
if (conversations.length > 0 && !hasPeekAnimationPlayed) {
|
||||
if (typeof IntersectionObserver !== "undefined") {
|
||||
const observer = new IntersectionObserver((entries) => {
|
||||
const entry = entries[0];
|
||||
if (entry.isIntersecting) {
|
||||
observer.disconnect();
|
||||
hasPeekAnimationPlayed = true;
|
||||
setTimeout(() => {
|
||||
if (list.scrollHeight > list.clientHeight) {
|
||||
list.scrollTo({ top: 40, behavior: "smooth" });
|
||||
@@ -112,6 +115,7 @@ export function ConversationList({
|
||||
observer.observe(list);
|
||||
} else {
|
||||
// Fallback for no IntersectionObserver (e.g. some tests or very old browsers)
|
||||
hasPeekAnimationPlayed = true;
|
||||
setTimeout(() => {
|
||||
if (list.scrollHeight > list.clientHeight) {
|
||||
list.scrollTo({ top: 40, behavior: "smooth" });
|
||||
|
||||
Reference in new issue
Block a user