Skip to content

Commit

Permalink
Fixed repeating buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
MuraliChandran committed May 6, 2020
1 parent 75db482 commit 8599c62
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webchat",
"version": "0.0.0",
"version": "1.2.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
3 changes: 0 additions & 3 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ <h1>Chat-App-Making</h1>
<app-chat-widget ></app-chat-widget>
</div>




<router-outlet></router-outlet>
51 changes: 39 additions & 12 deletions src/app/chat/chat-widget/chat-widget.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ export class ChatWidgetComponent implements OnInit {

public messages = [];
public BT = [];
public result = [];
a: string;
public val = [];

count = 0;
public get visible() {
return this._visible;
}
Expand Down Expand Up @@ -93,31 +95,33 @@ export class ChatWidgetComponent implements OnInit {

addBT(title: any) {
this.BT.push({ title });

//Get Disctinct Buttons
this.DistinctButtons(this.BT);
}

buttonclick($event: Event) {
var a = $event.srcElement as HTMLElement;

console.log("a", a.innerText)
var b = a.innerText.replace(/ +/g,"");
console.log("b", b)
console.log('a', a.innerText);
var b = a.innerText.replace(/ +/g, '');
console.log('b', b);
//To find the right Payload.
var payloadval: any;
for (var i = 0; i < this.BT.length; i++){
var c = this.BT[i].title.title.replace(/(\r\n|\n|\r)/gm,"");
console.log("c",c)
if (c.includes(b)){
for (var i = 0; i < this.BT.length; i++) {
var c = this.BT[i].title.title.replace(/(\r\n|\n|\r)/gm, '');
console.log('c', c);
if (c.includes(b)) {
payloadval = this.BT[i].title.payload;
console.log("payloadval", payloadval);
console.log('payloadval', payloadval);
}
}
console.log("payloadval",payloadval);


console.log('payloadval', payloadval);

//return empty strings
if (a.innerText.trim() === '') return;

//console.log('mydiv', this.mydiv);
console.log('mydiv', this.mydiv);

for (var i = 0; i < this.messages.length; i++)
if (this.messages[i].buttons === true) this.messages[i].buttons = false;
Expand Down Expand Up @@ -157,6 +161,29 @@ export class ChatWidgetComponent implements OnInit {
});
}

DistinctButtons(Val: any) {
var addonce = false;

for (var i = 0; i < Val.length; i++) {
for (var j = 0; j < this.result.length; j++) {
if (Val[i].title.title == this.result[j].title.title) {
addonce = true;
}
}
this.count++;
if (this.count == 1 && addonce == false) {
this.result.push(Val[i]);
}
addonce = false;
this.count = 0;
}
Val = this.result;
this.result = [];
this.BT = [];
this.BT = Val;
Val = '';
}

toggleChat() {
console.log('Toggle chat');
this.visible = !this.visible;
Expand Down
3 changes: 2 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</head>
<body style = "background-color: burlywood;">

<app-root></app-root>
<app-root></app-root>

</body>
</html>

0 comments on commit 8599c62

Please sign in to comment.