diff options
Diffstat (limited to 'client/src/app/+admin/follows/following-list/follow-modal.component.ts')
-rw-r--r-- | client/src/app/+admin/follows/following-list/follow-modal.component.ts | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/client/src/app/+admin/follows/following-list/follow-modal.component.ts b/client/src/app/+admin/follows/following-list/follow-modal.component.ts new file mode 100644 index 000000000..dc6909200 --- /dev/null +++ b/client/src/app/+admin/follows/following-list/follow-modal.component.ts | |||
@@ -0,0 +1,69 @@ | |||
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' | ||
8 | |||
9 | @Component({ | ||
10 | selector: 'my-follow-modal', | ||
11 | templateUrl: './follow-modal.component.html', | ||
12 | styleUrls: [ './follow-modal.component.scss' ] | ||
13 | }) | ||
14 | export class FollowModalComponent extends FormReactive implements OnInit { | ||
15 | @ViewChild('modal', { static: true }) modal: NgbModal | ||
16 | |||
17 | @Output() newFollow = new EventEmitter<void>() | ||
18 | |||
19 | placeholder = 'example.com\nchocobozzz@example.com\nchocobozzz_channel@example.com' | ||
20 | |||
21 | private openedModal: NgbModalRef | ||
22 | |||
23 | constructor ( | ||
24 | protected formValidatorService: FormValidatorService, | ||
25 | private modalService: NgbModal, | ||
26 | private followService: InstanceFollowService, | ||
27 | private notifier: Notifier | ||
28 | ) { | ||
29 | super() | ||
30 | } | ||
31 | |||
32 | ngOnInit () { | ||
33 | this.buildForm({ | ||
34 | hostsOrHandles: UNIQUE_HOSTS_OR_HANDLE_VALIDATOR | ||
35 | }) | ||
36 | } | ||
37 | |||
38 | openModal () { | ||
39 | this.openedModal = this.modalService.open(this.modal, { centered: true }) | ||
40 | } | ||
41 | |||
42 | hide () { | ||
43 | this.openedModal.close() | ||
44 | } | ||
45 | |||
46 | submit () { | ||
47 | this.addFollowing() | ||
48 | |||
49 | this.form.reset() | ||
50 | this.hide() | ||
51 | } | ||
52 | |||
53 | httpEnabled () { | ||
54 | return window.location.protocol === 'https:' | ||
55 | } | ||
56 | |||
57 | private async addFollowing () { | ||
58 | const hostsOrHandles = splitAndGetNotEmpty(this.form.value['hostsOrHandles']) | ||
59 | |||
60 | this.followService.follow(hostsOrHandles).subscribe( | ||
61 | () => { | ||
62 | this.notifier.success($localize`Follow request(s) sent!`) | ||
63 | this.newFollow.emit() | ||
64 | }, | ||
65 | |||
66 | err => this.notifier.error(err.message) | ||
67 | ) | ||
68 | } | ||
69 | } | ||