1 | import { Component, OnInit } from '@angular/core';
|
---|
2 | import { FormControl } from '@angular/forms';
|
---|
3 | import { Router } from '@angular/router';
|
---|
4 | import { CategoryFacadeService } from 'src/app/core/state/category-facade.service';
|
---|
5 | import { QuestionFacadeService } from 'src/app/core/state/question-facade.service';
|
---|
6 | import { CategoryStateViewModel, PreviewQuestionsOrderEnum } from 'src/app/shared-app/models';
|
---|
7 |
|
---|
8 | @Component({
|
---|
9 | selector: 'app-questions-preview-general',
|
---|
10 | templateUrl: './questions-preview-general.component.html',
|
---|
11 | styleUrls: ['./questions-preview-general.component.scss']
|
---|
12 | })
|
---|
13 | export class QuestionsPreviewGeneralComponent implements OnInit {
|
---|
14 | categories?: CategoryStateViewModel[];
|
---|
15 | previewQuestions$ = this.questionFacade.getPreviewQuestionsLatest();
|
---|
16 | QuestionsSortBy = PreviewQuestionsOrderEnum;
|
---|
17 | questionsSortByForm = new FormControl(PreviewQuestionsOrderEnum.Latest);
|
---|
18 |
|
---|
19 | constructor(private categoriesFacade: CategoryFacadeService, private questionFacade: QuestionFacadeService, private router: Router) {}
|
---|
20 |
|
---|
21 | ngOnInit(): void {
|
---|
22 | this.categoriesFacade.fetchCategories();
|
---|
23 | this.questionFacade.fetchPreviewQuestions(PreviewQuestionsOrderEnum.Latest);
|
---|
24 | this.questionsSortByForm.valueChanges.subscribe((value: PreviewQuestionsOrderEnum) => {
|
---|
25 | this.questionFacade.fetchPreviewQuestions(value);
|
---|
26 |
|
---|
27 | if (value === PreviewQuestionsOrderEnum.Latest) {
|
---|
28 | this.previewQuestions$ = this.questionFacade.getPreviewQuestionsLatest();
|
---|
29 | } else if (value === PreviewQuestionsOrderEnum.Popular) {
|
---|
30 | this.previewQuestions$ = this.questionFacade.getPreviewQuestionsPopular();
|
---|
31 | }
|
---|
32 | });
|
---|
33 | }
|
---|
34 |
|
---|
35 | goToQuestion(uid: string): void {
|
---|
36 | this.router.navigateByUrl(`questioning/${uid}`);
|
---|
37 | }
|
---|
38 |
|
---|
39 | routeToSearch(): void {
|
---|
40 | this.router.navigateByUrl(`questioning/search`);
|
---|
41 | }
|
---|
42 | }
|
---|