1 import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { splitAndGetNotEmpty, UNIQUE_HOSTS_OR_HANDLE_VALIDATOR } from '@app/shared/form-validators/host-validators'
4 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
5 import { InstanceFollowService } from '@app/shared/shared-instance'
6 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
7 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
10 selector: 'my-follow-modal',
11 templateUrl: './follow-modal.component.html',
12 styleUrls: [ './follow-modal.component.scss' ]
14 export class FollowModalComponent extends FormReactive implements OnInit {
15 @ViewChild('modal', { static: true }) modal: NgbModal
17 @Output() newFollow = new EventEmitter<void>()
19 placeholder = 'example.com\nchocobozzz@example.com\nchocobozzz_channel@example.com'
21 private openedModal: NgbModalRef
24 protected formValidatorService: FormValidatorService,
25 private modalService: NgbModal,
26 private followService: InstanceFollowService,
27 private notifier: Notifier
34 hostsOrHandles: UNIQUE_HOSTS_OR_HANDLE_VALIDATOR
39 this.openedModal = this.modalService.open(this.modal, { centered: true })
43 this.openedModal.close()
54 return window.location.protocol === 'https:'
57 private addFollowing () {
58 const hostsOrHandles = splitAndGetNotEmpty(this.form.value['hostsOrHandles'])
60 this.followService.follow(hostsOrHandles)
63 this.notifier.success($localize`Follow request(s) sent!`)
67 error: err => this.notifier.error(err.message)