Skip to content

Commit

Permalink
feat: Adicionando funcao de salvar video para assistir mais tarde na …
Browse files Browse the repository at this point in the history
…previa
  • Loading branch information
wChrstphr committed Dec 8, 2024
1 parent a68454c commit fae8fc0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/app/pages/video/video.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ <h6 class="description-text" title="{{ video.title }}">{{ video.title }}</h6>
</div>

<!-- Ícones dentro do vídeo -->
<!-- Favoritar -->
<div class="star-icon" title="Favoritar">
<button class="favorite-button" (click)="toggleFavorite(video)" [class.favorited]="video.isFavorited">
<img *ngIf="!video.isFavorited" src="https://cdn-icons-png.flaticon.com/128/126/126482.png"
Expand All @@ -29,9 +30,12 @@ <h6 class="description-text" title="{{ video.title }}">{{ video.title }}</h6>
alt="desfavoritar vídeo">
</button>
</div>

<!-- Assitir mais tarde -->
<div class="save-icon" title="Assistir mais tarde">
<img src="https://cdn-icons-png.flaticon.com/128/5662/5662990.png" alt="salvar vídeo">
<button class="save-button" (click)="toggleWatchLater(video)" [class.saved]="video.isWatchLater">
<img *ngIf="!video.isWatchLater" src="https://cdn-icons-png.flaticon.com/128/5662/5662990.png" alt="salvar vídeo">
<img *ngIf="video.isWatchLater" src="https://cdn-icons-png.flaticon.com/128/5662/5662989.png" alt="remover vídeo da lista">
</button>
</div>
</div>
</div>
Expand Down
49 changes: 47 additions & 2 deletions src/app/pages/video/video.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class VideoComponent implements OnInit {
user: any;
favoriteMessage: string | null = null; // Armazena a mensagem
eduplayVideoUrl = "https://eduplay.rnp.br/portal/video/embed/";
isWatchLater = true;

constructor(
private videoService: VideoService,
Expand Down Expand Up @@ -115,7 +116,6 @@ export class VideoComponent implements OnInit {
}
}


checkFavoriteStatus(): void {
this.videoService.checkFavorite(this.idVideo.toString(), this.userId.toString()).subscribe({
next: (response) => {
Expand All @@ -133,10 +133,55 @@ export class VideoComponent implements OnInit {
alert(message); // Exemplo de alert, mas você pode customizar com mensagens na tela
}

// Assistir mais tarde
toggleWatchLater(video: IVideo): void {
const videoId = video.id ?? 0;

video.isWatchLater = !video.isWatchLater;

if (video.isWatchLater) {
this.videoService.addToWatchLater(videoId.toString(), this.userId.toString()).subscribe({
next: () => {
this.alertService.showMessage("success", "Sucesso", "Vídeo adicionado à lista de Assistir Mais tarde");
},
error: (err) => {
console.error('Error adding to watch later', err);
this.alertService.showMessage('error', 'Erro', 'Erro ao adicionar o vídeo para assistir mais tarde')
}
});
} else {
this.videoService.removeFromWatchLater(videoId.toString(), this.userId.toString()).subscribe({
next: () => {
this.alertService.showMessage("success", "Sucesso", "Vídeo removido da lista de Assistir mais tarde.");
},
error: (err) => {
console.error('Error removing from watch later', err);
this.alertService.showMessage('error', 'Erro', 'Erro ao remover o vídeo da lista de assistir mais tarde')
}
});
}
}

checkWatchLaterStatus(): void {
this.videoService.checkWatchLater(this.idVideo.toString(), this.userId.toString()).subscribe({
next: (response) => {
this.isWatchLater = response.status; // Acessa a propriedade status do objeto response
},
error: (err) => {
console.error('Error checking watch later status', err);
}
});
}

showWatchLaterMessage(isWatchLater: boolean): void {
const message = isWatchLater ? 'Vídeo salvo a lista!' : 'Vídeo removido da lista!';
this.favoriteMessage = message; // Armazena a mensagem na variável
alert(message); // Exemplo de alert, mas você pode customizar com mensagens na tela
}

returnToCatalog(): void {
this.router.navigate(['/catalog']);
}

// Função que retorna a URL do vídeo
getVideoUrl(): string {
return `${this.eduplayVideoUrl}${this.idVideo}`;
Expand Down
4 changes: 3 additions & 1 deletion src/shared/model/video.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface IVideo {
channels?: IChannel[];
catalog?: any;
isFavorited?: boolean; // Adiciona a propriedade isFavorited
isWatchLater?: boolean;
}

export class Video implements IVideo {
Expand All @@ -35,6 +36,7 @@ export class Video implements IVideo {
public embed?: string,
public channels?: IChannel[],
public catalog?: any,
public isFavorited?: boolean
public isFavorited?: boolean,
public isWatchLater?: boolean
) {}
}

0 comments on commit fae8fc0

Please sign in to comment.