source: src/Clients/Angular/finki-chattery/src/app/modules/questioning/components/questions-preview-general/questions-preview-general.component.ts@ a3b5f34

dev
Last change on this file since a3b5f34 was a3b5f34, checked in by Стојков Марко <mst@…>, 3 years ago

Searching questions

  • Property mode set to 100644
File size: 1.8 KB
Line 
1import { Component, OnInit } from '@angular/core';
2import { FormControl } from '@angular/forms';
3import { Router } from '@angular/router';
4import { CategoryFacadeService } from 'src/app/core/state/category-facade.service';
5import { QuestionFacadeService } from 'src/app/core/state/question-facade.service';
6import { 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})
13export 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}
Note: See TracBrowser for help on using the repository browser.