Skip to content

Commit

Permalink
refactor(Discussion): Extract common function to show/hide posts
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokiterashima committed Oct 24, 2023
1 parent 46bea79 commit 57ff2be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
[response]="componentState"
[numReplies]="componentState.replies.length"
[mode]="'grading'"
(deleteButtonClicked)="deleteButtonClicked($event)"
(undoDeleteButtonClicked)="undoDeleteButtonClicked($event)"
(deleteButtonClicked)="hidePost($event)"
(undoDeleteButtonClicked)="showPost($event)"
[isDisabled]="true"
class="post"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,37 +107,8 @@ export class DiscussionShowWorkComponent extends ComponentShowWorkDirective {
* the class from seeing the post.
* @param componentState the student component state the teacher wants to delete.
*/
deleteButtonClicked(componentState: any): void {
const toWorkgroupId = componentState.workgroupId;
const userInfo = this.ConfigService.getUserInfoByWorkgroupId(toWorkgroupId);
const periodId = userInfo.periodId;
const teacherUserInfo = this.ConfigService.getMyUserInfo();
const fromWorkgroupId = teacherUserInfo.workgroupId;
const runId = this.ConfigService.getRunId();
const nodeId = this.nodeId;
const componentId = this.componentId;
const studentWorkId = componentState.id;
const data = {
action: 'Delete'
};
const annotation = this.AnnotationService.createInappropriateFlagAnnotation(
runId,
periodId,
nodeId,
componentId,
fromWorkgroupId,
toWorkgroupId,
studentWorkId,
data
);
this.AnnotationService.saveAnnotation(annotation).then(() => {
const componentStates = this.TeacherDiscussionService.getPostsAssociatedWithComponentIdsAndWorkgroupId(
this.getGradingComponentIds(),
this.workgroupId
);
const annotations = this.getInappropriateFlagAnnotationsByComponentStates(componentStates);
this.setClassResponses(componentStates, annotations);
});
protected hidePost(componentState: any): void {
this.flagPost(componentState, 'Delete');
}

/**
Expand All @@ -146,7 +117,11 @@ export class DiscussionShowWorkComponent extends ComponentShowWorkDirective {
* This will make the post visible to the students.
* @param componentState the student component state the teacher wants to show again.
*/
undoDeleteButtonClicked(componentState: any): any {
protected showPost(componentState: any): void {
this.flagPost(componentState, 'Undo Delete');
}

private flagPost(componentState: any, action: 'Delete' | 'Undo Delete'): void {
const toWorkgroupId = componentState.workgroupId;
const userInfo = this.ConfigService.getUserInfoByWorkgroupId(toWorkgroupId);
const periodId = userInfo.periodId;
Expand All @@ -157,7 +132,7 @@ export class DiscussionShowWorkComponent extends ComponentShowWorkDirective {
const componentId = this.componentId;
const studentWorkId = componentState.id;
const data = {
action: 'Undo Delete'
action: action
};
const annotation = this.AnnotationService.createInappropriateFlagAnnotation(
runId,
Expand Down

0 comments on commit 57ff2be

Please sign in to comment.