From 6cf16e9880c858923fc7830a9d92646ddfa95710 Mon Sep 17 00:00:00 2001 From: Davut Beyazit <davut.beyazit@mni.thm.de> Date: Mon, 10 May 2021 21:08:31 +0200 Subject: [PATCH] Fixed missing parse for JSON data Fixed period filters not being set if not done in filterTimePeriod --- .../moderator-comment-list.component.ts | 6 ++++-- .../shared/comment-list/comment-list.component.ts | 5 +++-- src/app/services/http/comment.service.ts | 9 +++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts b/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts index c31b1c07b..1dade371d 100644 --- a/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts +++ b/src/app/components/moderator/moderator-comment-list/moderator-comment-list.component.ts @@ -352,8 +352,6 @@ export class ModeratorCommentListComponent implements OnInit, OnDestroy { // set current filters to local storage for later use localStorage.setItem('currentFilters', JSON.stringify(this.currentFilter)); - localStorage.setItem('currentPeriod', JSON.stringify(this.period)); - localStorage.setItem('currentFromNowTimestamp', JSON.stringify(this.fromNow)); // can be null } clickedUserNumber(usrNumber: number): void { @@ -429,6 +427,10 @@ export class ModeratorCommentListComponent implements OnInit, OnDestroy { } else { this.commentsFilteredByTime = this.comments; } + + localStorage.setItem('currentPeriod', JSON.stringify(this.period)); + localStorage.setItem('currentFromNowTimestamp', JSON.stringify(this.fromNow)); // can be null + this.filterComments(this.currentFilter); } } diff --git a/src/app/components/shared/comment-list/comment-list.component.ts b/src/app/components/shared/comment-list/comment-list.component.ts index cb7475de6..f9a117285 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -508,8 +508,6 @@ export class CommentListComponent implements OnInit, OnDestroy { // set current filters to local storage for later use localStorage.setItem('currentFilters', JSON.stringify(this.currentFilter)); - localStorage.setItem('currentPeriod', JSON.stringify(this.period)); - localStorage.setItem('currentFromNowTimestamp', JSON.stringify(this.fromNow)); // can be null } sort(array: any[], type: string): any[] { @@ -643,6 +641,9 @@ export class CommentListComponent implements OnInit, OnDestroy { this.commentsFilteredByTime = this.comments; } + localStorage.setItem('currentPeriod', JSON.stringify(this.period)); + localStorage.setItem('currentFromNowTimestamp', JSON.stringify(this.fromNow)); // can be null + this.filterComments(this.currentFilter); this.titleService.attachTitle('(' + this.commentsFilteredByTime.length + ')'); } diff --git a/src/app/services/http/comment.service.ts b/src/app/services/http/comment.service.ts index a6828e2a0..4d88c290e 100644 --- a/src/app/services/http/comment.service.ts +++ b/src/app/services/http/comment.service.ts @@ -100,12 +100,11 @@ export class CommentService extends BaseHttpService { filter(com : Comment) : boolean { /* Get Filter Options */ - const currentFilters = localStorage.getItem('currentFilters'); - const period = localStorage.getItem('currentPeriod'); - const timestamp = localStorage.getItem('currentFromNowTimestamp'); + const currentFilters = JSON.parse(localStorage.getItem('currentFilters')); + const period = JSON.parse(localStorage.getItem('currentPeriod')); + const timestamp = JSON.parse(localStorage.getItem('currentFromNowTimestamp')); /* Filter by Period */ - /* const currentTime = new Date(); const hourInSeconds = 3600000; let periodInSeconds; @@ -149,8 +148,6 @@ export class CommentService extends BaseHttpService { return false; } - */ - /* Other Filters */ const read = 'read'; const unread = 'unread'; -- GitLab