Skip to content

Commit

Permalink
Fix load more when scrolling to end of rules table (#2167)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmichalski authored Jan 5, 2024
1 parent 13bf10a commit 38a14d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
1 change: 0 additions & 1 deletion packages/desktop-client/src/components/ManageRules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ function ManageRulesContent({
<View style={{ flex: 1 }}>
<RulesHeader />
<SimpleTable
data={filteredRules}
loadMore={loadMore}
// Hide the last border of the item in the table
style={{ marginBottom: -1 }}
Expand Down
28 changes: 11 additions & 17 deletions packages/desktop-client/src/components/rules/SimpleTable.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
import React, { type ReactNode, useEffect, useRef } from 'react';
import React, { type ReactNode, type UIEvent, useRef } from 'react';

import { type CSSProperties } from '../../style';
import View from '../common/View';

type SimpleTableProps = {
data: unknown;
loadMore?: () => void;
style?: CSSProperties;
onHoverLeave?: () => void;
children: ReactNode;
};

export default function SimpleTable({
data,
loadMore,
style,
onHoverLeave,
children,
}: SimpleTableProps) {
const contentRef = useRef<HTMLDivElement>();
const contentHeight = useRef<number>();
const scrollRef = useRef<HTMLDivElement>();

function onScroll(e) {
if (contentHeight.current != null) {
if (loadMore && e.target.scrollTop > contentHeight.current - 750) {
loadMore();
}
function onScroll(e: UIEvent<HTMLElement>) {
if (
loadMore &&
Math.abs(
e.currentTarget.scrollHeight -
e.currentTarget.clientHeight -
e.currentTarget.scrollTop,
) < 1
) {
loadMore();
}
}

useEffect(() => {
if (contentRef.current) {
contentHeight.current = contentRef.current.getBoundingClientRect().height;
} else {
contentHeight.current = null;
}
}, [contentRef.current, data]);

return (
<View
style={{
Expand Down

0 comments on commit 38a14d9

Please sign in to comment.