From 7358b67072e8f147c7eb695ff08de632f5e2bebf Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 7 Nov 2023 00:06:17 +0100 Subject: [PATCH] Fixed server loading in web --- web/src/app/models/graphql/queries.model.ts | 13 ++++++++++ .../server-dashboard.component.html | 2 +- .../server-dashboard.component.ts | 24 +++++++++++++++++-- web/src/app/services/data/data.service.ts | 13 +++++++++- 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/web/src/app/models/graphql/queries.model.ts b/web/src/app/models/graphql/queries.model.ts index 9b8e8059..09e582d5 100644 --- a/web/src/app/models/graphql/queries.model.ts +++ b/web/src/app/models/graphql/queries.model.ts @@ -62,6 +62,19 @@ export class Queries { static serversQuery = ` query ServerInfo($filter: ServerFilter, $page: Page, $sort: Sort) { serverCount + servers(filter: $filter, page: $page, sort: $sort) { + id + discordId + name + iconURL + userCount + activeUserCount + } + } + `; + + static serversDashboardQuery = ` + query DetailedServerInfo($filter: ServerFilter, $page: Page, $sort: Sort) { servers(filter: $filter, page: $page, sort: $sort) { id discordId diff --git a/web/src/app/modules/view/server/server-dashboard/server-dashboard.component.html b/web/src/app/modules/view/server/server-dashboard/server-dashboard.component.html index dfd2c275..3038c077 100644 --- a/web/src/app/modules/view/server/server-dashboard/server-dashboard.component.html +++ b/web/src/app/modules/view/server/server-dashboard/server-dashboard.component.html @@ -12,7 +12,7 @@
-
+
diff --git a/web/src/app/modules/view/server/server-dashboard/server-dashboard.component.ts b/web/src/app/modules/view/server/server-dashboard/server-dashboard.component.ts index 04edbb08..90f2cb4b 100644 --- a/web/src/app/modules/view/server/server-dashboard/server-dashboard.component.ts +++ b/web/src/app/modules/view/server/server-dashboard/server-dashboard.component.ts @@ -5,6 +5,10 @@ import { DataService } from "src/app/services/data/data.service"; import { SpinnerService } from "src/app/services/spinner/spinner.service"; import { SidebarService } from "../../../../services/sidebar/sidebar.service"; import { ServerService } from "../../../../services/server.service"; +import { Query } from "../../../../models/graphql/query.model"; +import { Queries } from "../../../../models/graphql/queries.model"; +import { catchError } from "rxjs/operators"; +import { throwError } from "rxjs"; @Component({ selector: "app-server-dashboard", @@ -27,14 +31,30 @@ export class ServerDashboardComponent implements OnInit { ngOnInit(): void { this.data.getServerFromRoute(this.route).then(server => { - this.server = server; + // this.server = server; + + this.loadServer(server.id); }); this.serverService.server$.subscribe(server => { if (!server) { return; } - this.server = server; + this.loadServer(server.id); + }); + } + + loadServer(id?: number): void { + this.data.query(Queries.serversDashboardQuery, { + filter: { + id: id + } + }).pipe(catchError(err => { + this.spinner.hideSpinner(); + return throwError(() => err); + })).subscribe(data => { + this.server = data.servers[0]; + this.spinner.hideSpinner(); }); } diff --git a/web/src/app/services/data/data.service.ts b/web/src/app/services/data/data.service.ts index 99d09b83..336eb22d 100644 --- a/web/src/app/services/data/data.service.ts +++ b/web/src/app/services/data/data.service.ts @@ -29,6 +29,18 @@ export class DataService { ) { } + public getServerIdFromRoute(route: ActivatedRoute): Promise { + return new Promise((resolve, reject) => { + this.spinner.showSpinner(); + if (!route.snapshot.params["serverId"] || route.snapshot.params["serverId"] == "undefined") { + this.spinner.hideSpinner(); + this.router.navigate(["/dashboard"]); + reject(); + } + resolve(route.snapshot.params["serverId"]); + }); + } + public getServerFromRoute(route: ActivatedRoute): Promise { return new Promise((resolve, reject) => { this.spinner.showSpinner(); @@ -50,7 +62,6 @@ export class DataService { resolve(server); }); }); - } public query(query: string, variables?: Variables, f?: Function): Observable {