chore: toggle topic done

pull/3813/head
Arik Chakma 2 years ago
parent 38b1cf4b33
commit 7177638b49
  1. 30
      src/components/TopicOverlay/topic.js

@ -1,3 +1,4 @@
import { toggleMarkResourceDoneApi } from '../../lib/progress-api.ts';
export class Topic { export class Topic {
constructor() { constructor() {
this.overlayId = 'topic-overlay'; this.overlayId = 'topic-overlay';
@ -244,22 +245,41 @@ export class Topic {
return matchingElements; return matchingElements;
} }
markAsDone(topicId) { async markAsDone(topicId) {
const updatedTopicId = topicId.replace(/^\d+-/, ''); const updatedTopicId = topicId.replace(/^\d+-/, '');
localStorage.setItem(updatedTopicId, 'done'); const { response, error } = await toggleMarkResourceDoneApi({
resourceId: this.activeResourceId,
topicId: updatedTopicId,
resourceType: this.activeResourceType,
});
if (response) {
this.close();
this.querySvgElementsByTopicId(updatedTopicId).forEach((item) => { this.querySvgElementsByTopicId(updatedTopicId).forEach((item) => {
item?.classList?.add('done'); item?.classList?.add('done');
}); });
} else {
console.error(error);
}
} }
markAsPending(topicId) { async markAsPending(topicId) {
const updatedTopicId = topicId.replace(/^\d+-/, ''); const updatedTopicId = topicId.replace(/^\d+-/, '');
localStorage.removeItem(updatedTopicId); const { response, error } = await toggleMarkResourceDoneApi({
resourceId: this.activeResourceId,
topicId: updatedTopicId,
resourceType: this.activeResourceType,
});
if (response) {
this.close();
this.querySvgElementsByTopicId(updatedTopicId).forEach((item) => { this.querySvgElementsByTopicId(updatedTopicId).forEach((item) => {
item?.classList?.remove('done'); item?.classList?.remove('done');
}); });
} else {
console.error(error);
}
} }
handleOverlayClick(e) { handleOverlayClick(e) {
@ -275,7 +295,7 @@ export class Topic {
e.target.closest(`#${this.markTopicDoneId}`); e.target.closest(`#${this.markTopicDoneId}`);
if (isClickedDone) { if (isClickedDone) {
this.markAsDone(this.activeTopicId); this.markAsDone(this.activeTopicId);
this.close(); // this.close();
} }
const isClickedPending = const isClickedPending =

Loading…
Cancel
Save