Skip to content

Commit

Permalink
Fix ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
compulim committed Jul 31, 2020
1 parent 7bef695 commit fd16b21
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
4 changes: 2 additions & 2 deletions packages/component/src/BasicTranscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { css } from 'glamor';
import { Panel as ScrollToBottomPanel, useAnimatingToEnd, useSticky } from 'react-scroll-to-bottom';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React, { useCallback, useMemo, useRef, useEffect } from 'react';
import React, { useCallback, useMemo, useRef } from 'react';

import BasicTypingIndicator from './BasicTypingIndicator';
import Fade from './Utils/Fade';
Expand Down Expand Up @@ -206,7 +206,7 @@ const BasicTranscript = ({ className }) => {

return activityElementsWithMetadata;
}),
[activities, memoizeRenderActivityElement]
[activities, activityElementsRef, memoizeRenderActivityElement]
);

// Activity ID of the last visible activity in the list.
Expand Down
53 changes: 28 additions & 25 deletions packages/component/src/hooks/useObserveScrollPosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,34 @@ export default function useObserveScrollPosition(observer, deps) {
);
}

// This hook is very similar to useEffect, which internally use useCallback.
// The "deps" is treated as the dependencies for the useCallback.
/* eslint-disable-next-line react-hooks/exhaustive-deps */
const effectCallback = useCallback(({ scrollTop }) => {
const scrollable = getTranscriptScrollableElement();
const [{ height: offsetHeight } = {}] = scrollable.getClientRects();

// Find the activity just above scroll view bottom.
// If the scroll view is already on top, get the first activity.
const entry = scrollable.scrollTop
? [...activityElementsRef.current].reverse().find(({ element }) => {
if (!element) {
return false;
}

const [{ y } = {}] = element.getClientRects();

return y < offsetHeight;
})
: activityElementsRef.current[0];

const { activityID } = entry || {};

observer && observer({ activityID, scrollTop });
}, deps);
const effectCallback = useCallback(
({ scrollTop }) => {
const scrollable = getTranscriptScrollableElement();
const [{ height: offsetHeight } = {}] = scrollable.getClientRects();

// Find the activity just above scroll view bottom.
// If the scroll view is already on top, get the first activity.
const entry = scrollable.scrollTop
? [...activityElementsRef.current].reverse().find(({ element }) => {
if (!element) {
return false;
}

const [{ y } = {}] = element.getClientRects();

return y < offsetHeight;
})
: activityElementsRef.current[0];

const { activityID } = entry || {};

observer && observer({ activityID, scrollTop });
},
// This hook is very similar to useEffect, which internally use useCallback.
// The "deps" is treated as the dependencies for the useCallback.
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[activityElementsRef, getTranscriptScrollableElement, ...deps]
);

useScrollToBottomObserveScrollPosition(effectCallback);
}

0 comments on commit fd16b21

Please sign in to comment.