aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-video-playlist/video-playlist-miniature.component.ts
blob: 225c4eb644d2fcf7790314b86b7a5797cfa74e9f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { LinkType } from 'src/types/link.type'
import { Component, Input, OnInit } from '@angular/core'
import { VideoPlaylist } from './video-playlist.model'
import { MarkdownService } from '@app/core'

@Component({
  selector: 'my-video-playlist-miniature',
  styleUrls: [ './video-playlist-miniature.component.scss' ],
  templateUrl: './video-playlist-miniature.component.html'
})
export class VideoPlaylistMiniatureComponent implements OnInit {
  @Input() playlist: VideoPlaylist

  @Input() toManage = false

  @Input() displayChannel = false
  @Input() displayDescription = false
  @Input() displayPrivacy = false
  @Input() displayAsRow = false

  @Input() linkType: LinkType = 'internal'

  routerLink: any
  playlistHref: string
  playlistTarget: string
  playlistDescription: string

  constructor (
    private markdownService: MarkdownService
  ) {}

  async ngOnInit () {
    this.buildPlaylistUrl()
    if (this.displayDescription) {
      this.playlistDescription = await this.markdownService.textMarkdownToHTML({ markdown: this.playlist.description })
    }
  }

  buildPlaylistUrl () {
    if (this.toManage) {
      this.routerLink = [ '/my-library/video-playlists', this.playlist.uuid ]
      return
    }

    if (this.playlist.videosLength === 0) {
      this.routerLink = null
      return
    }

    if (this.linkType === 'internal' || !this.playlist.url) {
      this.routerLink = VideoPlaylist.buildWatchUrl(this.playlist)
      return
    }

    if (this.linkType === 'external') {
      this.routerLink = null
      this.playlistHref = this.playlist.url
      this.playlistTarget = '_blank'
      return
    }

    // Lazy load
    this.routerLink = [ '/search/lazy-load-playlist', { url: this.playlist.url } ]

    return
  }
}