diff options
author | kontrollanten <6680299+kontrollanten@users.noreply.github.com> | 2021-04-27 16:08:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-27 16:08:10 +0200 |
commit | 0979075453b380fa8e3694db3f460e822f046c35 (patch) | |
tree | 93efe74fe8fb76c39a5acfe0722243ccdfd045b5 /client/src/app/shared/shared-account-avatar | |
parent | 75d749596205511e012cecbdd39123277244f462 (diff) | |
download | PeerTube-0979075453b380fa8e3694db3f460e822f046c35.tar.gz PeerTube-0979075453b380fa8e3694db3f460e822f046c35.tar.zst PeerTube-0979075453b380fa8e3694db3f460e822f046c35.zip |
Use account initial as default avatar (#4002)
* client: use account initial as default avatar
* fix UI in user list
Avatars was cutted in the top and bottom
Diffstat (limited to 'client/src/app/shared/shared-account-avatar')
3 files changed, 84 insertions, 4 deletions
diff --git a/client/src/app/shared/shared-account-avatar/account-avatar.component.html b/client/src/app/shared/shared-account-avatar/account-avatar.component.html index ca4ceb12f..083daccfb 100644 --- a/client/src/app/shared/shared-account-avatar/account-avatar.component.html +++ b/client/src/app/shared/shared-account-avatar/account-avatar.component.html | |||
@@ -1,5 +1,8 @@ | |||
1 | <ng-template #img> | 1 | <ng-template #img> |
2 | <img [class]="class" [src]="avatarUrl" i18n-alt alt="Account avatar" /> | 2 | <img *ngIf="avatarUrl || !initial" [class]="class" [src]="avatarUrl || defaultAvatarUrl" i18n-alt alt="Account avatar" /> |
3 | <div *ngIf="!avatarUrl && initial" [class]="class"> | ||
4 | <span>{{ initial }}</span> | ||
5 | </div> | ||
3 | </ng-template> | 6 | </ng-template> |
4 | 7 | ||
5 | <a *ngIf="account && href" [href]="href" target="_blank" rel="noopener noreferrer" [title]="title"> | 8 | <a *ngIf="account && href" [href]="href" target="_blank" rel="noopener noreferrer" [title]="title"> |
diff --git a/client/src/app/shared/shared-account-avatar/account-avatar.component.scss b/client/src/app/shared/shared-account-avatar/account-avatar.component.scss index bb941d712..75a4cbf86 100644 --- a/client/src/app/shared/shared-account-avatar/account-avatar.component.scss +++ b/client/src/app/shared/shared-account-avatar/account-avatar.component.scss | |||
@@ -5,6 +5,10 @@ | |||
5 | @include avatar(25px); | 5 | @include avatar(25px); |
6 | } | 6 | } |
7 | 7 | ||
8 | .avatar-32 { | ||
9 | @include avatar(32px); | ||
10 | } | ||
11 | |||
8 | .avatar-34 { | 12 | .avatar-34 { |
9 | @include avatar(34px); | 13 | @include avatar(34px); |
10 | } | 14 | } |
@@ -19,4 +23,54 @@ | |||
19 | 23 | ||
20 | .avatar-120 { | 24 | .avatar-120 { |
21 | @include avatar(120px); | 25 | @include avatar(120px); |
22 | } \ No newline at end of file | 26 | |
27 | &.initial { | ||
28 | font-size: 46px; | ||
29 | } | ||
30 | } | ||
31 | |||
32 | a:hover { | ||
33 | text-decoration: none; | ||
34 | } | ||
35 | |||
36 | .initial { | ||
37 | background-color: #3C2109; | ||
38 | color: #fff; | ||
39 | display: flex; | ||
40 | align-items: center; | ||
41 | justify-content: center; | ||
42 | font-size: 22px; | ||
43 | border-radius: 50%; | ||
44 | |||
45 | &.blue { | ||
46 | background-color: #009FD4; | ||
47 | } | ||
48 | |||
49 | &.green { | ||
50 | background-color: #00AA55; | ||
51 | } | ||
52 | |||
53 | &.purple { | ||
54 | background-color: #B381B3; | ||
55 | } | ||
56 | |||
57 | &.gray { | ||
58 | background-color: #939393; | ||
59 | } | ||
60 | |||
61 | &.yellow { | ||
62 | background-color: #AA8F00; | ||
63 | } | ||
64 | |||
65 | &.orange { | ||
66 | background-color: #D47500; | ||
67 | } | ||
68 | |||
69 | &.red { | ||
70 | background-color: #E76E3C; | ||
71 | } | ||
72 | |||
73 | &.dark-blue { | ||
74 | background-color: #0A3055; | ||
75 | } | ||
76 | } | ||
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 | } |