-import { Component, Input } from '@angular/core'
+import { Component, Input, OnChanges } from '@angular/core'
import { VideoChannel } from '../shared-main'
import { Account } from '../shared-main/account/account.model'
type ActorInput = {
name: string
- avatar?: { url?: string, path: string }
+ avatars: { width: number, url?: string, path: string }[]
url: string
}
-export type ActorAvatarSize = '18' | '25' | '32' | '34' | '36' | '40' | '100' | '120'
+export type ActorAvatarSize = '18' | '25' | '28' | '32' | '34' | '35' | '36' | '40' | '48' | '75' | '80' | '100' | '120'
@Component({
selector: 'my-actor-avatar',
styleUrls: [ './actor-avatar.component.scss' ],
templateUrl: './actor-avatar.component.html'
})
-export class ActorAvatarComponent {
+export class ActorAvatarComponent implements OnChanges {
private _title: string
@Input() account: ActorInput
return ''
}
+ classes: string[] = []
+
get alt () {
if (this.account) return $localize`Account avatar`
if (this.channel) return $localize`Channel avatar`
}
get defaultAvatarUrl () {
- if (this.channel) return VideoChannel.GET_DEFAULT_AVATAR_URL()
-
- return Account.GET_DEFAULT_AVATAR_URL()
+ if (this.account) return Account.GET_DEFAULT_AVATAR_URL(this.getSizeNumber())
+ if (this.channel) return VideoChannel.GET_DEFAULT_AVATAR_URL(this.getSizeNumber())
}
get avatarUrl () {
- if (this.account) return Account.GET_ACTOR_AVATAR_URL(this.account)
- if (this.channel) return VideoChannel.GET_ACTOR_AVATAR_URL(this.channel)
+ if (this.account) return Account.GET_ACTOR_AVATAR_URL(this.account, this.getSizeNumber())
+ if (this.channel) return VideoChannel.GET_ACTOR_AVATAR_URL(this.channel, this.getSizeNumber())
return ''
}
return name.slice(0, 1)
}
- getClass (type: 'avatar' | 'initial') {
- const base = [ 'avatar' ]
+ ngOnChanges () {
+ this.classes = [ 'avatar' ]
- if (this.size) base.push(`avatar-${this.size}`)
+ if (this.size) this.classes.push(`avatar-${this.size}`)
- if (this.channel) base.push('channel')
- else base.push('account')
+ if (this.channel) this.classes.push('channel')
+ else this.classes.push('account')
- if (type === 'initial' && this.initial) {
- base.push('initial')
- base.push(this.getColorTheme())
+ if (!this.avatarUrl && this.initial) {
+ this.classes.push('initial')
+ this.classes.push(this.getColorTheme())
}
-
- return base
}
hasActor () {
return !!this.account || !!this.channel
}
+ private getSizeNumber () {
+ if (this.size) return +this.size
+
+ return undefined
+ }
+
private getColorTheme () {
+ const initialLowercase = this.initial.toLowerCase()
+
// Keep consistency with CSS
const themes = {
- abc: 'blue',
+ '0123456789abc': 'blue',
def: 'green',
ghi: 'purple',
jkl: 'gray',
}
const theme = Object.keys(themes)
- .find(chars => chars.includes(this.initial))
+ .find(chars => chars.includes(initialLowercase))
return themes[theme]
}