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'
11 selector: 'my-follow-modal',
12 templateUrl: './follow-modal.component.html',
13 styleUrls: [ './follow-modal.component.scss' ]
15 export class FollowModalComponent extends FormReactive implements OnInit {
16 @ViewChild('modal', { static: true }) modal: NgbModal
18 @Output() newFollow = new EventEmitter<void>()
20 placeholder = 'example.com\nchocobozzz@example.com\nchocobozzz_channel@example.com'
22 private openedModal: NgbModalRef
25 protected formReactiveService: FormReactiveService,
26 private modalService: NgbModal,
27 private followService: InstanceFollowService,
28 private notifier: Notifier
35 hostsOrHandles: UNIQUE_HOSTS_OR_HANDLE_VALIDATOR
40 this.openedModal = this.modalService.open(this.modal, { centered: true })
44 this.openedModal.close()
55 return window.location.protocol === 'https:'
58 private addFollowing () {
59 const hostsOrHandles = splitAndGetNotEmpty(this.form.value['hostsOrHandles'])
61 this.followService.follow(hostsOrHandles)
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!`
74 error: err => this.notifier.error(err.message)