]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/follows/following-list/follow-modal.component.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / follows / following-list / follow-modal.component.ts
1 import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { prepareIcu } from '@app/helpers'
4 import { splitAndGetNotEmpty, UNIQUE_HOSTS_OR_HANDLE_VALIDATOR } from '@app/shared/form-validators/host-validators'
5 import { FormReactive, FormReactiveService } from '@app/shared/shared-forms'
6 import { InstanceFollowService } from '@app/shared/shared-instance'
7 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
8 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
9
10 @Component({
11 selector: 'my-follow-modal',
12 templateUrl: './follow-modal.component.html',
13 styleUrls: [ './follow-modal.component.scss' ]
14 })
15 export class FollowModalComponent extends FormReactive implements OnInit {
16 @ViewChild('modal', { static: true }) modal: NgbModal
17
18 @Output() newFollow = new EventEmitter<void>()
19
20 placeholder = 'example.com\nchocobozzz@example.com\nchocobozzz_channel@example.com'
21
22 private openedModal: NgbModalRef
23
24 constructor (
25 protected formReactiveService: FormReactiveService,
26 private modalService: NgbModal,
27 private followService: InstanceFollowService,
28 private notifier: Notifier
29 ) {
30 super()
31 }
32
33 ngOnInit () {
34 this.buildForm({
35 hostsOrHandles: UNIQUE_HOSTS_OR_HANDLE_VALIDATOR
36 })
37 }
38
39 openModal () {
40 this.openedModal = this.modalService.open(this.modal, { centered: true })
41 }
42
43 hide () {
44 this.openedModal.close()
45 }
46
47 submit () {
48 this.addFollowing()
49
50 this.form.reset()
51 this.hide()
52 }
53
54 httpEnabled () {
55 return window.location.protocol === 'https:'
56 }
57
58 private addFollowing () {
59 const hostsOrHandles = splitAndGetNotEmpty(this.form.value['hostsOrHandles'])
60
61 this.followService.follow(hostsOrHandles)
62 .subscribe({
63 next: () => {
64 this.notifier.success(
65 prepareIcu($localize`{count, plural, =1 {Follow request sent!} other {Follow requests sent!}}`)(
66 { count: hostsOrHandles.length },
67 $localize`Follow request(s) sent!`
68 )
69 )
70
71 this.newFollow.emit()
72 },
73
74 error: err => this.notifier.error(err.message)
75 })
76 }
77 }