hide show subscribe buttons

This commit is contained in:
chsakell
2016-10-03 15:03:46 +03:00
parent f23e285a9f
commit 4dc031cf8b
4 changed files with 20 additions and 5 deletions

View File

@@ -19,13 +19,16 @@
<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()"> <button type="button" class="btn btn-default btn-md" (click)="subscribe()" *ngIf="!subscribed">
Subscribe to feed Subscribe to feed
</button> </button>
<button type="button" class="btn btn-danger btn-md" (click)="unsubscribe()" *ngIf="subscribed">
Unubscribe
</button>
</td> </td>
</tr> </tr>
<tr> <tr *ngIf="subscribed">
<td><button type="button" class="btn btn-default btn-xs">Send</button></td> <td><button type="button" class="btn btn-default btn-md">Send</button></td>
<td><input type="text" class="form-control" placeholder="Type message.." /></td> <td><input type="text" class="form-control" placeholder="Type message.." /></td>
</tr> </tr>
<tr> <tr>

View File

@@ -10,6 +10,7 @@ import { FeedService } from '../services/feed.service';
export class MatchComponent implements OnInit { export class MatchComponent implements OnInit {
@Input() match: Match; @Input() match: Match;
subscribed: boolean;
constructor(private feedService: FeedService) { } constructor(private feedService: FeedService) { }
@@ -17,6 +18,12 @@ export class MatchComponent implements OnInit {
subscribe() { subscribe() {
console.log(this.match.Id); console.log(this.match.Id);
this.subscribed = true;
this.feedService.subscribeToFeed(this.match.Id); this.feedService.subscribeToFeed(this.match.Id);
} }
unsubscribe() {
this.subscribed = false;
this.feedService.unsubscribeToFeed(this.match.Id);
}
} }

View File

@@ -11,14 +11,15 @@ export interface FeedProxy {
export interface FeedClient { export interface FeedClient {
userConnected: (user: any) => void; userConnected: (user: any) => void;
userDisconnected: (id: string) => void; userDisconnected: (id: string) => void;
updateMatch: (match: Match) => void; updateMatch: (match: Match) => void;
addFeed: (feed: Feed) => void; addFeed: (feed: Feed) => void;
messageReceived: (message: string) => void; messageReceived: (message: string) => void;
} }
export interface FeedServer { export interface FeedServer {
subscribe(matchId: number) : void; subscribe(matchId: number): void;
unsubscribe(matchId: number): void;
} }
export enum ConnectionState { export enum ConnectionState {

View File

@@ -121,4 +121,8 @@ export class FeedService {
public subscribeToFeed(matchId: number) { public subscribeToFeed(matchId: number) {
this.server.subscribe(matchId); this.server.subscribe(matchId);
} }
public unsubscribeToFeed(matchId: number) {
this.server.unsubscribe(matchId);
}
} }