Skip to content

Commit

Permalink
ui: refactor input components
Browse files Browse the repository at this point in the history
  • Loading branch information
George-Spanos committed Mar 29, 2024
1 parent 0e5e84a commit 82793f4
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 70 deletions.
6 changes: 3 additions & 3 deletions src/ui/src/app/round/poker-table/board/board.component.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Component, Input } from '@angular/core';
import { Component, input } from '@angular/core';
import { Board } from '@moby-it/poker-core';
import { CardComponent } from '../card/card.component';

@Component({
selector: 'ppo-board',
imports: [CardComponent],
template: `
@for (card of board; track card) {
@for (card of board(); track card) {
<ppo-card [card]="card"></ppo-card>
}
`,
standalone: true
})
export class BoardComponent {
@Input() board!: Board;
board = input<Board>();
}
12 changes: 6 additions & 6 deletions src/ui/src/app/round/poker-table/card/card.component.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Component, Input } from '@angular/core';
import { Card } from '@moby-it/poker-core';
import { Component, input } from '@angular/core';
import { fadeAnimation } from '@app/shared/ui/animations/fadeIn';
import { Card } from '@moby-it/poker-core';
@Component({
selector: 'ppo-card',
template: `
@if (back) {
@if (back()) {
<img src="/assets/cards/card_hidden.svg" @fade alt="" srcset="" />
} @else {
<img src="/assets/cards/{{ card }}.svg" @fade alt="" srcset="" />
<img src="/assets/cards/{{ card() }}.svg" @fade alt="" srcset="" />
}
`,
animations: [fadeAnimation],
standalone: true
})
export class CardComponent {
@Input() back = false;
@Input() card: Card | undefined;
back = input(false);
card = input<Card>();
cardLink = '/assets/svg-cards.svg#';
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Component, Input } from '@angular/core';
import { Component, input } from '@angular/core';
import { Card } from '@moby-it/poker-core';
import { CardComponent } from '../card/card.component';

