aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-actor-image/actor-avatar.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-06-27 11:22:21 +0200
committerChocobozzz <me@florianbigard.com>2022-06-27 11:22:21 +0200
commit87fdea2fbf486f056dd24bfd416841813bd41c58 (patch)
tree24cc7e153620d792d255d5c441e8bf1609cbe636 /client/src/app/shared/shared-actor-image/actor-avatar.component.ts
parente722fb5923ddf11d72e48cec9788abc64327c22f (diff)
downloadPeerTube-87fdea2fbf486f056dd24bfd416841813bd41c58.tar.gz
PeerTube-87fdea2fbf486f056dd24bfd416841813bd41c58.tar.zst
PeerTube-87fdea2fbf486f056dd24bfd416841813bd41c58.zip
Refactor actor avatar component
Diffstat (limited to 'client/src/app/shared/shared-actor-image/actor-avatar.component.ts')
-rw-r--r--client/src/app/shared/shared-actor-image/actor-avatar.component.ts73
1 files changed, 50 insertions, 23 deletions
diff --git a/client/src/app/shared/shared-actor-image/actor-avatar.component.ts b/client/src/app/shared/shared-actor-image/actor-avatar.component.ts
index fdc8268d8..437de1d50 100644
--- a/client/src/app/shared/shared-actor-image/actor-avatar.component.ts
+++ b/client/src/app/shared/shared-actor-image/actor-avatar.component.ts
@@ -18,8 +18,8 @@ export type ActorAvatarSize = '18' | '25' | '28' | '32' | '34' | '35' | '36' | '
18export class ActorAvatarComponent implements OnChanges { 18export class ActorAvatarComponent implements OnChanges {
19 private _title: string 19 private _title: string
20 20
21 @Input() account: ActorInput 21 @Input() actor: ActorInput
22 @Input() channel: ActorInput 22 @Input() actorType: 'channel' | 'account' | 'unlogged'
23 23
24 @Input() previewImage: string 24 @Input() previewImage: string
25 25
@@ -36,8 +36,8 @@ export class ActorAvatarComponent implements OnChanges {
36 36
37 get title () { 37 get title () {
38 if (this._title) return this._title 38 if (this._title) return this._title
39 if (this.account) return $localize`${this.account.name} (account page)` 39 if (this.isAccount()) return $localize`${this.actor.name} (account page)`
40 if (this.channel) return $localize`${this.channel.name} (channel page)` 40 if (this.isChannel()) return $localize`${this.actor.name} (channel page)`
41 41
42 return '' 42 return ''
43 } 43 }
@@ -45,48 +45,75 @@ export class ActorAvatarComponent implements OnChanges {
45 classes: string[] = [] 45 classes: string[] = []
46 46
47 get alt () { 47 get alt () {
48 if (this.account) return $localize`Account avatar` 48 if (this.isAccount()) return $localize`Account avatar`
49 if (this.channel) return $localize`Channel avatar` 49 if (this.isChannel()) return $localize`Channel avatar`
50 50
51 return '' 51 return ''
52 } 52 }
53 53
54 get defaultAvatarUrl () { 54 get defaultAvatarUrl () {
55 if (this.channel) return VideoChannel.GET_DEFAULT_AVATAR_URL(this.getSizeNumber()) 55 if (this.isChannel()) return VideoChannel.GET_DEFAULT_AVATAR_URL(this.getSizeNumber())
56 56
57 // account or unlogged
57 return Account.GET_DEFAULT_AVATAR_URL(this.getSizeNumber()) 58 return Account.GET_DEFAULT_AVATAR_URL(this.getSizeNumber())
58 } 59 }
59 60
60 get avatarUrl () { 61 get avatarUrl () {
61 if (this.account) return Account.GET_ACTOR_AVATAR_URL(this.account, this.getSizeNumber()) 62 if (!this.actor) return ''
62 if (this.channel) return VideoChannel.GET_ACTOR_AVATAR_URL(this.channel, this.getSizeNumber())
63 63
64 return '' 64 if (this.isAccount()) return Account.GET_ACTOR_AVATAR_URL(this.actor, this.getSizeNumber())
65 } 65 if (this.isChannel()) return VideoChannel.GET_ACTOR_AVATAR_URL(this.actor, this.getSizeNumber())
66
67 get initial () {
68 const name = this.account?.name
69 if (!name) return ''
70 66
71 return name.slice(0, 1) 67 return ''
72 } 68 }
73 69
74 ngOnChanges () { 70 ngOnChanges () {
75 this.classes = [ 'avatar' ] 71 this.classes = [ 'avatar' ]
76 72
77 if (this.size) this.classes.push(`avatar-${this.size}`) 73 if (this.size) {
74 this.classes.push(`avatar-${this.size}`)
75 }
78 76
79 if (this.channel) this.classes.push('channel') 77 if (this.isChannel()) {
80 else this.classes.push('account') 78 this.classes.push('channel')
79 } else {
80 this.classes.push('account')
81 }
81 82
82 if (!this.avatarUrl && this.initial) { 83 // No avatar, use actor name initial
84 if (this.displayActorInitial()) {
83 this.classes.push('initial') 85 this.classes.push('initial')
84 this.classes.push(this.getColorTheme()) 86 this.classes.push(this.getColorTheme())
85 } 87 }
86 } 88 }
87 89
88 hasActor () { 90 displayImage () {
89 return !!this.account || !!this.channel 91 if (this.actorType === 'unlogged') return true
92
93 return !!(this.actor && this.avatarUrl)
94 }
95
96 displayActorInitial () {
97 return this.actor && !this.avatarUrl
98 }
99
100 displayPlaceholder () {
101 return this.actorType !== 'unlogged' && !this.actor
102 }
103
104 getActorInitial () {
105 const name = this.actor?.name
106 if (!name) return ''
107
108 return name.slice(0, 1)
109 }
110
111 private isAccount () {
112 return this.actorType === 'account'
113 }
114
115 private isChannel () {
116 return this.actorType === 'channel'
90 } 117 }
91 118
92 private getSizeNumber () { 119 private getSizeNumber () {
@@ -96,7 +123,7 @@ export class ActorAvatarComponent implements OnChanges {
96 } 123 }
97 124
98 private getColorTheme () { 125 private getColorTheme () {
99 const initialLowercase = this.initial.toLowerCase() 126 const initialLowercase = this.getActorInitial().toLowerCase()
100 127
101 // Keep consistency with CSS 128 // Keep consistency with CSS
102 const themes = { 129 const themes = {