Skip to content

Commit

Permalink
[Fixes 1169] (#1175) (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidQuartz authored Sep 9, 2022
1 parent da24952 commit 266520f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
10 changes: 10 additions & 0 deletions geonode_mapstore_client/client/js/actions/gnsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const UPDATE_RESOURCES_METADATA = 'GEONODE_SEARCH:UPDATE_RESOURCES_METADA
export const SET_FEATURED_RESOURCES = 'GEONODE:SET_FEATURED_RESOURCES';
export const UPDATE_FEATURED_RESOURCES = 'GEONODE_SEARCH:UPDATE_FEATURED_RESOURCES';
export const REDUCE_TOTAL_COUNT = 'GEONODE_REDUCE_TOTAL_COUNT';
export const INCREASE_TOTAL_COUNT = 'GEONODE_INCREASE_TOTAL_COUNT';

/**
* Actions for GeoNode resource featured items
Expand Down Expand Up @@ -90,6 +91,15 @@ export function reduceTotalCount() {
};
}

/**
* Increase total count of resouces after deletion
*/
export function increaseTotalCount() {
return {
type: INCREASE_TOTAL_COUNT
};
}


export default {
SEARCH_RESOURCES,
Expand Down
8 changes: 6 additions & 2 deletions geonode_mapstore_client/client/js/epics/favorite.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
SET_FAVORITE_RESOURCE
} from '@js/actions/gnresource';
import {
updateResources
updateResources,
reduceTotalCount,
increaseTotalCount
} from '@js/actions/gnsearch';
import {
setFavoriteResource
Expand Down Expand Up @@ -40,7 +42,9 @@ export const gnSaveFavoriteContent = (action$, store) =>
Observable.defer(() => setFavoriteResource(pk, favorite))
.switchMap(() => {
return Observable.of(
updateResources(newResources, true)
updateResources(newResources, true),
// if on favorites filter page, we must adjust total count appropriately
...((state?.gnsearch?.params?.f?.includes('favorite') && !action.favorite) ? [reduceTotalCount()] : [increaseTotalCount()])
);
})
.catch((error) => {
Expand Down
9 changes: 8 additions & 1 deletion geonode_mapstore_client/client/js/reducers/gnsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
LOADING_RESOURCES,
UPDATE_RESOURCES_METADATA,
SET_FEATURED_RESOURCES,
REDUCE_TOTAL_COUNT
REDUCE_TOTAL_COUNT,
INCREASE_TOTAL_COUNT
} from '@js/actions/gnsearch';

import { UPDATE_SINGLE_RESOURCE } from '@js/actions/gnresource';
Expand Down Expand Up @@ -104,6 +105,12 @@ function gnsearch(state = defaultState, action) {
total: state.total - 1
};
}
case INCREASE_TOTAL_COUNT: {
return {
...state,
total: state.total + 1
};
}
default:
return state;
}
Expand Down

0 comments on commit 266520f

Please sign in to comment.