Fixed profile navigation #255
This commit is contained in:
parent
24d5bbf4d8
commit
e6c614dfdc
@ -1,4 +1,4 @@
|
|||||||
import { Component, OnInit } from "@angular/core";
|
import { Component, OnDestroy, OnInit } from "@angular/core";
|
||||||
import { ActivatedRoute, Router } from "@angular/router";
|
import { ActivatedRoute, Router } from "@angular/router";
|
||||||
import { Queries } from "../../../../models/graphql/queries.model";
|
import { Queries } from "../../../../models/graphql/queries.model";
|
||||||
import { UserListQuery } from "../../../../models/graphql/query.model";
|
import { UserListQuery } from "../../../../models/graphql/query.model";
|
||||||
@ -10,17 +10,21 @@ import { AuthService } from "src/app/services/auth/auth.service";
|
|||||||
import { ToastService } from "src/app/services/toast/toast.service";
|
import { ToastService } from "src/app/services/toast/toast.service";
|
||||||
import { TranslateService } from "@ngx-translate/core";
|
import { TranslateService } from "@ngx-translate/core";
|
||||||
import { Server } from "../../../../models/data/server.model";
|
import { Server } from "../../../../models/data/server.model";
|
||||||
|
import { Subject } from "rxjs";
|
||||||
|
import { takeUntil } from "rxjs/operators";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "app-profile",
|
selector: "app-profile",
|
||||||
templateUrl: "./profile.component.html",
|
templateUrl: "./profile.component.html",
|
||||||
styleUrls: ["./profile.component.scss"]
|
styleUrls: ["./profile.component.scss"]
|
||||||
})
|
})
|
||||||
export class ProfileComponent implements OnInit {
|
export class ProfileComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
user: User = { createdAt: "", modifiedAt: "" };
|
user: User = { createdAt: "", modifiedAt: "" };
|
||||||
private server: Server = {};
|
private server: Server = {};
|
||||||
|
|
||||||
|
private unsubscriber = new Subject<void>();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
@ -32,10 +36,11 @@ export class ProfileComponent implements OnInit {
|
|||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
public ngOnInit(): void {
|
||||||
|
this.route.params.pipe(takeUntil(this.unsubscriber)).subscribe(params => {
|
||||||
this.data.getServerFromRoute(this.route).then(async (server) => {
|
this.data.getServerFromRoute(this.route).then(async (server) => {
|
||||||
if (!this.route.snapshot.params["memberId"] || this.route.snapshot.params["memberId"] == "undefined") {
|
if (!params["memberId"] || params["memberId"] == "undefined") {
|
||||||
this.router.navigate([`/server/${server.id}`]);
|
await this.router.navigate([`/server/${server.id}`]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.server = server;
|
this.server = server;
|
||||||
@ -43,17 +48,17 @@ export class ProfileComponent implements OnInit {
|
|||||||
let authUser = await this.auth.getLoggedInUser();
|
let authUser = await this.auth.getLoggedInUser();
|
||||||
this.spinner.showSpinner();
|
this.spinner.showSpinner();
|
||||||
let user: UserDTO | null = authUser?.users?.find(u => u.server == server.id) ?? null;
|
let user: UserDTO | null = authUser?.users?.find(u => u.server == server.id) ?? null;
|
||||||
if (!user || user?.id != this.route.snapshot.params["memberId"] && !user?.isModerator) {
|
if (!user || user?.id != params["memberId"] && !user?.isModerator) {
|
||||||
this.toast.error(this.translate.instant("view.server.profile.permission_denied"), this.translate.instant("view.server.profile.permission_denied_d"));
|
this.toast.error(this.translate.instant("view.server.profile.permission_denied"), this.translate.instant("view.server.profile.permission_denied_d"));
|
||||||
this.spinner.hideSpinner();
|
this.spinner.hideSpinner();
|
||||||
this.router.navigate(["/server", server.id]);
|
await this.router.navigate(["/server", server.id]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.data.query<UserListQuery>(Queries.usersQuery, {
|
this.data.query<UserListQuery>(Queries.usersQuery, {
|
||||||
serverId: this.server.id,
|
serverId: this.server.id,
|
||||||
filter: {
|
filter: {
|
||||||
id: this.route.snapshot.params["memberId"]
|
id: params["memberId"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(x: { servers: Server[] }) => {
|
(x: { servers: Server[] }) => {
|
||||||
@ -67,7 +72,11 @@ export class ProfileComponent implements OnInit {
|
|||||||
this.spinner.hideSpinner();
|
this.spinner.hideSpinner();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public ngOnDestroy(): void {
|
||||||
|
this.unsubscriber.next();
|
||||||
|
this.unsubscriber.complete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user