Skip to content

Commit 8568e60

Browse files
committed
Scroll Up Button
1 parent 163f942 commit 8568e60

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

my-app/src/presenters/ListViewPresenter.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ const ListViewPresenter = observer(({ model }) => {
7070
}
7171
};
7272

73+
const setTargetScroll = (position) =>{
74+
model.setScrollPosition(position);
75+
}
76+
7377
const [isPopupOpen, setIsPopupOpen] = useState(false);
7478
const [selectedCourse, setSelectedCourse] = useState(null);
7579
const preP = <PrerequisitePresenter
@@ -109,6 +113,7 @@ const ListViewPresenter = observer(({ model }) => {
109113
popup={popup}
110114

111115
targetScroll={model.scrollPosition}
116+
setTargetScroll={setTargetScroll}
112117
scrollContainerRef={scrollContainerRef}
113118
persistantScrolling={persistantScrolling}
114119

my-app/src/views/ListView.jsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ function ListView(props) {
4949
}
5050
}, [props.targetScroll, hasMore, displayedCourses.length]);
5151

52+
useEffect(() => {
53+
if (props.targetScroll === 0 && props.scrollContainerRef?.current) {
54+
props.scrollContainerRef.current.scrollTop = 0;
55+
}
56+
}, [props.targetScroll]);
57+
5258
if (!props.courses) {
5359
return (
5460
<div className="relative bg-white text-black p-2 flex flex-col gap-5 h-screen">
@@ -170,6 +176,16 @@ function ListView(props) {
170176
</div>
171177
)}
172178
{props.popup}
179+
{!isLoading && props.targetScroll > 1000 &&(
180+
<button
181+
onClick={() => props.setTargetScroll(0)}
182+
className="fixed bottom-6 right-6 z-50 bg-[#000061] text-white p-3 rounded-full shadow-lg hover:bg-[#1a1a80] transition-all"
183+
title="Scroll to top"
184+
>
185+
186+
</button>
187+
)}
188+
173189
</div>
174190
);
175191
}

0 commit comments

Comments
 (0)