From b8b50ca55a87063beccb3110c084551e4005c55c Mon Sep 17 00:00:00 2001 From: Roger Far Date: Sat, 9 Oct 2021 20:24:19 -0600 Subject: [PATCH] Fixed bug in the Signalr service where it would stop updating when moving away from the index page. --- .../src/app/torrent-table/torrent-table.component.ts | 10 ++-------- client/src/app/torrent.service.ts | 10 ++++------ client/src/app/torrent/torrent.component.ts | 2 -- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/client/src/app/torrent-table/torrent-table.component.ts b/client/src/app/torrent-table/torrent-table.component.ts index 6a5a8c9..454220d 100644 --- a/client/src/app/torrent-table/torrent-table.component.ts +++ b/client/src/app/torrent-table/torrent-table.component.ts @@ -1,4 +1,4 @@ -import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { Torrent } from '../models/torrent.model'; import { TorrentService } from '../torrent.service'; @@ -8,7 +8,7 @@ import { TorrentService } from '../torrent.service'; templateUrl: './torrent-table.component.html', styleUrls: ['./torrent-table.component.scss'], }) -export class TorrentTableComponent implements OnInit, OnDestroy { +export class TorrentTableComponent implements OnInit { public torrents: Torrent[] = []; public error: string; @@ -19,8 +19,6 @@ export class TorrentTableComponent implements OnInit, OnDestroy { (result) => { this.torrents = result; - this.torrentService.connect(); - this.torrentService.update$.subscribe((result2) => { this.torrents = result2; }); @@ -31,10 +29,6 @@ export class TorrentTableComponent implements OnInit, OnDestroy { ); } - ngOnDestroy(): void { - this.torrentService.disconnect(); - } - public selectTorrent(torrentId: string): void { this.router.navigate([`/torrent/${torrentId}`]); } diff --git a/client/src/app/torrent.service.ts b/client/src/app/torrent.service.ts index 4b8f22b..0c883e0 100644 --- a/client/src/app/torrent.service.ts +++ b/client/src/app/torrent.service.ts @@ -8,12 +8,14 @@ import { Torrent, TorrentFileAvailability } from './models/torrent.model'; providedIn: 'root', }) export class TorrentService { - constructor(private http: HttpClient) {} - public update$: Subject = new Subject(); private connection: signalR.HubConnection; + constructor(private http: HttpClient) { + this.connect(); + } + public connect(): void { if (this.connection != null) { return; @@ -27,10 +29,6 @@ export class TorrentService { }); } - public disconnect(): void { - this.connection?.stop(); - } - public getList(): Observable { return this.http.get(`/Api/Torrents`); } diff --git a/client/src/app/torrent/torrent.component.ts b/client/src/app/torrent/torrent.component.ts index 9e276a0..9d304a8 100644 --- a/client/src/app/torrent/torrent.component.ts +++ b/client/src/app/torrent/torrent.component.ts @@ -44,8 +44,6 @@ export class TorrentComponent implements OnInit { (torrent) => { this.torrent = torrent; - this.torrentService.connect(); - this.torrentService.update$.subscribe((result) => { this.update(result); });