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

A favorite icon will let the authenticated user add the resource to his favorites #214

Merged
merged 42 commits into from
Jun 25, 2021

Conversation

luorlandini
Copy link

A favorite icon will let the authenticated user add the resource to his favorites

logged user

Registrazione.schermo.2021-05-27.alle.17.44.48.mov

unlogged user

Registrazione.schermo.2021-05-27.alle.17.46.03.mov

@luorlandini luorlandini added the enhancement New feature or request label May 28, 2021
@luorlandini luorlandini self-assigned this May 28, 2021
@giohappy
Copy link

please @allyoucanmap review and merge this.

@@ -243,6 +243,12 @@ export const getDocumentsByDocType = (docType = 'image', {
}));
};

export const setFavouriteResource = (pk, method) => {
// eslint-disable-next-line dot-notation
return axios[method](parseDevHostname(`${endpoints[RESOURCES]}/${pk}/favorite`))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to pass the method?
I would prefer to have to separated function if they are needed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to have one function, instead of 2 similar function, in this case change only the CRUD method

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the aim is to use a single function I propose a different approach and do not expose the method.
Now we have here:

  • setFavouriteResource(pk, 'post') // set favourite to true
  • setFavouriteResource(pk, 'delete') // set favourite to false

My proposal is to make this more explicit:

  • setFavouriteResource(pk, true) // set favourite to true
  • setFavouriteResource(pk, false) // set favourite to false

Another proposal is to avoid as much as possible eslint-disable. We should try to follow the eslint rules:

const setFavouriteResource = (pk, favourite) => {
    const request = favourite ? axios.post : axios.get;
    return request(parseDevHostname(`${endpoints[RESOURCES]}/${pk}/favorite`))
}

closePanel,
favourite,
onFavourite,
isLogged
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use something more related to favourite instead of isLogged. isLogged is related to the user and the DetailsPanel component should not be aware of the user state

maybe enableFavourite?

const state = store.getState();
const pk = state?.gnresource?.data.pk;
const favourite = action.favourite;
const method = (favourite) ? 'post' : 'delete';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have setFavouriteResource and deleteFavouriteResource

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably is better removeFavouriteResource instead of delete

@luorlandini luorlandini requested a review from allyoucanmap June 25, 2021 08:38
@allyoucanmap allyoucanmap merged commit 8a02564 into GeoNode:master Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants