fix: best practice topic toggle

pull/3813/head
Arik Chakma 2 years ago
parent 0018627afe
commit 2c06225c3c
  1. 35
      src/components/TopicOverlay/topic.js

@ -153,9 +153,9 @@ export class Topic {
const isDone = localStorage.getItem(topicId) === 'done'; const isDone = localStorage.getItem(topicId) === 'done';
if (isDone) { if (isDone) {
this.markAsPending(topicId); this.markAsPending(topicId, bestPracticeId, 'best-practice');
} else { } else {
this.markAsDone(topicId); this.markAsDone(topicId, bestPracticeId, 'best-practice');
} }
} }
@ -166,7 +166,7 @@ export class Topic {
return; return;
} }
this.markAsPending(topicId); this.markAsPending(topicId, bestPracticeId, 'best-practice');
} }
handleBestPracticeTopicClick(e) { handleBestPracticeTopicClick(e) {
@ -245,12 +245,15 @@ export class Topic {
return matchingElements; return matchingElements;
} }
async markAsDone(topicId) { async markAsDone(topicId, resourceId, resourceType) {
const updatedTopicId = topicId.replace(/^\d+-/, ''); const updatedTopicId = topicId.replace(/^\d+-/, '');
console.log('Marking as done: ', updatedTopicId, resourceId, resourceType);
const { response, error } = await toggleMarkResourceDoneApi({ const { response, error } = await toggleMarkResourceDoneApi({
resourceId: this.activeResourceId, resourceId,
topicId: updatedTopicId, topicId: updatedTopicId,
resourceType: this.activeResourceType, resourceType,
}); });
if (response) { if (response) {
@ -263,13 +266,13 @@ export class Topic {
} }
} }
async markAsPending(topicId) { async markAsPending(topicId, resourceId, resourceType) {
const updatedTopicId = topicId.replace(/^\d+-/, ''); const updatedTopicId = topicId.replace(/^\d+-/, '');
const { response, error } = await toggleMarkResourceDoneApi({ const { response, error } = await toggleMarkResourceDoneApi({
resourceId: this.activeResourceId, resourceId,
topicId: updatedTopicId, topicId: updatedTopicId,
resourceType: this.activeResourceType, resourceType,
}); });
if (response) { if (response) {
@ -294,7 +297,11 @@ export class Topic {
e.target.id === this.markTopicDoneId || e.target.id === this.markTopicDoneId ||
e.target.closest(`#${this.markTopicDoneId}`); e.target.closest(`#${this.markTopicDoneId}`);
if (isClickedDone) { if (isClickedDone) {
this.markAsDone(this.activeTopicId); this.markAsDone(
this.activeTopicId,
this.activeResourceId,
this.activeResourceType
);
// this.close(); // this.close();
} }
@ -302,8 +309,12 @@ export class Topic {
e.target.id === this.markTopicPendingId || e.target.id === this.markTopicPendingId ||
e.target.closest(`#${this.markTopicPendingId}`); e.target.closest(`#${this.markTopicPendingId}`);
if (isClickedPending) { if (isClickedPending) {
this.markAsPending(this.activeTopicId); this.markAsPending(
this.close(); this.activeTopicId,
this.activeResourceId,
this.activeResourceType
);
// this.close();
} }
const isClickedPopupOpener = const isClickedPopupOpener =

Loading…
Cancel
Save