-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Añade lógica para seleccionar patrones de formato de fecha basados en…
… el idioma
- Loading branch information
Showing
3 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 27 additions & 2 deletions
29
src/app/shared/components/challenge-card/challenge-card.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,44 @@ | ||
import { Component, Input, inject } from '@angular/core' | ||
import { Component, Input, type OnInit, type OnDestroy, inject } from '@angular/core' | ||
import { Subscription } from 'rxjs' | ||
import { StarterService } from '../../../services/starter.service' | ||
import { DateFormatterService } from '../../../services/date-formatter.service' | ||
// Cambia la importación de tipo solamente a una importación normal aquí | ||
import { TranslateService } from '@ngx-translate/core' | ||
|
||
@Component({ | ||
selector: 'app-challenge-card', | ||
templateUrl: './challenge-card.component.html', | ||
styleUrls: ['./challenge-card.component.scss'], | ||
providers: [] | ||
}) | ||
export class ChallengeCardComponent { | ||
export class ChallengeCardComponent implements OnInit, OnDestroy { | ||
private readonly starterService = inject(StarterService) | ||
private readonly dateFormatter = inject(DateFormatterService) | ||
private readonly translate = inject(TranslateService) | ||
private translateSubscription!: Subscription | ||
formattedDate: string = '' | ||
|
||
@Input() title: string = '' | ||
@Input() languages: any = [] | ||
@Input() creation_date!: Date | ||
@Input() level = '' | ||
@Input() popularity!: number | ||
@Input() id = '' | ||
|
||
ngOnInit (): void { | ||
this.updateFormattedDate() | ||
this.translateSubscription = this.translate.onLangChange.subscribe(() => { | ||
this.updateFormattedDate() | ||
}) | ||
} | ||
|
||
ngOnDestroy (): void { | ||
if (this.translateSubscription instanceof Subscription) { | ||
this.translateSubscription.unsubscribe() | ||
} | ||
} | ||
|
||
private updateFormattedDate (): void { | ||
this.formattedDate = this.dateFormatter.format(this.creation_date) | ||
} | ||
} |