Skip to content

Commit

Permalink
Check undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-jeremy committed Nov 1, 2024
1 parent 57510d3 commit 8426eb0
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions packages/desktop-client/src/components/ScrollProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function ScrollProvider<T extends Element>({
switch (direction) {
case 'up':
const hasScrolledToTop = () => {
if (scrollY.current) {
if (scrollY.current !== undefined) {
return scrollY.current <= tolerance;
}
return false;
Expand All @@ -63,9 +63,9 @@ export function ScrollProvider<T extends Element>({
case 'down':
const hasScrolledToBottom = () => {
if (
scrollHeight.current &&
scrollY.current &&
clientHeight.current
scrollHeight.current !== undefined &&
scrollY.current !== undefined &&
clientHeight.current !== undefined
) {
return (
scrollHeight.current - scrollY.current <=
Expand All @@ -77,15 +77,19 @@ export function ScrollProvider<T extends Element>({
return hasScrolledToBottom();
case 'left':
const hasScrollToLeft = () => {
if (scrollX.current) {
if (scrollX.current !== undefined) {
return scrollX.current <= tolerance;
}
return false;
};
return hasScrollToLeft();
case 'right':
const hasScrolledToRight = () => {
if (scrollWidth.current && scrollX.current && clientWidth.current) {
if (
scrollWidth.current !== undefined &&
scrollX.current !== undefined &&
clientWidth.current !== undefined
) {
return (
scrollWidth.current - scrollX.current <=
clientWidth.current + tolerance
Expand Down Expand Up @@ -142,11 +146,11 @@ export function ScrollProvider<T extends Element>({
const target = e.target;
if (target instanceof Element) {
previousScrollX.current = scrollX.current;
scrollX.current = target.scrollLeft || 0;
scrollX.current = target.scrollLeft;
previousScrollY.current = scrollY.current;
scrollY.current = target.scrollTop || 0;
scrollHeight.current = target.scrollHeight || 0;
clientHeight.current = target.clientHeight || 0;
scrollY.current = target.scrollTop;
scrollHeight.current = target.scrollHeight;
clientHeight.current = target.clientHeight;

listeners.current.forEach(listener =>
listener({
Expand Down

0 comments on commit 8426eb0

Please sign in to comment.