@ministryofjustice/hmpps-digital-prison-reporting-frontend 5.2.0 → 5.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/all.js CHANGED
@@ -114,23 +114,27 @@ class BookmarkButton extends DprClientClass {
114
114
  * @memberof BookmarkButton
115
115
  */
116
116
  initEventListener() {
117
- this.getElement().addEventListener('click', () => this.activateBookmark());
117
+ this.getElement().addEventListener('click', (e) => this.activateBookmark(e));
118
118
  this.getElement().addEventListener('keydown', (e) => {
119
119
  if (e.key === 'Enter' || e.key === ' ') {
120
- this.activateBookmark();
120
+ this.activateBookmark(e);
121
121
  }
122
122
  });
123
123
  }
124
- async activateBookmark() {
124
+ async activateBookmark(e) {
125
+ e.preventDefault();
125
126
  if (this.isRunning)
126
127
  return;
127
128
  this.isRunning = true;
128
- this.getElement().style.pointerEvents = 'none';
129
- this.getElement().style.opacity = '0.5';
129
+ this.getElement().classList.add('bookmark-disabled');
130
130
  try {
131
131
  await fetch(this.endpoint, {
132
132
  method: 'POST',
133
- headers: { 'Content-Type': 'application/json' },
133
+ headers: {
134
+ Accept: 'application/json',
135
+ 'Content-Type': 'application/json',
136
+ 'CSRF-Token': this.csrfToken,
137
+ },
134
138
  body: JSON.stringify({
135
139
  type: this.linkType,
136
140
  id: this.id,
@@ -152,8 +156,7 @@ class BookmarkButton extends DprClientClass {
152
156
  }
153
157
  finally {
154
158
  this.isRunning = false;
155
- this.getElement().style.pointerEvents = '';
156
- this.getElement().style.opacity = '1';
159
+ this.getElement().classList.remove('bookmark-disabled');
157
160
  }
158
161
  }
159
162
  }