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

EZP-29266: Content item seems to be always bookmarked #509

Conversation

tischsoic
Copy link
Contributor

Fixes the bug concerning a bookmark star on a location page. The content was always bookmarked, even if it wasn't.

Question Answer
Tickets https://jira.ez.no/browse/EZP-29266
Bug fix? yes
New feature? no
BC breaks? no
Tests pass? -
Doc needed? no
License GPL-2.0

Checklist:

  • Coding standards ($ composer fix-cs)
  • Ready for Code Review

… adds propser CSS class on bookmark form wrapper; small adjustments in CSS styles were added.
@tischsoic tischsoic changed the title EZP-29266: Fixed bookmark icon on a location page; now JS dynamically… EZP-29266: Content item seems to be always bookmarked Jun 15, 2018
const bookmarkCheckedClass = 'ez-add-to-bookmarks--checked';

if (bookmarked) {
wrapperClassList.add(bookmarkCheckedClass);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not an expert, but I believe there is toggle method
@sunpietro

Copy link
Contributor Author

@tischsoic tischsoic Jun 15, 2018

Choose a reason for hiding this comment

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

This function also manages CSS class on event: ez-bookmark-change.
I assume that this event with bookmarked property set to true can occur even if the content is already bookmarked.
This is why I decided not to use toggle function.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can do it like this wrapper.classList.toggle('ez-add-to-bookmarks--checked', isBookmarked);. See the reference: https://developer.mozilla.org/en-US/docs/Web/API/Element/classList

@@ -15,14 +16,31 @@
const isCurrentLocation = (locationId) => {
return parseInt(locationId, 10) === currentLocationId;
};
const setBookmarkWrapperCheckedClass = (bookmarked) => {
const wrapperClassList = document.querySelector(SELECTOR_BOOKMARK_WRAPPER).classList;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be const wrapper = document.querySelector(SELECTOR_BOOKMARK_WRAPPER);

Copy link
Member

Choose a reason for hiding this comment

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

doc

@@ -15,14 +16,31 @@
const isCurrentLocation = (locationId) => {
return parseInt(locationId, 10) === currentLocationId;
};
const setBookmarkWrapperCheckedClass = (bookmarked) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

isBookmarked

const bookmarkCheckedClass = 'ez-add-to-bookmarks--checked';

if (bookmarked) {
wrapperClassList.add(bookmarkCheckedClass);
Copy link
Contributor

Choose a reason for hiding this comment

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

You can do it like this wrapper.classList.toggle('ez-add-to-bookmarks--checked', isBookmarked);. See the reference: https://developer.mozilla.org/en-US/docs/Web/API/Element/classList

const updateBookmarkForm = (event) => {
const { bookmarked, locationId } = event.detail;

if (isCurrentLocation(locationId)) {
updateBookmarkCheckbox(bookmarked);
setBookmarkWrapperCheckedClass(bookmarked);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like the function name. I see it more like this: toggleBookmarkCheckedState

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe, toggleBookmarkIconState?

}
};
const updateBookmarkWrapperClass = (event) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

updateBookmarkCheckedState

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that updateBookmarkCheckedState suggests that the input state is being updated, when it is not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe, updateBookmarkIconState?

@@ -15,14 +16,31 @@
const isCurrentLocation = (locationId) => {
return parseInt(locationId, 10) === currentLocationId;
};
const setBookmarkWrapperCheckedClass = (bookmarked) => {
const wrapperClassList = document.querySelector(SELECTOR_BOOKMARK_WRAPPER).classList;
const bookmarkCheckedClass = 'ez-add-to-bookmarks--checked';
Copy link
Member

Choose a reason for hiding this comment

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

This should be at the top CLASS_BOOKMARK_CHECKED.

@dew326
Copy link
Member

dew326 commented Jun 15, 2018

I don't where the markup was fixed to use bootstrap one?

@lserwatka
Copy link
Member

@dew326 @sunpietro are you OK with last changes?

@@ -4,6 +4,8 @@
const SELECTOR_BOOKMARK_LOCATION_INPUT = '#location_update_bookmark_location';
const SELECTOR_BOOKMARK_WRAPPER = '.ez-add-to-bookmarks';

const CLASS_BOOKMARK_CHECKED = 'ez-add-to-bookmarks--checked';
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, no extra lines before this const

Copy link
Contributor

Choose a reason for hiding this comment

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

You're using this CSS class once. There's no need to store it in a variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dew326 told me in above comment to store it in CLASS_BOOKMARK_CHECKED. :P

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, because in the previous approach you were using it in 2 places in the code. Now it's used only once.

Copy link
Member

Choose a reason for hiding this comment

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

It was when you were using it twice. There is no need to cache string when you use it once but it's also not a mistake, so it can stay. :)

@lserwatka lserwatka merged commit 5b45ed0 into ezsystems:master Jun 15, 2018
mateuszdebinski pushed a commit that referenced this pull request Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants