From fe9980d71f28f74dbcb45ef3af355e6a2334e292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Grabowski?= Date: Fri, 17 May 2024 13:59:54 +0200 Subject: [PATCH 1/3] IBX-8195: Content items are displayed multiple times in UDW after adding item to bookmarks --- .../universal-discovery/_finder.branch.scss | 2 +- .../components/finder/finder.branch.js | 11 ++++------- .../useFindLocationsByParentLocationIdFetch.js | 18 ++++++++---------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/bundle/Resources/public/scss/ui/modules/universal-discovery/_finder.branch.scss b/src/bundle/Resources/public/scss/ui/modules/universal-discovery/_finder.branch.scss index 394a459755..697a374346 100644 --- a/src/bundle/Resources/public/scss/ui/modules/universal-discovery/_finder.branch.scss +++ b/src/bundle/Resources/public/scss/ui/modules/universal-discovery/_finder.branch.scss @@ -69,6 +69,6 @@ display: flex; align-items: center; justify-content: center; - margin-top: calculateRem(50px); + margin: calculateRem(50px) 0; } } diff --git a/src/bundle/ui-dev/src/modules/universal-discovery/components/finder/finder.branch.js b/src/bundle/ui-dev/src/modules/universal-discovery/components/finder/finder.branch.js index b21aff638e..64dc19ed12 100644 --- a/src/bundle/ui-dev/src/modules/universal-discovery/components/finder/finder.branch.js +++ b/src/bundle/ui-dev/src/modules/universal-discovery/components/finder/finder.branch.js @@ -27,7 +27,6 @@ const FinderBranch = ({ locationData, itemsPerPage }) => { const [sortOrder] = useContext(SortOrderContext); const contentTypesMap = useContext(ContentTypesMapContext); const [markedLocationId] = useContext(MarkedLocationIdContext); - const totalCount = useRef(0); const branchRef = useRef(null); const sortingOptions = SORTING_OPTIONS.find((option) => option.sortClause === sorting); const [loadedLocations, isLoading] = useFindLocationsByParentLocationIdFetch( @@ -40,14 +39,14 @@ const FinderBranch = ({ locationData, itemsPerPage }) => { let resizeStartPositionX = 0; let branchCurrentWidth = 0; const loadMore = ({ target }) => { - const areAllItemsLoaded = locationData.subitems.length >= totalCount.current; + const areAllItemsLoaded = locationData.subitems.length >= loadedLocations.totalCount; const isOffsetReached = target.scrollHeight - target.clientHeight - target.scrollTop < SCROLL_OFFSET; if (areAllItemsLoaded || !isOffsetReached || isLoading) { return; } - setOffset(offset + itemsPerPage); + setOffset(Math.min(offset + itemsPerPage, loadedLocations.totalCount)); }; const expandBranch = () => { dispatchLoadedLocationsAction({ type: 'UPDATE_LOCATIONS', data: { ...locationData, collapsed: false } }); @@ -113,11 +112,11 @@ const FinderBranch = ({ locationData, itemsPerPage }) => { return (
- {renderLoadingSpinner()} - {subitems.map(({ location }) => ( ))} + + {renderLoadingSpinner()}
{renderDragHandler()}
@@ -137,14 +136,12 @@ const FinderBranch = ({ locationData, itemsPerPage }) => { useEffect(() => { setOffset(0); - totalCount.current = 0; }, [sortingOptions.sortClause, sortOrder]); useEffect(() => { if (loadedLocations.subitems) { const data = { ...locationData, ...loadedLocations, subitems: [...locationData.subitems, ...loadedLocations.subitems] }; - totalCount.current = loadedLocations.totalCount; dispatchLoadedLocationsAction({ type: 'UPDATE_LOCATIONS', data }); } }, [loadedLocations, dispatchLoadedLocationsAction, isLoading]); diff --git a/src/bundle/ui-dev/src/modules/universal-discovery/hooks/useFindLocationsByParentLocationIdFetch.js b/src/bundle/ui-dev/src/modules/universal-discovery/hooks/useFindLocationsByParentLocationIdFetch.js index d425525d30..3695303f23 100644 --- a/src/bundle/ui-dev/src/modules/universal-discovery/hooks/useFindLocationsByParentLocationIdFetch.js +++ b/src/bundle/ui-dev/src/modules/universal-discovery/hooks/useFindLocationsByParentLocationIdFetch.js @@ -66,17 +66,15 @@ export const useFindLocationsByParentLocationIdFetch = (locationData, { sortClau let effectCleaned = false; - if (state.dataFetched) { - if ( - !locationData.parentLocationId || - locationData.collapsed || - locationData.subitems.length >= locationData.totalCount || - locationData.subitems.length >= limit + offset - ) { - dispatch({ type: 'FETCH_END', data: {} }); + if ( + !locationData.parentLocationId || + locationData.collapsed || + locationData.subitems.length >= locationData.totalCount || + locationData.subitems.length >= limit + offset + ) { + dispatch({ type: 'FETCH_END', data: state.data }); - return; - } + return; } dispatch({ type: 'FETCH_START' }); From 86281e7842787b23242ee4066c96e92b5c574e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Grabowski?= Date: Tue, 4 Jun 2024 17:01:35 +0200 Subject: [PATCH 2/3] change loaded location total to location data total on load more --- .../universal-discovery/components/finder/finder.branch.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bundle/ui-dev/src/modules/universal-discovery/components/finder/finder.branch.js b/src/bundle/ui-dev/src/modules/universal-discovery/components/finder/finder.branch.js index 64dc19ed12..d1a095bca8 100644 --- a/src/bundle/ui-dev/src/modules/universal-discovery/components/finder/finder.branch.js +++ b/src/bundle/ui-dev/src/modules/universal-discovery/components/finder/finder.branch.js @@ -39,14 +39,14 @@ const FinderBranch = ({ locationData, itemsPerPage }) => { let resizeStartPositionX = 0; let branchCurrentWidth = 0; const loadMore = ({ target }) => { - const areAllItemsLoaded = locationData.subitems.length >= loadedLocations.totalCount; + const areAllItemsLoaded = locationData.subitems.length >= locationData.totalCount; const isOffsetReached = target.scrollHeight - target.clientHeight - target.scrollTop < SCROLL_OFFSET; if (areAllItemsLoaded || !isOffsetReached || isLoading) { return; } - setOffset(Math.min(offset + itemsPerPage, loadedLocations.totalCount)); + setOffset(Math.min(offset + itemsPerPage, locationData.totalCount)); }; const expandBranch = () => { dispatchLoadedLocationsAction({ type: 'UPDATE_LOCATIONS', data: { ...locationData, collapsed: false } }); From a0c14e451102c94c1dec2e111db0e885a1ddea1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Grabowski?= Date: Fri, 7 Jun 2024 10:14:51 +0200 Subject: [PATCH 3/3] fix linter --- .../universal-discovery/components/finder/finder.branch.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bundle/ui-dev/src/modules/universal-discovery/components/finder/finder.branch.js b/src/bundle/ui-dev/src/modules/universal-discovery/components/finder/finder.branch.js index d1a095bca8..5a55d30df3 100644 --- a/src/bundle/ui-dev/src/modules/universal-discovery/components/finder/finder.branch.js +++ b/src/bundle/ui-dev/src/modules/universal-discovery/components/finder/finder.branch.js @@ -169,6 +169,7 @@ FinderBranch.propTypes = { parentLocationId: PropTypes.number.isRequired, subitems: PropTypes.array.isRequired, location: PropTypes.object.isRequired, + totalCount: PropTypes.number.isRequired, collapsed: PropTypes.bool, }).isRequired, itemsPerPage: PropTypes.number,