@Component({
selector: 'ppo-opponent-hand',
imports: [CardComponent],
template: `
@if (isVisible) {
@if (isVisible()) {
<div class="opponent-hand">
@for (card of hand; track card) {
@for (card of hand(); track card) {
<ppo-card [card]="card" class="card"></ppo-card>
}
</div>
} @else {
<div class="opponent-hand">
@for (card of hand; track card) {
@for (card of hand(); track card) {
<ppo-card [back]="true" class="card"></ppo-card>
}
</div>
Expand All @@ -28,6 +28,6 @@ import { CardComponent } from '../card/card.component';
standalone: true
})
export class OpponentHandComponent {
@Input() hand: Card[] = [];
@Input() isVisible = false;
hand = input<Card[]>();
isVisible = input(false);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input } from '@angular/core';
import { Component, input } from '@angular/core';
import { Card } from '@moby-it/poker-core';
import { CardComponent } from '../card/card.component';

Expand All @@ -7,7 +7,7 @@ import { CardComponent } from '../card/card.component';
imports: [CardComponent],
template: `
<div class="player-hand">
@for (card of hand; track card) {
@for (card of hand(); track card) {
<ppo-card [card]="card"></ppo-card>
}
</div>
Expand All @@ -22,5 +22,5 @@ import { CardComponent } from '../card/card.component';
standalone: true
})
export class PlayingHandComponent {
@Input() hand: Card[] = [];
hand = input<Card[]>();
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="poker-table-container">
@if (round) {
<ppo-board class="board" [board]="round.board"></ppo-board>
<ppo-playing-hand [hand]="round.myHand"></ppo-playing-hand>
@for (opponent of round.opponentsHands; track opponent; let i = $index) {
@if (round()) {
<ppo-board class="board" [board]="round()?.board"></ppo-board>
<ppo-playing-hand [hand]="round()?.myHand"></ppo-playing-hand>
@for (opponent of round()?.opponentsHands; track opponent; let i = $index) {
<ppo-opponent-hand
[hand]="opponent"
[isVisible]="opponent | handIsVisible"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Component, Input } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Component, input } from '@angular/core';
import { Round } from '@moby-it/poker-core';
import { BoardComponent } from '../board/board.component';
import { PlayingHandComponent } from '../playing-hand/playing-hand.component';
import { OpponentHandComponent } from '../opponent-hand/opponent-hand.component';
import { HandIsVisiblePipe } from './handIsVisible.pipe';
import { PlayingHandComponent } from '../playing-hand/playing-hand.component';
import { HandBadgeGridPositionPipe } from './handBadgeGridPosition.pipe';
import { CommonModule } from '@angular/common';
import { HandIsVisiblePipe } from './handIsVisible.pipe';

@Component({
selector: 'ppo-poker-table',
Expand All @@ -27,5 +27,5 @@ import { CommonModule } from '@angular/common';
standalone: true
})
export class PokerTableComponent {
@Input() round: Round | null | undefined;
round = input<Round | null | undefined>();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Clipboard } from '@angular/cdk/clipboard';

import { Component, Input } from '@angular/core';
import { Component, Input, input } from '@angular/core';
import { createRouteUrl } from '@app/round/helpers';
import { ToastrService } from 'ngx-toastr';
@Component({
Expand Down Expand Up @@ -40,11 +40,11 @@ import { ToastrService } from 'ngx-toastr';
standalone: true,
})
export class CopyRoundLinkButtonComponent {
@Input() roundId: string | undefined;
constructor(private clipboard: Clipboard, private toaster: ToastrService) {}
roundId = input<string>();
constructor(private clipboard: Clipboard, private toaster: ToastrService) { }
copyToClipboard(): void {
if (this.roundId) {
const url = createRouteUrl(this.roundId);
if (this.roundId()) {
const url = createRouteUrl(this.roundId() as string);
this.clipboard.copy(url);
this.toaster.info('Link copied', '', { timeOut: 2000 });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { Component, Input, signal } from '@angular/core';
import { Component, input, signal } from '@angular/core';
import { PokerOddsStore } from '@app/play/poker-odds.store';
@Component({
selector: 'ppo-add-round-to-favorites-button',
Expand Down Expand Up @@ -33,16 +33,16 @@ import { PokerOddsStore } from '@app/play/poker-odds.store';
})
export class FavoriteButtonComponent {
favoritesFill = signal('transparent');
roundId = input<string>();
constructor(private pokerOdds: PokerOddsStore) { }
@Input() roundId: string | undefined;
saveToFavorites(): void {
if (this.roundId) {
if (this.roundId()) {
if (this.favoritesFill() === 'transparent') {
this.pokerOdds.addRoundToFavorites(this.roundId).subscribe(() => {
this.pokerOdds.addRoundToFavorites(this.roundId() as string).subscribe(() => {
this.favoritesFill.set('white');
});
} else {
this.pokerOdds.removeRoundFromFavorites(this.roundId).subscribe(() => {
this.pokerOdds.removeRoundFromFavorites(this.roundId() as string).subscribe(() => {
this.favoritesFill.set('transparent');
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { Component, Input } from '@angular/core';
import { Router, RouterModule } from '@angular/router';
import { Component, input } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'ppo-play-round-button',
template: `<svg
Expand Down Expand Up @@ -34,11 +34,11 @@ import { Router, RouterModule } from '@angular/router';
standalone: true,
})
export class PlayRoundButtonComponent {
constructor(private router: Router) {}
@Input() roundId: string | undefined;
constructor(private router: Router) { }
roundId = input<string>();
playRound(): void {
if (this.roundId) {
this.router.navigate(['/', 'play', this.roundId]);
if (this.roundId()) {
this.router.navigate(['/', 'play', this.roundId()]);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@if (header && body) {
@if (header() && body()) {
<div class="round-result">
<span class="body-{{ headerClass }} header">{{ header }}</span>
<span class="body body-{{ bodyClass }}" [ngClass]="classes">
{{ body }}
<span class="body-{{ headerClass }} header">{{ header() }}</span>
<span class="body body-{{ bodyClass }}" [ngClass]="classes()">
{{ body() }}
</span>
<ng-content select="[actions]"></ng-content>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import { CommonModule } from '@angular/common';
import { Component, Input, OnInit } from '@angular/core';
import { Component, effect, input } from '@angular/core';

@Component({
selector: 'ppo-round-result',
templateUrl: './round-result.component.html',
standalone: true,
imports: [CommonModule]
})
export class RoundResultComponent implements OnInit {
export class RoundResultComponent {

size = input('md');
header = input();
body = input();
classes = input<string[]>();

headerClass = 'lg';
bodyClass = 'sm';
@Input() size: 'lg' | 'md' = 'md';
@Input() header: string | number | undefined | null;
@Input() body: string | number | undefined | null;
@Input() classes: string[] = [];
ngOnInit(): void {
if (this.size === 'lg') {
this.headerClass = 'xl';
this.bodyClass = 'md';
}
constructor() {
effect(() => {
if (this.size() === 'lg') {
this.headerClass = 'xl';
this.bodyClass = 'md';
}
});
}
}
9 changes: 5 additions & 4 deletions src/ui/src/app/shared/ui/directives/tooltip.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
ElementRef,
EmbeddedViewRef,
HostListener,
Input,
OnDestroy,
ViewContainerRef,
input
} from '@angular/core';
import { TooltipComponent } from '../components/tooltip/tooltip.component';

Expand All @@ -16,8 +16,9 @@ import { TooltipComponent } from '../components/tooltip/tooltip.component';
standalone: true
})
export class TooltipDirective implements OnDestroy {
@Input() ppoTooltip = '';
@Input() fontSize = '22';

ppoTooltip = input('');
fontSize = input('22');
private componentRef: ComponentRef<TooltipComponent> | null = null;
@HostListener('mouseenter')
onMouseEnter(): void {
Expand Down Expand Up @@ -53,7 +54,7 @@ export class TooltipDirective implements OnDestroy {
) { }
private setTooltipComponentProperties(): void {
if (this.componentRef !== null) {
this.componentRef.instance.tooltip = this.ppoTooltip;
this.componentRef.instance.tooltip = this.ppoTooltip();
const { left, right, bottom } =
this.elementRef.nativeElement.getBoundingClientRect();
this.componentRef.instance.left = (right - left) / 2 + left;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</div>
<div
class="row"
*ngFor="let userRound of rounds; trackBy: userRoundTrackBy"
*ngFor="let userRound of rounds(); trackBy: userRoundTrackBy"
(click)="selectRound(userRound)"
[ngClass]="{
selected: selectedRound()?.roundId === userRound.roundId
Expand Down
14 changes: 7 additions & 7 deletions src/ui/src/app/user/ui/round-list/round-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { CommonModule } from '@angular/common';
import {
Component,
DestroyRef,
Input,
OnChanges,
OnInit,
SimpleChanges,
inject,
signal,
input,
signal
} from '@angular/core';
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { ActivatedRoute, Router } from '@angular/router';
Expand All @@ -16,7 +16,7 @@ import { ScoreIsAccuratePipe } from '@app/round/helpers';
import { CopyRoundLinkButtonComponent, PlayRoundButtonComponent, PokerTableComponent, RoundResultComponent } from "@app/round/poker-table";
import { UserRoundViewmodel } from '@app/user/models';
import { UserProfileStore } from '@app/user/user-profile.store';
import { BehaviorSubject, filter, switchMap, take, tap } from 'rxjs';
import { tap } from 'rxjs';
import { SuitToSvgPipe } from './suitToSvg.pipe';
@Component({
selector: 'ppo-round-list',
Expand Down Expand Up @@ -49,19 +49,19 @@ export class RoundListComponent implements OnChanges, OnInit {
) {
this.route.queryParamMap.pipe(takeUntilDestroyed()).subscribe((params) => {
const selectedRoundId = params.get('selectedRoundId');
const selectedRoundIdx = this.rounds.findIndex(
const selectedRoundIdx = this.rounds().findIndex(
(r) => r.roundId === selectedRoundId
);
if (selectedRoundIdx >= 0) {
this.selectedRound.set(this.rounds[selectedRoundIdx]);
this.selectedRound.set(this.rounds()[selectedRoundIdx]);
}
});
}
selectedRound = signal<UserRoundViewmodel | null>(null);
watchingMyOwnProfile = this.userProfile.watchingMyOwnProfile;
username = this.userProfile.username;
destroy = inject(DestroyRef);
@Input() rounds: UserRoundViewmodel[] = [];
rounds = input<UserRoundViewmodel[]>([]);
selectRound(round?: UserRoundViewmodel): void {
if (!round) {
this.router.navigate([], { relativeTo: this.route });
Expand All @@ -77,7 +77,7 @@ export class RoundListComponent implements OnChanges, OnInit {
ngOnInit(): void {
if (this.rounds.length) {
if (!this.route.snapshot.queryParamMap.has('selectedRoundId')) {
this.selectRound(this.rounds[0]);
this.selectRound(this.rounds()[0]);
}
}

Expand Down

0 comments on commit 82793f4

Please sign in to comment.