mirror of
https://github.com/chsakell/aspnet-core-signalr-angular.git
synced 2025-12-22 17:27:48 +00:00
move feed service from match component
This commit is contained in:
@@ -60,7 +60,7 @@ namespace LiveGameFeed.Core
|
|||||||
FeedViewModel _feed = new FeedViewModel()
|
FeedViewModel _feed = new FeedViewModel()
|
||||||
{
|
{
|
||||||
MatchId = match.Id,
|
MatchId = match.Id,
|
||||||
Description = points + " points for " + (updateHost == true ? match.Host : match.Guest + "!"),
|
Description = points + " points for " + (updateHost == true ? match.Host : match.Guest) + "!",
|
||||||
CreatedAt = DateTime.Now
|
CreatedAt = DateTime.Now
|
||||||
};
|
};
|
||||||
using (var client = new HttpClient())
|
using (var client = new HttpClient())
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4" *ngFor="let match of matches">
|
<div class="col-md-4" *ngFor="let match of matches">
|
||||||
<match [match]="match"></match>
|
<match [match]="match" (updateSubscription)="updateSubscription($event)"></match>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<chat [matches]="matches"></chat>
|
<chat [matches]="matches"></chat>
|
||||||
|
|||||||
@@ -73,4 +73,11 @@ export class HomeComponent implements OnInit {
|
|||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateSubscription(subscription: any) {
|
||||||
|
if(<boolean>subscription.subscribe === true)
|
||||||
|
this.feedService.subscribeToFeed(<number>subscription.matchId);
|
||||||
|
else
|
||||||
|
this.feedService.unsubscribeFromFeed(<number>subscription.matchId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -19,10 +19,10 @@
|
|||||||
<span class="label label-success">{{match.Type}}</span>
|
<span class="label label-success">{{match.Type}}</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<button type="button" class="btn btn-default btn-md" (click)="subscribe()" *ngIf="!subscribed">
|
<button type="button" class="btn btn-default btn-md" (click)="setSubscription(true)" *ngIf="!subscribed">
|
||||||
Subscribe to feed
|
Subscribe to feed
|
||||||
</button>
|
</button>
|
||||||
<button type="button" class="btn btn-danger btn-md" (click)="unsubscribe()" *ngIf="subscribed">
|
<button type="button" class="btn btn-danger btn-md" (click)="unsubscribe(false)" *ngIf="subscribed">
|
||||||
Unubscribe
|
Unubscribe
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Component, OnInit, Input } from '@angular/core';
|
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
||||||
|
|
||||||
import { ChatMessage, Match } from '../interfaces';
|
import { ChatMessage, Match } from '../interfaces';
|
||||||
import { FeedService } from '../services/feed.service';
|
import { FeedService } from '../services/feed.service';
|
||||||
@@ -11,32 +11,43 @@ import { DataService } from '../services/data.service';
|
|||||||
export class MatchComponent implements OnInit {
|
export class MatchComponent implements OnInit {
|
||||||
|
|
||||||
@Input() match: Match;
|
@Input() match: Match;
|
||||||
|
@Output() updateSubscription = new EventEmitter();
|
||||||
subscribed: boolean;
|
subscribed: boolean;
|
||||||
chatMessage: string = '';
|
chatMessage: string = '';
|
||||||
|
|
||||||
constructor(private feedService: FeedService,
|
constructor(private dataService: DataService) { }
|
||||||
private dataService: DataService) { }
|
|
||||||
|
|
||||||
ngOnInit() { }
|
ngOnInit() { }
|
||||||
|
|
||||||
subscribe() {
|
subscribe() {
|
||||||
console.log(this.match.Id);
|
console.log(this.match.Id);
|
||||||
this.subscribed = true;
|
this.subscribed = true;
|
||||||
this.feedService.subscribeToFeed(this.match.Id);
|
//this.feedService.subscribeToFeed(this.match.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsubscribe() {
|
unsubscribe() {
|
||||||
this.subscribed = false;
|
this.subscribed = false;
|
||||||
this.feedService.unsubscribeToFeed(this.match.Id);
|
//this.feedService.unsubscribeToFeed(this.match.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSubscription(val: boolean) {
|
||||||
|
this.subscribed = val;
|
||||||
|
let subscription =
|
||||||
|
{
|
||||||
|
subscribe: val,
|
||||||
|
matchId: this.match.Id
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateSubscription.emit(subscription);
|
||||||
}
|
}
|
||||||
|
|
||||||
addChatMessage() {
|
addChatMessage() {
|
||||||
let self = this;
|
let self = this;
|
||||||
let messageToSend: ChatMessage = {
|
let messageToSend: ChatMessage = {
|
||||||
MatchId : self.match.Id,
|
MatchId: self.match.Id,
|
||||||
Text : self.chatMessage,
|
Text: self.chatMessage,
|
||||||
CreatedAt : new Date(Date.now())
|
CreatedAt: new Date(Date.now())
|
||||||
};
|
};
|
||||||
|
|
||||||
this.dataService.addChatMessage(messageToSend)
|
this.dataService.addChatMessage(messageToSend)
|
||||||
.subscribe(() => {
|
.subscribe(() => {
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ export class FeedService {
|
|||||||
this.server.subscribe(matchId);
|
this.server.subscribe(matchId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsubscribeToFeed(matchId: number) {
|
public unsubscribeFromFeed(matchId: number) {
|
||||||
this.server.unsubscribe(matchId);
|
this.server.unsubscribe(matchId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user