Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-8195: Content items are displayed multiple times in UDW after adding item to bookmarks #1265

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@
display: flex;
align-items: center;
justify-content: center;
margin-top: calculateRem(50px);
margin: calculateRem(50px) 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 >= locationData.totalCount;
const isOffsetReached = target.scrollHeight - target.clientHeight - target.scrollTop < SCROLL_OFFSET;

if (areAllItemsLoaded || !isOffsetReached || isLoading) {
return;
}

setOffset(offset + itemsPerPage);
setOffset(Math.min(offset + itemsPerPage, locationData.totalCount));
};
const expandBranch = () => {
dispatchLoadedLocationsAction({ type: 'UPDATE_LOCATIONS', data: { ...locationData, collapsed: false } });
Expand Down Expand Up @@ -113,11 +112,11 @@ const FinderBranch = ({ locationData, itemsPerPage }) => {
return (
<Fragment>
<div className="c-finder-branch__items-wrapper" onScroll={loadMore} style={{ width }}>
{renderLoadingSpinner()}

{subitems.map(({ location }) => (
<FinderLeaf key={location.id} location={location} />
))}

{renderLoadingSpinner()}
</div>
{renderDragHandler()}
</Fragment>
Expand All @@ -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]);
Expand Down Expand Up @@ -172,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down
Loading