web: Components: Fixed reset of InfiniteLoader cache

This commit is contained in:
Alexey Safronov 2019-11-28 11:49:00 +03:00
parent f46c12cc32
commit fef1d5cea4
2 changed files with 21 additions and 12 deletions

View File

@ -106,8 +106,7 @@ class ADSelectorExample extends React.Component {
loadNextPage = ({ startIndex, searchValue, currentGroup }) => {
console.log(
`loadNextPage(startIndex=${startIndex}, searchValue=${searchValue}, currentGroup=${currentGroup &&
currentGroup.label})`
`loadNextPage(startIndex=${startIndex}, searchValue="${searchValue}", currentGroup="${currentGroup}")`
);
this.setState({ isNextPageLoading: true }, () => {
setTimeout(() => {
@ -220,7 +219,7 @@ class ADSelectorExample extends React.Component {
if (!user) return null;
console.log("onOptionTooltipShow", index, user);
// console.log("onOptionTooltipShow", index, user);
return (
<div

View File

@ -1,4 +1,4 @@
import React, { useRef, useState } from "react";
import React, { useRef, useState, useEffect } from "react";
import PropTypes from "prop-types";
import styled, { css } from "styled-components";
import Checkbox from "../../checkbox";
@ -157,9 +157,17 @@ const ADSelector = props => {
onGroupChanged
} = props;
//console.log("options", options);
//console.log("hasNextPage", hasNextPage);
//console.log("isNextPageLoading", isNextPageLoading);
const listOptionsRef = useRef(null);
const listGroupsRef = useRef(null);
useEffect(() => {
resetCache();
}, [searchValue, currentGroup, hasNextPage])
const [selectedOptionList, setSelectedOptionList] = useState(
selectedOptions || []
);
@ -294,7 +302,7 @@ const ADSelector = props => {
const resetCache = () => {
if (listOptionsRef && listOptionsRef.current) {
listOptionsRef.current.resetloadMoreItemsCache();
listOptionsRef.current.resetloadMoreItemsCache(true);
}
};
@ -302,13 +310,11 @@ const ADSelector = props => {
if(!currentGroup || !group || currentGroup.key === group.key)
return;
resetCache();
setCurrentGroup(group);
onGroupChanged && onGroupChanged(group);
};
const onSearchChange = value => {
resetCache();
setSearchValue(value);
onSearchChanged && onSearchChanged(value);
};
@ -481,12 +487,16 @@ const ADSelector = props => {
const loadMoreItems = startIndex => {
if (isNextPageLoading) return;
loadNextPage &&
loadNextPage({
const options = {
startIndex: startIndex || 0,
searchValue,
searchValue: searchValue,
currentGroup: currentGroup ? currentGroup.key : null
});
};
console.log("loadMoreItems", options);
loadNextPage &&
loadNextPage(options);
};
return (