docbrown/app/javascript/packs/hideBookmarkButtons.js
Arit Amana 0d023163ba
Hide 'Save' button on posts that belong to the current user (#17293)
* implement change

* struggling with tests

* extend implementation to relevant views

* update Article.test.jsx snapshot

* fix failing specs

* query userData more robustly

* default saveable value in SaveButton component

* fix spec

* fetch currentUser async
2022-04-28 12:33:01 -04:00

12 lines
422 B
JavaScript

import { getUserDataAndCsrfToken } from '@utilities/getUserDataAndCsrfToken';
getUserDataAndCsrfToken().then(({ currentUser }) => {
const currentUserId = currentUser && currentUser.id;
document.querySelectorAll('.bookmark-button').forEach((button) => {
const { articleAuthorId } = button.dataset;
if (currentUserId && articleAuthorId == currentUserId) {
button.classList.add('hidden');
}
});
});