Display discussions from backend

This commit is contained in:
Michał Romaszkin 2020-06-13 23:58:50 +02:00
parent 0a2f3e67b7
commit 13ecb753a5
4 changed files with 21 additions and 44 deletions

View File

@ -4,42 +4,15 @@ import { ForumData } from '../_interfaces/forumdata';
@Injectable() @Injectable()
export class SharedDataService { export class SharedDataService {
private dataBS: BehaviorSubject<ForumData | any> = new BehaviorSubject({}); private dataBS: BehaviorSubject<any> = new BehaviorSubject(null);
private json = `
{
"id": "1",
"name": "Kurs 1",
"discussion": [
{
"title": "test123",
"id": "1",
"first_post": "0"
},
{
"title": "dupa321",
"id": "2",
"first_post": "2"
},
{
"title": "TEST",
"id": "3",
"first_post": "10"
}
]
}`;
constructor() {} constructor() {}
public setData(value: any): void { public setData(value: string) {
/* this.dataBS.next(value);
* this.dataBS.next(value);
*/
/* For testing purposes only */
const obj = JSON.parse(this.json);
this.dataBS.next(obj);
} }
public getData() { public getData(): Observable<string> {
return new Observable((fn) => this.dataBS.subscribe(fn)); return this.dataBS.asObservable();
} }
} }

View File

@ -37,11 +37,9 @@ export class FrontPageComponent {
} }
sendFile(event: any): void { sendFile(event: any): void {
// this.sendDataService.postFile(this.file).subscribe((res: any) => { this.sendDataService.postFile(this.file).subscribe((res: any) => {
// this.sharedDataService.setData(res); this.sharedDataService.setData(res);
// }); this.router.navigate(['/view']);
/* For testing */ });
this.sharedDataService.setData('test');
this.router.navigate(['/view']);
} }
} }

View File

@ -1,7 +1,9 @@
<div class="picker-container"> <div class="picker-container" *ngIf="data">
<h1>Wybierz dyskusję z {{ data.name }}:</h1> <h1>
Wybierz dyskusję z <i>{{ data.name }}:</i>
</h1>
<nb-card <nb-card
*ngFor="let item of data.discussion" *ngFor="let item of data.discussions"
class="picker-container__discussion" class="picker-container__discussion"
[accent]="getRandomColor()" [accent]="getRandomColor()"
> >

View File

@ -3,6 +3,7 @@ import {
OnInit, OnInit,
OnDestroy, OnDestroy,
ChangeDetectionStrategy, ChangeDetectionStrategy,
AfterContentInit,
} from '@angular/core'; } from '@angular/core';
import { SharedDataService } from '../../_services/shared-data.service'; import { SharedDataService } from '../../_services/shared-data.service';
import { Colors } from '../../_types/color'; import { Colors } from '../../_types/color';
@ -11,11 +12,10 @@ import { Subscription } from 'rxjs';
interface CustomForumData { interface CustomForumData {
id: string; id: string;
name: string; name: string;
discussion: [ discussions: [
{ {
title: string; title: string;
id: string; id: string;
first_post: string;
} }
]; ];
} }
@ -35,7 +35,11 @@ export class DiscussionChooserComponent implements OnInit, OnDestroy {
ngOnInit(): void { ngOnInit(): void {
this.dataSub = this.sharedDataService.getData().subscribe((res) => { this.dataSub = this.sharedDataService.getData().subscribe((res) => {
this.data = res as CustomForumData; if (res) {
const obj = JSON.parse(res as string);
this.data = obj as CustomForumData;
console.log(this.data);
}
}); });
} }