Skip to content

Commit

Permalink
🐛 Corrigindo bug no botão da ordenação
Browse files Browse the repository at this point in the history
  • Loading branch information
navicg committed Dec 14, 2024
1 parent d711d9c commit 6e93705
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 41 deletions.
22 changes: 12 additions & 10 deletions src/app/pages/record/record.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ <h1 class="header-title">Histórico de Vídeos</h1>
<input type="checkbox" [(ngModel)]="trackingEnabled" (change)="toggleTracking(trackingEnabled)" />
Rastreamento do Histórico
</label>
<button
(click)="sortRecord(true)"
class="btn btn-secondary mr-2"
[class.active]="isAscendingActive">
Ordenar Crescente
<button
(click)="sortRecord(true)"
class="btn btn-secondary mr-2"
[ngClass]="{ 'active': isAscendingActive }"
>
Ordenar Crescente
</button>
<button
(click)="sortRecord(false)"
class="btn btn-secondary"
[class.active]="!isAscendingActive">
Ordenar Decrescente
<button
(click)="sortRecord(false)"
class="btn btn-secondary"
[ngClass]="{ 'active': isDescendingActive }"
>
Ordenar Decrescente
</button>
</div>

Expand Down
70 changes: 39 additions & 31 deletions src/app/pages/record/record.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export class RecordComponent {
userId: string = '';
recordVideos: any = {}; // Inicializado como um objeto vazio
trackingEnabled: boolean = true; // Estado da checkbox de rastreamento
isAscendingActive: boolean | null = null; // Estado para o botão ativo
isAscendingActive: boolean = false;
isDescendingActive: boolean = false;

constructor(private videoService: VideoService, private router: Router) {}

Expand Down Expand Up @@ -167,36 +168,43 @@ export class RecordComponent {
}

sortRecord(ascending: boolean): void {
this.isAscendingActive = ascending; // Atualiza o botão ativo
console.log('Sorting records, ascending:', ascending);
this.videoService.getRecordSorted(this.userId, ascending).subscribe({
next: (response) => {
console.log('Response from backend:', response.videos);

this.recordVideos = { videos: response.videos };

// Atualiza a lista filtrada
this.filteredVideos = [];
const videoIds = Object.keys(this.recordVideos.videos);

videoIds.forEach(id => {
const video = this.unbTvVideos.find(v => v.id?.toString() === id);
if (video) {
this.filteredVideos.push(video);
}
});

if (!ascending) {
this.filteredVideos.reverse();
}

console.log('Filtered videos after processing:', this.filteredVideos);
},
error: (err) => {
console.error('Error sorting record:', err);
}
});
}
console.log('Sorting records, ascending:', ascending);

// Atualiza o estado dos botões
this.isAscendingActive = ascending;
this.isDescendingActive = !ascending;

this.videoService.getRecordSorted(this.userId, ascending).subscribe({
next: (response) => {
console.log('Response from backend:', response.videos);

this.recordVideos = { videos: response.videos };

// Criação de uma nova lista de vídeos filtrados
this.filteredVideos = [];
const videoIds = Object.keys(this.recordVideos.videos);
console.log('Video IDs from backend:', videoIds);

// Mapeamento de IDs para os vídeos correspondentes
videoIds.forEach((id) => {
const video = this.unbTvVideos.find((v) => v.id?.toString() === id);
if (video) {
this.filteredVideos.push(video);
}
});

// Se não estiver em ordem ascendente, reverter a ordem dos vídeos
if (!ascending) {
this.filteredVideos.reverse();
}

console.log('Filtered videos after processing:', this.filteredVideos);
},
error: (err) => {
console.error('Error sorting record:', err);
},
});
}

deleteVideo(videoId: string): void {
this.videoService.removeVideoFromRecord(videoId, this.userId).subscribe({
Expand Down

0 comments on commit 6e93705

Please sign in to comment.