migrate angular 21 finalize
This commit is contained in:
@@ -1,18 +1,16 @@
|
||||
import {Directive, ElementRef, Input, OnInit, TemplateRef, ViewContainerRef} from '@angular/core';
|
||||
import {Directive, ElementRef, Input, OnInit, TemplateRef, ViewContainerRef, inject} from '@angular/core';
|
||||
import {UserService} from './user.service';
|
||||
|
||||
@Directive({selector: '[appOwner]'})
|
||||
export class OwnerDirective implements OnInit {
|
||||
private element = inject(ElementRef);
|
||||
private templateRef = inject<TemplateRef<unknown>>(TemplateRef);
|
||||
private viewContainer = inject(ViewContainerRef);
|
||||
private userService = inject(UserService);
|
||||
|
||||
private currentUserId: string | null = null;
|
||||
private iAppOwner: string | null = null;
|
||||
|
||||
public constructor(
|
||||
private element: ElementRef,
|
||||
private templateRef: TemplateRef<unknown>,
|
||||
private viewContainer: ViewContainerRef,
|
||||
private userService: UserService
|
||||
) {}
|
||||
|
||||
@Input()
|
||||
public set appOwner(value: string) {
|
||||
this.iAppOwner = value;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {ChangeDetectorRef, Directive, ElementRef, Input, OnInit, TemplateRef, ViewContainerRef} from '@angular/core';
|
||||
import {ChangeDetectorRef, Directive, ElementRef, Input, OnInit, TemplateRef, ViewContainerRef, inject} from '@angular/core';
|
||||
import {roles} from './roles';
|
||||
import {UserService} from './user.service';
|
||||
import {User} from './user';
|
||||
@@ -6,19 +6,17 @@ import {combineLatest} from 'rxjs';
|
||||
|
||||
@Directive({selector: '[appRole]'})
|
||||
export class RoleDirective implements OnInit {
|
||||
private element = inject(ElementRef);
|
||||
private templateRef = inject<TemplateRef<unknown>>(TemplateRef);
|
||||
private viewContainer = inject(ViewContainerRef);
|
||||
private userService = inject(UserService);
|
||||
private changeDetection = inject(ChangeDetectorRef);
|
||||
|
||||
@Input() public appRole: roles[] = [];
|
||||
private currentUser: User | null = null;
|
||||
private loggedIn = false;
|
||||
private currentViewState = false;
|
||||
|
||||
public constructor(
|
||||
private element: ElementRef,
|
||||
private templateRef: TemplateRef<unknown>,
|
||||
private viewContainer: ViewContainerRef,
|
||||
private userService: UserService,
|
||||
private changeDetection: ChangeDetectorRef
|
||||
) {}
|
||||
|
||||
public ngOnInit(): void {
|
||||
combineLatest([this.userService.user$, this.userService.loggedIn$()]).subscribe(_ => {
|
||||
this.currentUser = _[0];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Component, Input} from '@angular/core';
|
||||
import {Component, Input, inject} from '@angular/core';
|
||||
import {UserService} from '../user.service';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {Observable} from 'rxjs';
|
||||
@@ -11,9 +11,9 @@ import {AsyncPipe} from '@angular/common';
|
||||
imports: [AsyncPipe],
|
||||
})
|
||||
export class UserNameComponent {
|
||||
public name$: Observable<string | null> | null = null;
|
||||
private userService = inject(UserService);
|
||||
|
||||
public constructor(private userService: UserService) {}
|
||||
public name$: Observable<string | null> | null = null;
|
||||
|
||||
@Input()
|
||||
public set userId(id: string) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Injectable, inject} from '@angular/core';
|
||||
import {Auth, authState, createUserWithEmailAndPassword, sendPasswordResetEmail, signInWithEmailAndPassword, signOut} from '@angular/fire/auth';
|
||||
import {BehaviorSubject, firstValueFrom, Observable} from 'rxjs';
|
||||
import {filter, map, shareReplay, switchMap, take, tap} from 'rxjs/operators';
|
||||
@@ -20,18 +20,18 @@ export interface SongUsageMigrationResult {
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class UserService {
|
||||
private auth = inject(Auth);
|
||||
private db = inject(DbService);
|
||||
private router = inject(Router);
|
||||
private showDataService = inject(ShowDataService);
|
||||
private showSongDataService = inject(ShowSongDataService);
|
||||
|
||||
public users$ = this.db.col$<User>('users').pipe(shareReplay({bufferSize: 1, refCount: true}));
|
||||
private iUserId$ = new BehaviorSubject<string | null>(null);
|
||||
private iUser$ = new BehaviorSubject<User | null>(null);
|
||||
private userByIdCache = new Map<string, Observable<User | null>>();
|
||||
|
||||
public constructor(
|
||||
private auth: Auth,
|
||||
private db: DbService,
|
||||
private router: Router,
|
||||
private showDataService: ShowDataService,
|
||||
private showSongDataService: ShowSongDataService
|
||||
) {
|
||||
public constructor() {
|
||||
authState(this.auth)
|
||||
.pipe(
|
||||
filter(auth => !!auth),
|
||||
|
||||
Reference in New Issue
Block a user