Skip to content

Commit 03d533e

Browse files
authored
Merge pull request #1949 from wix/feat/AgendaList_debounce_scroll
AgendaList - debounce `scrollToSection`
2 parents a075904 + d5b2b65 commit 03d533e

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/expandableCalendar/agendaList.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import get from 'lodash/get';
22
import map from 'lodash/map';
33
import isFunction from 'lodash/isFunction';
44
import isUndefined from 'lodash/isUndefined';
5+
import debounce from 'lodash/debounce';
56

6-
import PropTypes from 'prop-types';
77
import XDate from 'xdate';
88

99
import React, {useCallback, useContext, useEffect, useRef} from 'react';
@@ -94,15 +94,15 @@ const AgendaList = (props: AgendaListProps) => {
9494
useEffect(() => {
9595
if (date !== _topSection.current) {
9696
setTimeout(() => {
97-
scrollToSection();
97+
scrollToSection(date);
9898
}, 500);
9999
}
100100
}, []);
101101

102102
useEffect(() => {
103103
// NOTE: on first init data should set first section to the current date!!!
104104
if (updateSource !== UpdateSources.LIST_DRAG && updateSource !== UpdateSources.CALENDAR_INIT) {
105-
scrollToSection();
105+
scrollToSection(date);
106106
}
107107
}, [date]);
108108

@@ -158,8 +158,8 @@ const AgendaList = (props: AgendaListProps) => {
158158
return sectionTitle;
159159
};
160160

161-
const scrollToSection = () => {
162-
const sectionIndex = scrollToNextEvent ? getNextSectionIndex(date) : getSectionIndex(date);
161+
const scrollToSection = useCallback(debounce((d) => {
162+
const sectionIndex = scrollToNextEvent ? getNextSectionIndex(d) : getSectionIndex(d);
163163
if (isUndefined(sectionIndex)) {
164164
return;
165165
}
@@ -175,7 +175,7 @@ const AgendaList = (props: AgendaListProps) => {
175175
viewOffset: (constants.isAndroid ? sectionHeight.current : 0) + viewOffset
176176
});
177177
}
178-
};
178+
}, 1000, {leading: false, trailing: true}), []);
179179

180180
const _onViewableItemsChanged = useCallback((info: {viewableItems: Array<ViewToken>; changed: Array<ViewToken>}) => {
181181
if (info?.viewableItems && !sectionScroll.current) {
@@ -265,15 +265,6 @@ const AgendaList = (props: AgendaListProps) => {
265265
export default AgendaList;
266266

267267
AgendaList.displayName = 'AgendaList';
268-
AgendaList.propTypes = {
269-
// ...SectionList.propTypes,
270-
dayFormat: PropTypes.string,
271-
dayFormatter: PropTypes.func,
272-
useMoment: PropTypes.bool,
273-
markToday: PropTypes.bool,
274-
sectionStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
275-
avoidDateUpdates: PropTypes.bool
276-
};
277268
AgendaList.defaultProps = {
278269
dayFormat: 'dddd, MMM d',
279270
stickySectionHeadersEnabled: true,

0 commit comments

Comments
 (0)