@abcagency/hc-ui-components 1.3.12 → 1.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/hooks/useList.js
CHANGED
|
@@ -40,7 +40,7 @@ var useListLogic = function useListLogic() {
|
|
|
40
40
|
localStorage.setItem('sortSetting', JSON.stringify(sortSetting));
|
|
41
41
|
var listingFiltered = dynamicSort(filteredListings, sortSetting.field, sortSetting.type);
|
|
42
42
|
setFilteredListings(listingFiltered);
|
|
43
|
-
}, [sortSetting
|
|
43
|
+
}, [sortSetting]);
|
|
44
44
|
useEffect(function () {
|
|
45
45
|
observer.current = new IntersectionObserver(handleObserver, {
|
|
46
46
|
root: scrollContainerRef.current,
|
|
@@ -60,13 +60,15 @@ var useListLogic = function useListLogic() {
|
|
|
60
60
|
}, [filteredListings.length, itemLimit]);
|
|
61
61
|
useEffect(function () {
|
|
62
62
|
localStorage.setItem('scrollPosition', scrollPosition.toString());
|
|
63
|
+
}, [scrollPosition]);
|
|
64
|
+
useEffect(function () {
|
|
63
65
|
var savedScrollPosition = scrollPosition;
|
|
64
66
|
if (parseInt(savedScrollPosition) > 3000) {
|
|
65
67
|
setItemLimit(savedScrollPosition / 10);
|
|
66
68
|
}
|
|
67
|
-
if (savedScrollPosition && scrollContainerRef.current) {
|
|
69
|
+
if (savedScrollPosition && scrollPosition != null && scrollContainerRef.current) {
|
|
70
|
+
scrollContainerRef.current;
|
|
68
71
|
setTimeout(function () {
|
|
69
|
-
scrollContainerRef.current.scrollTop = parseInt(savedScrollPosition, 10);
|
|
70
72
|
}, 300);
|
|
71
73
|
}
|
|
72
74
|
}, []);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useList.js","sources":["../../src/hooks/useList.js"],"sourcesContent":["import { useEffect, useState, useRef } from 'react';\n\nimport { getStorageObject } from '~/util/localStorageUtil';\nimport { dynamicSort } from '~/util/sortUtil';\n\nimport { useMapList } from '~/contexts/mapListContext';\n\nconst getDefaultItemId = () => {\n\tlet item = getStorageObject(\"selectedListItem\");\n\tif (item?.expanded == true) {\n\t\treturn item.id;\n\t} else {\n\t\treturn null;\n\t}\n};\n\nconst useListLogic = () => {\n\tconst [itemLimit, setItemLimit] = useState(100);\n\tconst [expandedId] = useState(getDefaultItemId());\n\tconst [sortSetting, setSortSetting] = useState(getStorageObject('sortSetting', null));\n\tconst [scrollPosition, setScrollPosition] = useState(getStorageObject('scrollPosition', 0));\n\tconst loader = useRef(null);\n\tconst scrollContainerRef = useRef(null);\n\tconst itemRefs = useRef({});\n\tconst observer = useRef(null);\n\tconst { filteredListings, setFilteredListings } = useMapList();\n\n\tuseEffect(() => {\n\t\tif (!sortSetting) return;\n\t\tlocalStorage.setItem('sortSetting', JSON.stringify(sortSetting));\n\t\tlet listingFiltered = dynamicSort(filteredListings, sortSetting.field, sortSetting.type);\n\t\tsetFilteredListings(listingFiltered);\n\t}, [sortSetting
|
|
1
|
+
{"version":3,"file":"useList.js","sources":["../../src/hooks/useList.js"],"sourcesContent":["import { useEffect, useState, useRef } from 'react';\n\nimport { getStorageObject } from '~/util/localStorageUtil';\nimport { dynamicSort } from '~/util/sortUtil';\n\nimport { useMapList } from '~/contexts/mapListContext';\n\nconst getDefaultItemId = () => {\n\tlet item = getStorageObject(\"selectedListItem\");\n\tif (item?.expanded == true) {\n\t\treturn item.id;\n\t} else {\n\t\treturn null;\n\t}\n};\n\nconst useListLogic = () => {\n\tconst [itemLimit, setItemLimit] = useState(100);\n\tconst [expandedId] = useState(getDefaultItemId());\n\tconst [sortSetting, setSortSetting] = useState(getStorageObject('sortSetting', null));\n\tconst [scrollPosition, setScrollPosition] = useState(getStorageObject('scrollPosition', 0));\n\tconst loader = useRef(null);\n\tconst scrollContainerRef = useRef(null);\n\tconst itemRefs = useRef({});\n\tconst observer = useRef(null);\n\tconst { filteredListings, setFilteredListings } = useMapList();\n\n\tuseEffect(() => {\n\t\tif (!sortSetting) return;\n\t\tlocalStorage.setItem('sortSetting', JSON.stringify(sortSetting));\n\t\tlet listingFiltered = dynamicSort(filteredListings, sortSetting.field, sortSetting.type);\n\t\tsetFilteredListings(listingFiltered);\n\t}, [sortSetting]);\n\n\tuseEffect(() => {\n\t\tobserver.current = new IntersectionObserver(handleObserver, {\n\t\t\troot: scrollContainerRef.current,\n\t\t\trootMargin: \"100px 0px\",\n\t\t\tthreshold: 0.5\n\t\t});\n\t\tconst { current } = loader;\n\t\tif (current) {\n\t\t\tobserver.current.observe(current);\n\t\t}\n\t\treturn () => {\n\t\t\tif (observer.current && current) {\n\t\t\t\tobserver.current.unobserve(current);\n\t\t\t}\n\t\t};\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [filteredListings.length, itemLimit]);\n\n\tuseEffect(() => {\n\t\tlocalStorage.setItem('scrollPosition', scrollPosition.toString());\n\t}, [scrollPosition]);\n\n\tuseEffect(() => {\n\t\tconst savedScrollPosition = scrollPosition;\n\t\tif (parseInt(savedScrollPosition) > 3000) {\n\t\t\tsetItemLimit(savedScrollPosition / 10);\n\t\t}\n\t\tif (savedScrollPosition && scrollPosition != null && scrollContainerRef.current) {\n\t\t\tlet scrollContainerRefCurrent = scrollContainerRef.current;\n\t\t\tsetTimeout(() => {\n\t\t\t\tscrollContainerRefCurrent = parseInt(savedScrollPosition, 10);\n\t\t\t}, 300);\n\t\t}\n\t}, []);\n\n\tuseEffect(() => {\n\t\tconst { current } = scrollContainerRef;\n\t\tif (current) {\n\t\t\tcurrent.addEventListener('scroll', handleScroll);\n\t\t}\n\t\treturn () => {\n\t\t\tif (current) {\n\t\t\t\tcurrent.removeEventListener('scroll', handleScroll);\n\t\t\t}\n\t\t};\n\t}, []);\n\n\tconst handleObserver = entities => {\n\t\tconst target = entities[0];\n\t\tif (!target.isIntersecting) return;\n\t\tif (filteredListings.length > itemLimit) {\n\t\t\tsetItemLimit(prevLimit => prevLimit + 100);\n\t\t} else if (observer.current) {\n\t\t\tobserver.current.disconnect();\n\t\t}\n\t};\n\n\tconst handleScroll = () => {\n\t\tif (scrollContainerRef.current) {\n\t\t\tsetScrollPosition(scrollContainerRef.current.scrollTop);\n\t\t}\n\t};\n\n\treturn { itemLimit, expandedId, sortSetting, scrollPosition, loader, scrollContainerRef, itemRefs, setSortSetting, setScrollPosition, dynamicSort, filteredListings };\n};\n\nexport default useListLogic;\n"],"names":["getDefaultItemId","item","getStorageObject","expanded","id","useListLogic","_useState","useState","_useState2","_slicedToArray","itemLimit","setItemLimit","_useState3","_useState4","expandedId","_useState5","_useState6","sortSetting","setSortSetting","_useState7","_useState8","scrollPosition","setScrollPosition","loader","useRef","scrollContainerRef","itemRefs","observer","_useMapList","useMapList","filteredListings","setFilteredListings","useEffect","localStorage","setItem","JSON","stringify","listingFiltered","dynamicSort","field","type","current","IntersectionObserver","handleObserver","root","rootMargin","threshold","observe","unobserve","length","toString","savedScrollPosition","parseInt","setTimeout","addEventListener","handleScroll","removeEventListener","entities","target","isIntersecting","prevLimit","disconnect","scrollTop"],"mappings":";;;;;;AAOA,IAAMA,gBAAgB,GAAG,SAAnBA,gBAAgBA,GAAS;AAC9B,EAAA,IAAIC,IAAI,GAAGC,gBAAgB,CAAC,kBAAkB,CAAC,CAAA;EAC/C,IAAI,CAAAD,IAAI,KAAA,IAAA,IAAJA,IAAI,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAJA,IAAI,CAAEE,QAAQ,KAAI,IAAI,EAAE;IAC3B,OAAOF,IAAI,CAACG,EAAE,CAAA;AACf,GAAC,MAAM;AACN,IAAA,OAAO,IAAI,CAAA;AACZ,GAAA;AACD,CAAC,CAAA;AAED,IAAMC,YAAY,GAAG,SAAfA,YAAYA,GAAS;AAC1B,EAAA,IAAAC,SAAA,GAAkCC,QAAQ,CAAC,GAAG,CAAC;IAAAC,UAAA,GAAAC,cAAA,CAAAH,SAAA,EAAA,CAAA,CAAA;AAAxCI,IAAAA,SAAS,GAAAF,UAAA,CAAA,CAAA,CAAA;AAAEG,IAAAA,YAA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AAS;IAC1B,IAAI9B,kBAAkB,CAACgB,OAAO,EAAE;AAC/BnB,MAAAA,iBAAiB,CAACG,kBAAkB,CAACgB,OAAO,CAACqB,SAAS,CAAC,CAAA;AACxD,KAAA;GACA,CAAA;EAED,OAAO;AAAEpD,IAAAA,SAAS,EAATA,SAAS;AAAEI,IAAAA,UAAU,EAAVA,UAAU;AAAEG,IAAAA,WAAW,EAAXA,WAAW;AAAEI,IAAAA,cAAc,EAAdA,cAAc;AAAEE,IAAAA,MAAM,EAANA,MAAM;AAAEE,IAAAA,kBAAkB,EAAlBA,kBAAkB;AAAEC,IAAAA,QAAQ,EAARA,QAAQ;AAAER,IAAAA,cAAc,EAAdA,cAAc;AAAEI,IAAAA,iBAAiB,EAAjBA,iBAAiB;AAAEgB,IAAAA,WAAW,EAAXA,WAAW;AAAER,IAAAA,gBAAgB,EAAhBA,gBAAAA;GAAkB,CAAA;AACtK;;;;"}
|
package/package.json
CHANGED
package/src/hooks/useList.js
CHANGED
|
@@ -30,7 +30,7 @@ const useListLogic = () => {
|
|
|
30
30
|
localStorage.setItem('sortSetting', JSON.stringify(sortSetting));
|
|
31
31
|
let listingFiltered = dynamicSort(filteredListings, sortSetting.field, sortSetting.type);
|
|
32
32
|
setFilteredListings(listingFiltered);
|
|
33
|
-
}, [sortSetting
|
|
33
|
+
}, [sortSetting]);
|
|
34
34
|
|
|
35
35
|
useEffect(() => {
|
|
36
36
|
observer.current = new IntersectionObserver(handleObserver, {
|
|
@@ -52,13 +52,17 @@ const useListLogic = () => {
|
|
|
52
52
|
|
|
53
53
|
useEffect(() => {
|
|
54
54
|
localStorage.setItem('scrollPosition', scrollPosition.toString());
|
|
55
|
+
}, [scrollPosition]);
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
55
58
|
const savedScrollPosition = scrollPosition;
|
|
56
59
|
if (parseInt(savedScrollPosition) > 3000) {
|
|
57
60
|
setItemLimit(savedScrollPosition / 10);
|
|
58
61
|
}
|
|
59
|
-
if (savedScrollPosition && scrollContainerRef.current) {
|
|
62
|
+
if (savedScrollPosition && scrollPosition != null && scrollContainerRef.current) {
|
|
63
|
+
let scrollContainerRefCurrent = scrollContainerRef.current;
|
|
60
64
|
setTimeout(() => {
|
|
61
|
-
|
|
65
|
+
scrollContainerRefCurrent = parseInt(savedScrollPosition, 10);
|
|
62
66
|
}, 300);
|
|
63
67
|
}
|
|
64
68
|
}, []);
|