diff options
Diffstat (limited to 'client/src/app/shared/shared-account-avatar/account-avatar.component.ts')
-rw-r--r-- | client/src/app/shared/shared-account-avatar/account-avatar.component.ts | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/client/src/app/shared/shared-account-avatar/account-avatar.component.ts b/client/src/app/shared/shared-account-avatar/account-avatar.component.ts index 02a0a18bf..76b696566 100644 --- a/client/src/app/shared/shared-account-avatar/account-avatar.component.ts +++ b/client/src/app/shared/shared-account-avatar/account-avatar.component.ts | |||
@@ -12,7 +12,7 @@ export class AccountAvatarComponent { | |||
12 | avatar?: { url?: string, path: string } | 12 | avatar?: { url?: string, path: string } |
13 | url: string | 13 | url: string |
14 | } | 14 | } |
15 | @Input() size: '25' | '34' | '36' | '40' | '120' = '36' | 15 | @Input() size: '25' | '32' | '34' | '36' | '40' | '120' = '36' |
16 | 16 | ||
17 | // Use an external link | 17 | // Use an external link |
18 | @Input() href: string | 18 | @Input() href: string |
@@ -23,6 +23,8 @@ export class AccountAvatarComponent { | |||
23 | this._title = value | 23 | this._title = value |
24 | } | 24 | } |
25 | 25 | ||
26 | defaultAvatarUrl = Account.GET_DEFAULT_AVATAR_URL() | ||
27 | |||
26 | private _title: string | 28 | private _title: string |
27 | 29 | ||
28 | get title () { | 30 | get title () { |
@@ -30,10 +32,31 @@ export class AccountAvatarComponent { | |||
30 | } | 32 | } |
31 | 33 | ||
32 | get class () { | 34 | get class () { |
33 | return `avatar avatar-${this.size}` | 35 | return `avatar avatar-${this.size}` + (this.avatarUrl ? '' : ` initial ${this.getColorTheme()}`) |
34 | } | 36 | } |
35 | 37 | ||
36 | get avatarUrl () { | 38 | get avatarUrl () { |
37 | return Account.GET_ACTOR_AVATAR_URL(this.account) | 39 | return Account.GET_ACTOR_AVATAR_URL(this.account) |
38 | } | 40 | } |
41 | |||
42 | get initial () { | ||
43 | return this.account?.name.slice(0, 1) | ||
44 | } | ||
45 | |||
46 | private getColorTheme () { | ||
47 | const themes = { | ||
48 | abc: 'blue', | ||
49 | def: 'green', | ||
50 | ghi: 'purple', | ||
51 | jkl: 'gray', | ||
52 | mno: 'yellow', | ||
53 | pqr: 'orange', | ||
54 | stv: 'red', | ||
55 | wxyz: 'dark-blue' | ||
56 | } | ||
57 | |||
58 | const theme = Object.keys(themes).find(chars => chars.includes(this.initial)) | ||
59 | |||
60 | return themes[theme] | ||
61 | } | ||
39 | } | 62 | } |