]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-actor-image/actor-avatar.component.ts
Fix forgot password button role
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-actor-image / actor-avatar.component.ts
CommitLineData
746018f6 1import { Component, Input } from '@angular/core'
746018f6
C
2import { VideoChannel } from '../shared-main'
3import { Account } from '../shared-main/account/account.model'
4
5type ActorInput = {
6 name: string
7 avatar?: { url?: string, path: string }
8 url: string
9}
10
06ec4bdd
C
11export type ActorAvatarSize = '18' | '25' | '32' | '34' | '36' | '40' | '100' | '120'
12
746018f6
C
13@Component({
14 selector: 'my-actor-avatar',
15 styleUrls: [ './actor-avatar.component.scss' ],
16 templateUrl: './actor-avatar.component.html'
17})
18export class ActorAvatarComponent {
9df52d66
C
19 private _title: string
20
746018f6
C
21 @Input() account: ActorInput
22 @Input() channel: ActorInput
23
0ea2f79d 24 @Input() previewImage: string
746018f6 25
06ec4bdd 26 @Input() size: ActorAvatarSize
746018f6
C
27
28 // Use an external link
29 @Input() href: string
30 // Use routerLink
31 @Input() internalHref: string | any[]
32
33 @Input() set title (value) {
34 this._title = value
35 }
36
746018f6
C
37 get title () {
38 if (this._title) return this._title
39 if (this.account) return $localize`${this.account.name} (account page)`
40 if (this.channel) return $localize`${this.channel.name} (channel page)`
41
42 return ''
43 }
44
45 get alt () {
46 if (this.account) return $localize`Account avatar`
47 if (this.channel) return $localize`Channel avatar`
48
49 return ''
50 }
51
746018f6 52 get defaultAvatarUrl () {
746018f6
C
53 if (this.channel) return VideoChannel.GET_DEFAULT_AVATAR_URL()
54
936441b9 55 return Account.GET_DEFAULT_AVATAR_URL()
746018f6
C
56 }
57
58 get avatarUrl () {
59 if (this.account) return Account.GET_ACTOR_AVATAR_URL(this.account)
7d026caf 60 if (this.channel) return VideoChannel.GET_ACTOR_AVATAR_URL(this.channel)
746018f6
C
61
62 return ''
63 }
64
65 get initial () {
66 const name = this.account?.name
67 if (!name) return ''
68
69 return name.slice(0, 1)
70 }
71
9df52d66
C
72 getClass (type: 'avatar' | 'initial') {
73 const base = [ 'avatar' ]
74
75 if (this.size) base.push(`avatar-${this.size}`)
76
77 if (this.channel) base.push('channel')
78 else base.push('account')
79
80 if (type === 'initial' && this.initial) {
81 base.push('initial')
82 base.push(this.getColorTheme())
83 }
84
85 return base
86 }
87
746018f6
C
88 hasActor () {
89 return !!this.account || !!this.channel
90 }
91
92 private getColorTheme () {
93 // Keep consistency with CSS
94 const themes = {
95 abc: 'blue',
96 def: 'green',
97 ghi: 'purple',
98 jkl: 'gray',
99 mno: 'yellow',
100 pqr: 'orange',
1fd61899 101 stvu: 'red',
746018f6
C
102 wxyz: 'dark-blue'
103 }
104
105 const theme = Object.keys(themes)
106 .find(chars => chars.includes(this.initial))
107
108 return themes[theme]
109 }
110}