1 | import { Component, OnInit } from '@angular/core';
|
---|
2 | import { FormControl, FormGroup, Validators } from '@angular/forms';
|
---|
3 | import { Router } from '@angular/router';
|
---|
4 |
|
---|
5 | import { CategoryFacadeService } from 'src/app/core/state/category-facade.service';
|
---|
6 | import { ButtonType } from 'src/app/shared-app/components/generic/button/button.models';
|
---|
7 | import { AskQuestionRequest } from '../../models/questioning-request.models';
|
---|
8 | import { QuestioningApiService } from '../../services/questioning-api.service';
|
---|
9 |
|
---|
10 | @Component({
|
---|
11 | selector: 'app-ask-question',
|
---|
12 | templateUrl: './ask-question.component.html',
|
---|
13 | styleUrls: ['./ask-question.component.scss']
|
---|
14 | })
|
---|
15 | export class AskQuestionComponent implements OnInit {
|
---|
16 | public titleForm = new FormControl('', [Validators.required, Validators.maxLength(500)]);
|
---|
17 | public textForm = new FormControl('', [Validators.required, Validators.maxLength(4000)]);
|
---|
18 | public categoriesForm = new FormControl([]);
|
---|
19 | public questionFormGroup: FormGroup;
|
---|
20 | public ButtonType = ButtonType;
|
---|
21 | public categoriesList$ = this.categoriesFacade.getCategories();
|
---|
22 |
|
---|
23 | constructor(private api: QuestioningApiService, private categoriesFacade: CategoryFacadeService, private router: Router) {
|
---|
24 | this.questionFormGroup = new FormGroup({
|
---|
25 | title: this.titleForm,
|
---|
26 | text: this.textForm,
|
---|
27 | categories: this.categoriesForm
|
---|
28 | });
|
---|
29 | }
|
---|
30 |
|
---|
31 | ngOnInit(): void {}
|
---|
32 |
|
---|
33 | public askQuestion(): void {
|
---|
34 | const body = new AskQuestionRequest(this.titleForm.value, this.textForm.value, this.categoriesForm.value);
|
---|
35 | this.api.askQuestion(body).subscribe((questionUid) => {
|
---|
36 | this.router.navigateByUrl(`questioning/${questionUid}`);
|
---|
37 | });
|
---|
38 | }
|
---|
39 | }
|
---|