courrier correct panel 2 scroll up
This commit is contained in:
parent
8819cbc081
commit
6f467fa5c6
@ -361,6 +361,13 @@ export default function CourrierPage() {
|
||||
className="h-9 w-9 text-gray-400 hover:text-gray-600"
|
||||
onClick={() => {
|
||||
setLoading(true);
|
||||
// Reset to page 1 when manually refreshing
|
||||
setPage(1);
|
||||
// Trigger a scroll reset
|
||||
if (typeof window !== 'undefined') {
|
||||
window.dispatchEvent(new CustomEvent('reset-email-scroll'));
|
||||
}
|
||||
// Load emails
|
||||
loadEmails().finally(() => setLoading(false));
|
||||
}}
|
||||
>
|
||||
|
||||
@ -64,6 +64,31 @@ export default function EmailList({
|
||||
// Update the emails length tracker
|
||||
setEmailsLength(emails.length);
|
||||
}, [emails, emailsLength, isLoading, scrollPosition]);
|
||||
|
||||
// Add event listener for scroll reset from parent component
|
||||
React.useEffect(() => {
|
||||
const handleResetScroll = () => {
|
||||
console.log("Resetting scroll position to top");
|
||||
if (scrollRef.current) {
|
||||
setTimeout(() => {
|
||||
if (scrollRef.current) {
|
||||
// Force scroll to top
|
||||
scrollRef.current.scrollTop = 0;
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
};
|
||||
|
||||
// Listen for the custom event
|
||||
window.addEventListener('reset-email-scroll', handleResetScroll);
|
||||
|
||||
// Also reset scroll when folder changes
|
||||
handleResetScroll();
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('reset-email-scroll', handleResetScroll);
|
||||
};
|
||||
}, [currentFolder]); // Reset scroll when folder changes
|
||||
|
||||
// Handle scroll to detect when user reaches the bottom or scrolls up
|
||||
const handleScroll = (event: React.UIEvent<HTMLDivElement>) => {
|
||||
|
||||
@ -240,6 +240,13 @@ export const useCourrier = () => {
|
||||
// If page is greater than 1, we're loading more emails
|
||||
const isLoadingMore = page > 1;
|
||||
loadEmails(isLoadingMore);
|
||||
|
||||
// If we're loading the first page, publish an event to reset scroll position
|
||||
if (page === 1 && typeof window !== 'undefined') {
|
||||
// Use a custom event to communicate with the EmailList component
|
||||
const event = new CustomEvent('reset-email-scroll');
|
||||
window.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
}, [currentFolder, page, perPage, session?.user?.id, loadEmails]);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user