unoffical wafrn mirror
wafrn.net
atproto
social-network
activitypub
1import { Component, computed, signal, inject } from '@angular/core'
2import { MatButtonModule } from '@angular/material/button'
3import { MatCheckboxChange, MatCheckboxModule } from '@angular/material/checkbox'
4import {
5 MatDialogActions,
6 MatDialogTitle,
7 MatDialogContent,
8 MatDialogRef,
9 MAT_DIALOG_DATA
10} from '@angular/material/dialog'
11import { MatInputModule } from '@angular/material/input'
12import { MatSelectModule } from '@angular/material/select'
13import { TranslatePipe } from '@ngx-translate/core'
14import { ProcessedPost } from 'src/app/interfaces/processed-post'
15import { UserReport } from 'src/app/interfaces/report'
16import { KeyValueTypedPipe } from 'src/app/pipes/keyvaluetyped.pipe'
17
18export type ReportDialogData = { type: 'post'; post: ProcessedPost } | { type: 'user'; userId: string }
19
20@Component({
21 selector: 'app-report-post',
22 templateUrl: './report-post.component.html',
23 styleUrls: ['./report-post.component.scss'],
24 imports: [
25 MatInputModule,
26 MatSelectModule,
27 MatCheckboxModule,
28 MatButtonModule,
29 MatDialogActions,
30 MatDialogTitle,
31 MatDialogContent,
32 TranslatePipe,
33 KeyValueTypedPipe
34 ]
35})
36export class ReportPostComponent {
37 private readonly dialogRef = inject<MatDialogRef<ReportPostComponent, UserReport | undefined>>(MatDialogRef);
38 data = inject<ReportDialogData>(MAT_DIALOG_DATA);
39
40 formValid = computed<boolean>(() => this.reportSeverity() !== null && this.reportDescription().length > 0)
41 postId: string | undefined
42 userId: string
43
44 reportSeverity = signal<number | null>(null)
45 reportDescription = signal<string>('')
46
47 blockUser = false
48
49 reportOptions: Record<number, string> = {
50 1: 'Spam',
51 3: 'Unlabeled NSFW',
52 5: 'Inciting hate against a person or collective',
53 10: 'Illegal content'
54 }
55
56 constructor() {
57 const data = this.data;
58
59 this.postId = data.type === 'post' ? data.post.id : undefined
60 this.userId = data.type === 'user' ? data.userId : data.post.userId
61 }
62
63 onInput(event: Event) {
64 const target = event.target
65 if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement) {
66 this.reportDescription.set(target.value)
67 }
68 }
69
70 onCheck(event: MatCheckboxChange) {
71 this.blockUser = event.checked
72 }
73
74 onCancel() {
75 this.dialogRef.close(undefined)
76 }
77
78 onConfirm() {
79 const report: UserReport & { block: boolean } = {
80 postId: this.postId,
81 userId: this.userId,
82 severity: this.reportSeverity() as number,
83 description: this.reportDescription(),
84 block: this.blockUser
85 }
86 this.dialogRef.close(report)
87 }
88}