diff --git a/public/client/js/react/src/search/filters.js b/public/client/js/react/src/search/filters.js
index 871e7de..c02fce6 100644
--- a/public/client/js/react/src/search/filters.js
+++ b/public/client/js/react/src/search/filters.js
@@ -155,9 +155,6 @@ const TextFilter = ({filter, changeFilter, removeFilter, search, aggs}) => {
setDropdownOptions([{label, options}])
}, [aggs]);
- useEffect(() => {
- debounce(filter)
- }, []);
useEffect(() => {
setText(filter.text)
@@ -165,7 +162,7 @@ const TextFilter = ({filter, changeFilter, removeFilter, search, aggs}) => {
const debouncedTextType = _.debounce(function(param){
changeFilter(param);
- },700,{leading: false, trailing: true});
+ },200,{leading: false, trailing: true});
function debounce(param) {
debouncedTextType(param)
diff --git a/public/client/js/react/src/search/map.js b/public/client/js/react/src/search/map.js
index 6693fcc..4529fe8 100644
--- a/public/client/js/react/src/search/map.js
+++ b/public/client/js/react/src/search/map.js
@@ -5,8 +5,9 @@ import * as helpers from '../../../lib/helpers';
let map; // Declare map variable
const Map = (props) => {
- const [currentQuery, setCurrentQuery] = useState('');
+ const [currentQuery, setCurrentQuery] = useState(JSON.stringify(queryBuilder.buildQueryShim(props.search)));
const mapRef = useRef(null); // To store the map instance without triggering re-renders
+ const searchRef = useRef(props.search);
// Equivalent to componentDidMount and componentDidUpdate
useEffect(() => {
@@ -43,18 +44,28 @@ const Map = (props) => {
});
}
+ if (!searchRef.current) {
+ searchRef.current = props.search
+ }
+
const query = queryBuilder.buildQueryShim(props.search);
mapRef.current.query(query);
- }, [props.search]); // Only re-run if props.search changes
+ }, []);
// Equivalent to UNSAFE_componentWillReceiveProps and shouldComponentUpdate
useEffect(() => {
+ const prevSearch = searchRef.current
+ if (prevSearch === props.search) {
+ return
+ }
+
const q = queryBuilder.buildQueryShim(props.search);
const next = JSON.stringify(q);
if (next !== currentQuery) {
setCurrentQuery(next);
mapRef.current.query(q);
+ searchRef.current = props.search
}
}, [props.search, currentQuery]);
diff --git a/public/client/js/react/src/search/results.js b/public/client/js/react/src/search/results.js
index e5a04f7..f31a2b1 100644
--- a/public/client/js/react/src/search/results.js
+++ b/public/client/js/react/src/search/results.js
@@ -1,9 +1,9 @@
-import React, {useState, useEffect, useMemo, useCallback, useRef} from 'react';
+import React, {useState, useEffect, useMemo, useCallback, useRef, memo} from 'react';
import idbapi from '../../../lib/idbapi';
import queryBuilder from '../../../lib/querybuilder';
-const Results = ({ searchProp, searchChange, view, viewChange, aggs, setAggs }) => {
+const Results = memo(({ searchProp, searchChange, view, viewChange, aggs, setAggs }) => {
const [lastQueryStringed, setLastQueryStringed] = useState('');
const [results, setResults] = useState([]);
const [attribution, setAttribution] = useState([]);
@@ -31,6 +31,7 @@ const Results = ({ searchProp, searchChange, view, viewChange, aggs, setAggs })
let more = response.itemCount > (search.from + search.size);
searchState.from = query.offset;
setSearch(searchState)
+ // searchChange(searchState)
setResults(res);
setAttribution(response.attribution);
setTotal(response.itemCount);
@@ -43,7 +44,7 @@ const Results = ({ searchProp, searchChange, view, viewChange, aggs, setAggs })
setLastQueryStringed(JSON.stringify(query));
}
- }, [search, results, lastQueryStringed]);
+ }, [search, lastQueryStringed]);
useEffect(() => {
if (searchProp!==search) {
@@ -56,21 +57,23 @@ const Results = ({ searchProp, searchChange, view, viewChange, aggs, setAggs })
}, [search]);
useEffect(() => {
- const handleScroll = () => {
+ const handleScroll = _.debounce(() => {
let newSearch = _.cloneDeep(search);
if (total > newSearch.from + newSearch.size) {
if (($(window).scrollTop() + 40 >= $(document).height() - $(window).height()) && (!loading)) {
+ setLoading(true)
newSearch.from += newSearch.size;
updateResults(newSearch);
+ searchChange(newSearch)
}
}
- };
+ }, 100);
window.onscroll = handleScroll;
return () => {
window.onscroll = null;
};
- }, [total, loading]);
+ }, [loading]);
const viewChangeHandler = (event) => {
event.preventDefault();
@@ -88,14 +91,14 @@ const Results = ({ searchProp, searchChange, view, viewChange, aggs, setAggs })
let resultsComponent;
switch (view) {
case 'list':
- resultsComponent =
;
+ resultsComponent =
;
break;
case 'labels':
resultsComponent =
;
break;
case 'media':
- resultsComponent = ;
+ resultsComponent = ;
break;
case 'recordsets':
resultsComponent = ;
@@ -119,7 +122,7 @@ const Results = ({ searchProp, searchChange, view, viewChange, aggs, setAggs })
{resultsComponent}
);
-}
+})
var sortClick=false;
const ResultsList = ({search, searchChange, results, loading}) => {
const [columns, setColumnsState] = useState(defaultColumns())
@@ -135,7 +138,7 @@ const ResultsList = ({search, searchChange, results, loading}) => {
}, [])
function resetColumns(){
- setColumns(defaultColumns());
+ setColumns(defaultColumns());
}
function defaultColumns(){
return ['family','scientificname','datecollected','country','institutioncode','basisofrecord'];
@@ -169,7 +172,7 @@ const ResultsList = ({search, searchChange, results, loading}) => {
//sorted column sorts the top level sort value in search and new sorting items length
//shall not exceed original length
var dir, localSearch = _.cloneDeep(search), name=e.currentTarget.attributes['data-term'].value,
- sort={name: name}, sorting=localSearch.sorting, curlength = sorting.length;
+ sort={name: name}, sorting=localSearch.sorting, curlength = sorting.length;
if(_.isUndefined(e.currentTarget.attributes['data-sort'])){
dir='asc';
}else{
@@ -198,14 +201,14 @@ const ResultsList = ({search, searchChange, results, loading}) => {
//to prevent opening if hiliting text
if(window.getSelection().toString().length===0 || (e.target.nodeName=='I' || e.target.nodeName=='BUTTON')){
- window.open('/portal/records/'+e.currentTarget.id,e.currentTarget.id);
+ window.open('/portal/records/'+e.currentTarget.id,e.currentTarget.id);
}
}
var cols = columns,self=this;
- //['scientificname','genus','collectioncode','specificepithet','commonname'];
+ //['scientificname','genus','collectioncode','specificepithet','commonname'];
var rows=[];
var headers=[];
//results table
@@ -331,7 +334,7 @@ const ResultsList = ({search, searchChange, results, loading}) => {
- {list}
+ {list}
@@ -343,10 +346,10 @@ const ResultsList = ({search, searchChange, results, loading}) => {