Skip to content

Commit

Permalink
Removing a favorite doesn't update the favorites list and the resourc…
Browse files Browse the repository at this point in the history
…e cannot be set as favorite again (#496)

* fix FavoriteList

* update UI with state value

* change error chach

* fix lint

* set favorite with api callback

* rm undefined in loading status
  • Loading branch information
luorlandini authored Sep 10, 2021
1 parent ad675a5 commit 6808ba2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ContentEditable from 'react-contenteditable';


const TextEditable = forwardRef(({
text,
text = "",
className = "gn-text-editable",
tagName,
disabled,
Expand Down
18 changes: 8 additions & 10 deletions geonode_mapstore_client/client/js/epics/favorite.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,32 @@ export const gnSaveFavoriteContent = (action$, store) =>
action$.ofType(SET_FAVORITE_RESOURCE)
.switchMap((action) => {
const state = store.getState();
const pk = state?.gnresource?.data.pk;
const isFavoriteList = (state?.gnsearch?.params?.f === 'favorite') ? true : false;
const pk = state?.gnresource?.data?.pk;
const isFavoriteList = (state?.gnsearch?.params?.f?.includes('favorite')) ? true : false;
const resource = state?.gnresource?.data;
const favorite = action.favorite;
const resources = store.getState().gnsearch?.resources || [];
const newResources = isFavoriteList ? ((resources.some(item => item.pk === resource.pk)) ?
resources.filter((item) => item.pk !== resource.pk)
: [...resources, resource]) : 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)

updateResources(newResources, true)
);

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

});


export default {
gnSaveFavoriteContent
};

0 comments on commit 6808ba2

Please sign in to comment.