Skip to content

Commit

Permalink
Merge pull request #588 from Afzal84/topicMsg-issue
Browse files Browse the repository at this point in the history
Fixes Topic duplicacy & Topic toast msg
  • Loading branch information
aAmitSengar authored Oct 14, 2022
2 parents 2f610a1 + 6f60af3 commit d48fca8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, Input, OnInit } from '@angular/core'
import { MatSnackBar } from '@angular/material'
// tslint:disable-next-line
import _ from 'lodash'
import { NSProfileDataV3 } from '../../models/profile-v3.models'
Expand All @@ -8,15 +9,15 @@ import { TopicService } from '../../services/topics.service'
selector: 'ws-app-topic-card',
templateUrl: './topic-card.component.html',
styleUrls: ['./topic-card.component.scss'],
/* tslint:disable */
/* tslint:disable */
host: { class: 'flex flex-1 top_main flex-col' },
/* tslint:enable */
})
export class TopicCardComponent implements OnInit {
@Input() topic!: NSProfileDataV3.ITopic
show = 6
// selectedTopics: Subscription | null = null
constructor(private topicService: TopicService) { }
constructor(private topicService: TopicService, private snackBar: MatSnackBar) { }

ngOnInit() {

Expand All @@ -28,9 +29,11 @@ export class TopicCardComponent implements OnInit {
if (index !== -1) {
/// remove from store
this.topicService.removeSystemTopics(top)
this.snackBar.open('Removed successfully!')
} else {
/// add to store
this.topicService.addSystemTopics(top)
this.snackBar.open('Added successfully!')
}
} else {
const index = _.indexOf(this.topicService.getCurrentSelectedDesTopics, top)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ export class TopicComponent implements OnInit, OnDestroy {
this.topicService.saveDesiredTopic(reqObj).subscribe(res => {
if (res) {
this.configSvc.updateGlobalProfile(true)
this.snackBar.open('Updated!')
}
})
}, (_error: any) => {
this.snackBar.open('Server error!')
}
)
}
}

Expand All @@ -165,9 +167,11 @@ export class TopicComponent implements OnInit, OnDestroy {
this.topicService.saveSystemTopic(reqObj).subscribe(res => {
if (res) {
this.configSvc.updateGlobalProfile(true)
this.snackBar.open('Updated!')
}
})
}, (_error: any) => {
this.snackBar.open('Server error!')
}
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HttpClient } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { MatSnackBar } from '@angular/material'
// tslint:disable-next-line
import _ from 'lodash'
import { BehaviorSubject, Observable } from 'rxjs'
Expand All @@ -17,7 +18,7 @@ export class TopicService {
public desiredTopics = new BehaviorSubject<string[]>([])
public autoSave = new BehaviorSubject<boolean>(false)
constructor(
private http: HttpClient) {
private http: HttpClient, private snackBar: MatSnackBar) {
}
loadTopics(): Observable<any> {
return this.http.get<any>(API_END_POINTS.getTopics)
Expand All @@ -29,8 +30,15 @@ export class TopicService {
}
addDesiredTopics(topic: string) {
const topics = this.desiredTopics.value
topics.push(topic)
this.desiredTopics.next(topics)
const index = _.indexOf(topics, topic)
if (index === -1) {
topics.push(topic)
this.snackBar.open('Added successfully!')
this.desiredTopics.next(topics)
} else {
this.snackBar.open('Alredy exist!')
}

}
/**
* this method will fill all already added topics from users Profile.
Expand Down Expand Up @@ -58,6 +66,7 @@ export class TopicService {
if (index !== -1) {
topics.splice(index, 1)
this.desiredTopics.next(topics)
this.snackBar.open('Removed successfully!')
}
}
// removeDesiredTopics(topic: string) {
Expand Down

0 comments on commit d48fca8

Please sign in to comment.