Skip to content

Commit

Permalink
303 update filtered list (#492)
Browse files Browse the repository at this point in the history
* rm add item in favorite list

* rm api call to get resource, use state

* rm comment

* rm unsed action

* add check favorite list
  • Loading branch information
luorlandini authored Sep 7, 2021
1 parent dbef1ba commit 0c29e35
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion geonode_mapstore_client/client/js/epics/favorite.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
updateResourceProperties,
SET_FAVORITE_RESOURCE
} from '@js/actions/gnresource';
import {
updateResources
} from '@js/actions/gnsearch';
import {
setFavoriteResource
} from '@js/api/geonode/v2';
Expand All @@ -21,15 +24,25 @@ export const gnSaveFavoriteContent = (action$, store) =>
.switchMap((action) => {
const state = store.getState();
const pk = state?.gnresource?.data.pk;
const isFavoriteList = (state?.gnsearch?.params?.f === 'favorite') ? true : false;
const resource = state?.gnresource?.data;
const favorite = action.favorite;
const resources = store.getState().gnsearch?.resources || [];
return Observable
.defer(() => setFavoriteResource(pk, favorite))
.switchMap(() => {
const newResources = (resources.some(item => item.pk === resource.pk)) ?
resources.filter((item) => item.pk !== resource.pk)
: [...resources, resource];

return Observable.of(
updateResourceProperties({
'favorite': favorite
})
}),
isFavoriteList && updateResources(newResources, true)

);

})
.catch((error) => {
return Observable.of(resourceError(error.data || error.message));
Expand Down

0 comments on commit 0c29e35

Please sign in to comment.