diff options
author | Chocobozzz <me@florianbigard.com> | 2022-06-27 11:22:21 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-06-27 11:22:21 +0200 |
commit | 87fdea2fbf486f056dd24bfd416841813bd41c58 (patch) | |
tree | 24cc7e153620d792d255d5c441e8bf1609cbe636 /client/src/app/shared | |
parent | e722fb5923ddf11d72e48cec9788abc64327c22f (diff) | |
download | PeerTube-87fdea2fbf486f056dd24bfd416841813bd41c58.tar.gz PeerTube-87fdea2fbf486f056dd24bfd416841813bd41c58.tar.zst PeerTube-87fdea2fbf486f056dd24bfd416841813bd41c58.zip |
Refactor actor avatar component
Diffstat (limited to 'client/src/app/shared')
9 files changed, 69 insertions, 50 deletions
diff --git a/client/src/app/shared/shared-abuse-list/abuse-details.component.html b/client/src/app/shared/shared-abuse-list/abuse-details.component.html index b04d46e32..fdf700f7c 100644 --- a/client/src/app/shared/shared-abuse-list/abuse-details.component.html +++ b/client/src/app/shared/shared-abuse-list/abuse-details.component.html | |||
@@ -10,7 +10,7 @@ | |||
10 | <a [routerLink]="[ '.' ]" [queryParams]="{ 'search': 'reporter:"' + abuse.reporterAccount.displayName + '"' }" | 10 | <a [routerLink]="[ '.' ]" [queryParams]="{ 'search': 'reporter:"' + abuse.reporterAccount.displayName + '"' }" |
11 | class="chip" | 11 | class="chip" |
12 | > | 12 | > |
13 | <my-actor-avatar size="18" [account]="abuse.reporterAccount"></my-actor-avatar> | 13 | <my-actor-avatar size="18" [actor]="abuse.reporterAccount" actorType="account"></my-actor-avatar> |
14 | <div> | 14 | <div> |
15 | <span class="muted">{{ abuse.reporterAccount.nameWithHost }}</span> | 15 | <span class="muted">{{ abuse.reporterAccount.nameWithHost }}</span> |
16 | </div> | 16 | </div> |
@@ -31,7 +31,7 @@ | |||
31 | <a [routerLink]="[ '.' ]" [queryParams]="{ 'search': 'reportee:"' +abuse.flaggedAccount.displayName + '"' }" | 31 | <a [routerLink]="[ '.' ]" [queryParams]="{ 'search': 'reportee:"' +abuse.flaggedAccount.displayName + '"' }" |
32 | class="chip" | 32 | class="chip" |
33 | > | 33 | > |
34 | <my-actor-avatar size="18" [account]="abuse.flaggedAccount"></my-actor-avatar> | 34 | <my-actor-avatar size="18" [actor]="abuse.flaggedAccount" actorType="account"></my-actor-avatar> |
35 | <div> | 35 | <div> |
36 | <span class="muted">{{ abuse.flaggedAccount ? abuse.flaggedAccount.nameWithHost : '' }}</span> | 36 | <span class="muted">{{ abuse.flaggedAccount ? abuse.flaggedAccount.nameWithHost : '' }}</span> |
37 | </div> | 37 | </div> |
diff --git a/client/src/app/shared/shared-abuse-list/abuse-list-table.component.html b/client/src/app/shared/shared-abuse-list/abuse-list-table.component.html index f79054d03..5f9db2b3b 100644 --- a/client/src/app/shared/shared-abuse-list/abuse-list-table.component.html +++ b/client/src/app/shared/shared-abuse-list/abuse-list-table.component.html | |||
@@ -43,7 +43,7 @@ | |||
43 | <td *ngIf="isAdminView()"> | 43 | <td *ngIf="isAdminView()"> |
44 | <a *ngIf="abuse.reporterAccount" [href]="abuse.reporterAccount.url" i18n-title title="Open account in a new tab" target="_blank" rel="noopener noreferrer"> | 44 | <a *ngIf="abuse.reporterAccount" [href]="abuse.reporterAccount.url" i18n-title title="Open account in a new tab" target="_blank" rel="noopener noreferrer"> |
45 | <div class="chip two-lines"> | 45 | <div class="chip two-lines"> |
46 | <my-actor-avatar [account]="abuse.reporterAccount" size="32"></my-actor-avatar> | 46 | <my-actor-avatar [actor]="abuse.reporterAccount" actorType="account" size="32"></my-actor-avatar> |
47 | <div> | 47 | <div> |
48 | {{ abuse.reporterAccount.displayName }} | 48 | {{ abuse.reporterAccount.displayName }} |
49 | <span>{{ abuse.reporterAccount.nameWithHost }}</span> | 49 | <span>{{ abuse.reporterAccount.nameWithHost }}</span> |
diff --git a/client/src/app/shared/shared-actor-image-edit/actor-avatar-edit.component.html b/client/src/app/shared/shared-actor-image-edit/actor-avatar-edit.component.html index b63bf1f92..6459c5ffe 100644 --- a/client/src/app/shared/shared-actor-image-edit/actor-avatar-edit.component.html +++ b/client/src/app/shared/shared-actor-image-edit/actor-avatar-edit.component.html | |||
@@ -1,6 +1,6 @@ | |||
1 | <div class="actor" *ngIf="actor"> | 1 | <div class="actor" *ngIf="actor"> |
2 | <div class="d-flex"> | 2 | <div class="d-flex"> |
3 | <my-actor-avatar [channel]="getChannel()" [account]="getAccount()" [previewImage]="preview" size="100"></my-actor-avatar> | 3 | <my-actor-avatar [actor]="actor" [actorType]="getActorType()" [previewImage]="preview" size="100"></my-actor-avatar> |
4 | 4 | ||
5 | <div class="actor-img-edit-container"> | 5 | <div class="actor-img-edit-container"> |
6 | 6 | ||
diff --git a/client/src/app/shared/shared-actor-image-edit/actor-avatar-edit.component.ts b/client/src/app/shared/shared-actor-image-edit/actor-avatar-edit.component.ts index 01bb401fb..b71a3c485 100644 --- a/client/src/app/shared/shared-actor-image-edit/actor-avatar-edit.component.ts +++ b/client/src/app/shared/shared-actor-image-edit/actor-avatar-edit.component.ts | |||
@@ -75,19 +75,9 @@ export class ActorAvatarEditComponent implements OnInit { | |||
75 | return !!this.preview || this.actor.avatars.length !== 0 | 75 | return !!this.preview || this.actor.avatars.length !== 0 |
76 | } | 76 | } |
77 | 77 | ||
78 | isChannel () { | 78 | getActorType () { |
79 | return !!(this.actor as VideoChannel).ownerAccount | 79 | if ((this.actor as VideoChannel).ownerAccount) return 'channel' |
80 | } | ||
81 | |||
82 | getChannel (): VideoChannel { | ||
83 | if (this.isChannel()) return this.actor as VideoChannel | ||
84 | |||
85 | return undefined | ||
86 | } | ||
87 | |||
88 | getAccount (): Account { | ||
89 | if (this.isChannel()) return undefined | ||
90 | 80 | ||
91 | return this.actor as Account | 81 | return 'account' |
92 | } | 82 | } |
93 | } | 83 | } |
diff --git a/client/src/app/shared/shared-actor-image/actor-avatar.component.html b/client/src/app/shared/shared-actor-image/actor-avatar.component.html index ba025da4d..fb9efc20a 100644 --- a/client/src/app/shared/shared-actor-image/actor-avatar.component.html +++ b/client/src/app/shared/shared-actor-image/actor-avatar.component.html | |||
@@ -1,19 +1,21 @@ | |||
1 | <ng-template #img> | 1 | <ng-template #img> |
2 | <img *ngIf="previewImage || avatarUrl || !initial" [class]="classes" [src]="previewImage || avatarUrl || defaultAvatarUrl" [alt]="alt" /> | 2 | <img *ngIf="displayImage()" [class]="classes" [src]="previewImage || avatarUrl || defaultAvatarUrl" [alt]="alt" /> |
3 | 3 | ||
4 | <div *ngIf="!avatarUrl && initial" [ngClass]="classes"> | 4 | <div *ngIf="displayActorInitial()" [ngClass]="classes"> |
5 | <span>{{ initial }}</span> | 5 | <span>{{ getActorInitial() }}</span> |
6 | </div> | 6 | </div> |
7 | |||
8 | <div *ngIf="displayPlaceholder()" [ngClass]="classes"></div> | ||
7 | </ng-template> | 9 | </ng-template> |
8 | 10 | ||
9 | <a *ngIf="hasActor() && href" [href]="href" target="_blank" rel="noopener noreferrer" [title]="title"> | 11 | <a *ngIf="actor && href" [href]="href" target="_blank" rel="noopener noreferrer" [title]="title"> |
10 | <ng-template *ngTemplateOutlet="img"></ng-template> | 12 | <ng-template *ngTemplateOutlet="img"></ng-template> |
11 | </a> | 13 | </a> |
12 | 14 | ||
13 | <a *ngIf="hasActor() && internalHref" [routerLink]="internalHref" [title]="title"> | 15 | <a *ngIf="actor && internalHref" [routerLink]="internalHref" [title]="title"> |
14 | <ng-template *ngTemplateOutlet="img"></ng-template> | 16 | <ng-template *ngTemplateOutlet="img"></ng-template> |
15 | </a> | 17 | </a> |
16 | 18 | ||
17 | <ng-container *ngIf="!hasActor() || (!href && !internalHref)"> | 19 | <ng-container *ngIf="!actor || (!href && !internalHref)"> |
18 | <ng-template *ngTemplateOutlet="img"></ng-template> | 20 | <ng-template *ngTemplateOutlet="img"></ng-template> |
19 | </ng-container> | 21 | </ng-container> |
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' | ' | |||
18 | export class ActorAvatarComponent implements OnChanges { | 18 | export 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 = { |
diff --git a/client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.html b/client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.html index 52a402329..395cc8562 100644 --- a/client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.html +++ b/client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.html | |||
@@ -1,7 +1,7 @@ | |||
1 | <div *ngIf="channel" class="channel"> | 1 | <div *ngIf="channel" class="channel"> |
2 | 2 | ||
3 | <div class="channel-avatar-row"> | 3 | <div class="channel-avatar-row"> |
4 | <my-actor-avatar [channel]="channel" [internalHref]="getVideoChannelLink()" i18n-title title="See this video channel" size="75"></my-actor-avatar> | 4 | <my-actor-avatar [actor]="channel" actorType="channel" [internalHref]="getVideoChannelLink()" i18n-title title="See this video channel" size="75"></my-actor-avatar> |
5 | 5 | ||
6 | <h6> | 6 | <h6> |
7 | <a [routerLink]="getVideoChannelLink()" i18n-title title="See this video channel"> | 7 | <a [routerLink]="getVideoChannelLink()" i18n-title title="See this video channel"> |
diff --git a/client/src/app/shared/shared-moderation/account-blocklist.component.html b/client/src/app/shared/shared-moderation/account-blocklist.component.html index 131110318..fef24cfdf 100644 --- a/client/src/app/shared/shared-moderation/account-blocklist.component.html +++ b/client/src/app/shared/shared-moderation/account-blocklist.component.html | |||
@@ -33,7 +33,7 @@ | |||
33 | <td> | 33 | <td> |
34 | <a [href]="accountBlock.blockedAccount.url" i18n-title title="Open account in a new tab" target="_blank" rel="noopener noreferrer"> | 34 | <a [href]="accountBlock.blockedAccount.url" i18n-title title="Open account in a new tab" target="_blank" rel="noopener noreferrer"> |
35 | <div class="chip two-lines"> | 35 | <div class="chip two-lines"> |
36 | <my-actor-avatar [account]="accountBlock.blockedAccount" size="32"></my-actor-avatar> | 36 | <my-actor-avatar [actor]="accountBlock.blockedAccount" actorType="account" size="32"></my-actor-avatar> |
37 | <div> | 37 | <div> |
38 | {{ accountBlock.blockedAccount.displayName }} | 38 | {{ accountBlock.blockedAccount.displayName }} |
39 | <span class="muted">{{ accountBlock.blockedAccount.nameWithHost }}</span> | 39 | <span class="muted">{{ accountBlock.blockedAccount.nameWithHost }}</span> |
diff --git a/client/src/app/shared/shared-video-miniature/video-miniature.component.html b/client/src/app/shared/shared-video-miniature/video-miniature.component.html index 3cf128de0..e8d2ca1c4 100644 --- a/client/src/app/shared/shared-video-miniature/video-miniature.component.html +++ b/client/src/app/shared/shared-video-miniature/video-miniature.component.html | |||
@@ -12,13 +12,13 @@ | |||
12 | <div class="d-flex video-miniature-meta"> | 12 | <div class="d-flex video-miniature-meta"> |
13 | <my-actor-avatar | 13 | <my-actor-avatar |
14 | *ngIf="displayOptions.avatar && displayOwnerVideoChannel() && !displayAsRow" [title]="channelLinkTitle" | 14 | *ngIf="displayOptions.avatar && displayOwnerVideoChannel() && !displayAsRow" [title]="channelLinkTitle" |
15 | [channel]="video.channel" [size]="actorImageSize" [internalHref]="[ '/c', video.byVideoChannel ]" | 15 | [actor]="video.channel" actorType="channel" [size]="actorImageSize" [internalHref]="[ '/c', video.byVideoChannel ]" |
16 | size="32" | 16 | size="32" |
17 | ></my-actor-avatar> | 17 | ></my-actor-avatar> |
18 | 18 | ||
19 | <my-actor-avatar | 19 | <my-actor-avatar |
20 | *ngIf="displayOptions.avatar && displayOwnerAccount() && !displayAsRow" [title]="channelLinkTitle" | 20 | *ngIf="displayOptions.avatar && displayOwnerAccount() && !displayAsRow" [title]="channelLinkTitle" |
21 | [account]="video.account" [size]="actorImageSize" [internalHref]="[ '/c', video.byVideoChannel ]" | 21 | [actor]="video.account" actorType="channel" [size]="actorImageSize" [internalHref]="[ '/c', video.byVideoChannel ]" |
22 | size="32" | 22 | size="32" |
23 | ></my-actor-avatar> | 23 | ></my-actor-avatar> |
24 | 24 | ||