aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-actor-image/actor-avatar-edit.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-04-07 17:01:29 +0200
committerChocobozzz <chocobozzz@cpy.re>2021-04-08 10:07:53 +0200
commitcdeddff142fd20f8cb8bb346625909d61c596603 (patch)
treee7b0ae302a002fb2eadc605300294a1f135c3744 /client/src/app/shared/shared-actor-image/actor-avatar-edit.component.ts
parent282695e699a35b65441b548061ef0db5de9b3971 (diff)
downloadPeerTube-cdeddff142fd20f8cb8bb346625909d61c596603.tar.gz
PeerTube-cdeddff142fd20f8cb8bb346625909d61c596603.tar.zst
PeerTube-cdeddff142fd20f8cb8bb346625909d61c596603.zip
Add ability to update the banner
Diffstat (limited to 'client/src/app/shared/shared-actor-image/actor-avatar-edit.component.ts')
-rw-r--r--client/src/app/shared/shared-actor-image/actor-avatar-edit.component.ts73
1 files changed, 73 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-actor-image/actor-avatar-edit.component.ts b/client/src/app/shared/shared-actor-image/actor-avatar-edit.component.ts
new file mode 100644
index 000000000..6f76172e9
--- /dev/null
+++ b/client/src/app/shared/shared-actor-image/actor-avatar-edit.component.ts
@@ -0,0 +1,73 @@
1import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
2import { Notifier, ServerService } from '@app/core'
3import { Account, VideoChannel } from '@app/shared/shared-main'
4import { NgbPopover } from '@ng-bootstrap/ng-bootstrap'
5import { getBytes } from '@root-helpers/bytes'
6
7@Component({
8 selector: 'my-actor-avatar-edit',
9 templateUrl: './actor-avatar-edit.component.html',
10 styleUrls: [
11 './actor-image-edit.scss',
12 './actor-avatar-edit.component.scss'
13 ]
14})
15export class ActorAvatarEditComponent implements OnInit {
16 @ViewChild('avatarfileInput') avatarfileInput: ElementRef<HTMLInputElement>
17 @ViewChild('avatarPopover') avatarPopover: NgbPopover
18
19 @Input() actor: VideoChannel | Account
20 @Input() editable = true
21 @Input() displaySubscribers = true
22 @Input() displayUsername = true
23
24 @Output() avatarChange = new EventEmitter<FormData>()
25 @Output() avatarDelete = new EventEmitter<void>()
26
27 avatarFormat = ''
28 maxAvatarSize = 0
29 avatarExtensions = ''
30
31 constructor (
32 private serverService: ServerService,
33 private notifier: Notifier
34 ) { }
35
36 ngOnInit (): void {
37 this.serverService.getConfig()
38 .subscribe(config => {
39 this.maxAvatarSize = config.avatar.file.size.max
40 this.avatarExtensions = config.avatar.file.extensions.join(', ')
41
42 this.avatarFormat = `${$localize`max size`}: 192*192px, ` +
43 `${getBytes(this.maxAvatarSize)} ${$localize`extensions`}: ${this.avatarExtensions}`
44 })
45 }
46
47 onAvatarChange (input: HTMLInputElement) {
48 this.avatarfileInput = new ElementRef(input)
49
50 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
51 if (avatarfile.size > this.maxAvatarSize) {
52 this.notifier.error('Error', $localize`This image is too large.`)
53 return
54 }
55
56 const formData = new FormData()
57 formData.append('avatarfile', avatarfile)
58 this.avatarPopover?.close()
59 this.avatarChange.emit(formData)
60 }
61
62 deleteAvatar () {
63 this.avatarDelete.emit()
64 }
65
66 hasAvatar () {
67 return !!this.actor.avatar
68 }
69
70 isChannel () {
71 return !!(this.actor as VideoChannel).ownerAccount
72 }
73}