Skip to content

Commit

Permalink
fix review list
Browse files Browse the repository at this point in the history
  • Loading branch information
hit25082000 committed Nov 1, 2024
1 parent 0360a5a commit dcca586
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/app/auth/services/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inject, Injectable } from '@angular/core';
import { Auth, signInWithEmailAndPassword, createUserWithEmailAndPassword, signOut, user } from '@angular/fire/auth';
import { inject, Injectable, signal } from '@angular/core';
import { Auth, signInWithEmailAndPassword, createUserWithEmailAndPassword, signOut, user, User } from '@angular/fire/auth';
import { BehaviorSubject, Observable, map } from 'rxjs';

@Injectable({
Expand All @@ -11,10 +11,15 @@ export class AuthService {
isAdmin$ = this.isAdminSubject.asObservable();
user$ = user(this.auth);
isLoggedIn$: Observable<boolean>;
currentUser = signal<User | undefined>(undefined)

constructor() {
this.isLoggedIn$ = this.user$.pipe(map(user => !!user));
this.user$.subscribe(user => this.checkAdminStatus(user?.email));

this.user$.subscribe((user)=>{
this.currentUser.set(user ?? undefined)
})
}

async login(email: string, password: string): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import { TimestampToDatePipe } from '../../pipes/timestamp-to-date.pipe';
<div class="reviews-list">
<div class="review-item" *ngFor="let review of reviews$ | async">
<div class="review-header">
<span class="user-name">{{ review.userName }}</span>
<span class="stars">
<div class="user-name">{{ review.userName }}</div>
<div class="stars">
<span *ngFor="let star of [1,2,3,4,5]"
[class.active]="star <= review.rating">⭐</span>
</span>
</div>
<span class="review-date">{{ review.createdAt | timestampToDate | date:'dd/MM/yyyy' }}</span>
</div>
<p class="comment">{{ review.comment }}</p>
Expand Down Expand Up @@ -66,9 +66,9 @@ import { TimestampToDatePipe } from '../../pipes/timestamp-to-date.pipe';
}
.review-header {
display: flex;
align-items: center;
gap: 15px;
margin-bottom: 10px;
flex-direction: column;
}
.user-name {
font-weight: bold;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class ReviewModalComponent {

const review = {
userId: user.uid,
userName: user.displayName || 'Anônimo',
userName: user.email || 'Anônimo',
gameId: this.modalGameId(),
rating: this.reviewForm().value.rating,
comment: this.reviewForm().value.comment,
Expand Down

0 comments on commit dcca586

Please sign in to comment.