NumbersComponent did not update on Push + subscription cleanup + code clean
This commit is contained in:
parent
6eb7165bf1
commit
5987330089
@ -17,7 +17,7 @@ export class Group extends GroupUuid {
|
||||
super(uuid);
|
||||
}
|
||||
|
||||
isOwner(user: UserPublic) {
|
||||
isOwner(user: UserPublic): boolean {
|
||||
return this.owner.publicUuid === user.publicUuid;
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ export class Group extends GroupUuid {
|
||||
);
|
||||
}
|
||||
|
||||
usersByNameOwnerFirst() {
|
||||
usersByNameOwnerFirst(): UserPublic[] {
|
||||
return this.users.sort((a, b) => this.compareOwnerFirstThenName(a, b));
|
||||
}
|
||||
|
||||
@ -50,17 +50,21 @@ export class Group extends GroupUuid {
|
||||
return a.created.getTime() - b.created.getTime();
|
||||
}
|
||||
|
||||
isOwnedBy(user: UserPublic | UserPrivate | null) {
|
||||
isOwnedBy(user: UserPublic | UserPrivate | null): boolean {
|
||||
return user !== null && user.is(this.owner);
|
||||
}
|
||||
|
||||
bannedByName() {
|
||||
bannedByName(): UserPublic[] {
|
||||
return this.banned.sort(UserPublic.compareName);
|
||||
}
|
||||
|
||||
hasUser(user: UserPublic) {
|
||||
hasUser(user: UserPublic): boolean {
|
||||
return this.users.some(u => u.is(user));
|
||||
}
|
||||
|
||||
equals(group: Group | null): boolean {
|
||||
return this.uuid === group?.uuid;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -27,4 +27,8 @@ export class Numbers {
|
||||
return this.lots.filter(u => u.user.is(user))[0];
|
||||
}
|
||||
|
||||
sameGroup(numbers: Numbers): boolean {
|
||||
return this.group.equals(numbers.group);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -24,12 +24,12 @@ import {Subscription, timer} from "rxjs";
|
||||
})
|
||||
export class NumbersComponent implements OnInit, OnDestroy {
|
||||
|
||||
private readonly subs: Subscription[] = [];
|
||||
|
||||
protected numbers: Numbers | null = null;
|
||||
|
||||
protected now: Date = new Date();
|
||||
|
||||
private timer?: Subscription;
|
||||
|
||||
constructor(
|
||||
protected readonly activatedRoute: ActivatedRoute,
|
||||
protected readonly numbersService: NumbersService,
|
||||
@ -40,8 +40,8 @@ export class NumbersComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.timer = timer(1000, 1000).subscribe(() => this.now = new Date());
|
||||
this.activatedRoute.params.subscribe(params => {
|
||||
this.subs.push(timer(1000, 1000).subscribe(() => this.now = new Date()));
|
||||
this.subs.push(this.activatedRoute.params.subscribe(params => {
|
||||
const uuid = params['uuid'];
|
||||
if (uuid) {
|
||||
this.numbersService.canAccess(uuid, granted => {
|
||||
@ -54,14 +54,17 @@ export class NumbersComponent implements OnInit, OnDestroy {
|
||||
} else {
|
||||
this.numbers = null;
|
||||
}
|
||||
}));
|
||||
this.userService.subscribePush(Numbers, numbers => {
|
||||
if (this.numbers?.sameGroup(numbers)) {
|
||||
this.numbers = numbers;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if (this.timer) {
|
||||
this.timer.unsubscribe();
|
||||
this.timer = undefined;
|
||||
}
|
||||
this.subs.forEach(sub => sub.unsubscribe());
|
||||
this.subs.length = 0;
|
||||
}
|
||||
|
||||
@HostListener('window:keydown.escape')
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
import {Component, Inject, LOCALE_ID, OnInit} from '@angular/core';
|
||||
import {Component, Inject, LOCALE_ID, OnDestroy, OnInit} from '@angular/core';
|
||||
import {BODIES, BODIES_PRINT, EARTH, EARTH_MOON, JUPITER, JUPITER_SCALED_DIAMETER, SUN} from "../SOLAR_SYSTEM";
|
||||
import {ActivatedRoute, Params} from "@angular/router";
|
||||
import {DecimalPipe, NgForOf, NgIf} from "@angular/common";
|
||||
import {MIO_KILO, SolarSystemBody} from "../SolarSystemBody";
|
||||
import {Unit} from "../../../../Unit";
|
||||
import {Subscription} from "rxjs";
|
||||
|
||||
function getScale(params: Params) {
|
||||
if ('scale' in params) {
|
||||
@ -37,10 +38,12 @@ export function makePaler(hexColor: string, factor: number): string {
|
||||
templateUrl: './solar-system-printout.component.html',
|
||||
styleUrl: './solar-system-printout.component.less'
|
||||
})
|
||||
export class SolarSystemPrintoutComponent implements OnInit {
|
||||
export class SolarSystemPrintoutComponent implements OnInit, OnDestroy {
|
||||
|
||||
public readonly PRINTABLE_ONLY: boolean = true;
|
||||
|
||||
private readonly subs: Subscription[] = [];
|
||||
|
||||
protected readonly makePaler = makePaler;
|
||||
|
||||
protected readonly BODIES_PRINT = BODIES_PRINT;
|
||||
@ -64,10 +67,15 @@ export class SolarSystemPrintoutComponent implements OnInit {
|
||||
|
||||
ngOnInit(): void {
|
||||
JUPITER.scaledDiameter = JUPITER_SCALED_DIAMETER;
|
||||
this.activatedRoute.params.subscribe(params => {
|
||||
this.subs.push(this.activatedRoute.params.subscribe(params => {
|
||||
const scale = getScale(params);
|
||||
BODIES.forEach(b => b.scale(scale));
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.subs.forEach(sub => sub.unsubscribe());
|
||||
this.subs.length = 0;
|
||||
}
|
||||
|
||||
fontSize(body: SolarSystemBody): string {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {Component, OnDestroy, OnInit} from '@angular/core';
|
||||
import {NgForOf, NgIf} from "@angular/common";
|
||||
import {ActivatedRoute} from "@angular/router";
|
||||
import {GroupListComponent} from "../group/shared/group-list/group-list.component";
|
||||
@ -8,6 +8,7 @@ import {Group} from "../../api/group/Group";
|
||||
import {UserPublic} from "../../api/User/UserPublic";
|
||||
import {ReactiveFormsModule} from "@angular/forms";
|
||||
import {TextComponent} from "../../shared/text/text.component";
|
||||
import {Subscription} from "rxjs";
|
||||
|
||||
@Component({
|
||||
selector: 'app-user',
|
||||
@ -22,7 +23,9 @@ import {TextComponent} from "../../shared/text/text.component";
|
||||
templateUrl: './user.component.html',
|
||||
styleUrl: './user.component.less'
|
||||
})
|
||||
export class UserComponent implements OnInit {
|
||||
export class UserComponent implements OnInit, OnDestroy {
|
||||
|
||||
private readonly subs: Subscription[] = [];
|
||||
|
||||
protected user: UserPublic | null = null;
|
||||
|
||||
@ -37,13 +40,18 @@ export class UserComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.activatedRoute.params.subscribe(params => {
|
||||
this.subs.push(this.activatedRoute.params.subscribe(params => {
|
||||
const publicUuid = params['publicUuid'];
|
||||
if (publicUuid) {
|
||||
this.userService.getByPublicUuid(publicUuid, user => this.user = user);
|
||||
this.groupService.findAllCommon(publicUuid, commonGroups => this.commonGroups = commonGroups);
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.subs.forEach(sub => sub.unsubscribe());
|
||||
this.subs.length = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user