Display discussions from backend
This commit is contained in:
parent
0a2f3e67b7
commit
13ecb753a5
@ -4,42 +4,15 @@ import { ForumData } from '../_interfaces/forumdata';
|
||||
|
||||
@Injectable()
|
||||
export class SharedDataService {
|
||||
private dataBS: BehaviorSubject<ForumData | any> = new BehaviorSubject({});
|
||||
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"
|
||||
}
|
||||
]
|
||||
}`;
|
||||
private dataBS: BehaviorSubject<any> = new BehaviorSubject(null);
|
||||
|
||||
constructor() {}
|
||||
|
||||
public setData(value: any): void {
|
||||
/*
|
||||
* this.dataBS.next(value);
|
||||
*/
|
||||
/* For testing purposes only */
|
||||
const obj = JSON.parse(this.json);
|
||||
this.dataBS.next(obj);
|
||||
public setData(value: string) {
|
||||
this.dataBS.next(value);
|
||||
}
|
||||
|
||||
public getData() {
|
||||
return new Observable((fn) => this.dataBS.subscribe(fn));
|
||||
public getData(): Observable<string> {
|
||||
return this.dataBS.asObservable();
|
||||
}
|
||||
}
|
||||
|
@ -37,11 +37,9 @@ export class FrontPageComponent {
|
||||
}
|
||||
|
||||
sendFile(event: any): void {
|
||||
// this.sendDataService.postFile(this.file).subscribe((res: any) => {
|
||||
// this.sharedDataService.setData(res);
|
||||
// });
|
||||
/* For testing */
|
||||
this.sharedDataService.setData('test');
|
||||
this.router.navigate(['/view']);
|
||||
this.sendDataService.postFile(this.file).subscribe((res: any) => {
|
||||
this.sharedDataService.setData(res);
|
||||
this.router.navigate(['/view']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
<div class="picker-container">
|
||||
<h1>Wybierz dyskusję z {{ data.name }}:</h1>
|
||||
<div class="picker-container" *ngIf="data">
|
||||
<h1>
|
||||
Wybierz dyskusję z <i>{{ data.name }}:</i>
|
||||
</h1>
|
||||
<nb-card
|
||||
*ngFor="let item of data.discussion"
|
||||
*ngFor="let item of data.discussions"
|
||||
class="picker-container__discussion"
|
||||
[accent]="getRandomColor()"
|
||||
>
|
||||
|
@ -3,6 +3,7 @@ import {
|
||||
OnInit,
|
||||
OnDestroy,
|
||||
ChangeDetectionStrategy,
|
||||
AfterContentInit,
|
||||
} from '@angular/core';
|
||||
import { SharedDataService } from '../../_services/shared-data.service';
|
||||
import { Colors } from '../../_types/color';
|
||||
@ -11,11 +12,10 @@ import { Subscription } from 'rxjs';
|
||||
interface CustomForumData {
|
||||
id: string;
|
||||
name: string;
|
||||
discussion: [
|
||||
discussions: [
|
||||
{
|
||||
title: string;
|
||||
id: string;
|
||||
first_post: string;
|
||||
}
|
||||
];
|
||||
}
|
||||
@ -35,7 +35,11 @@ export class DiscussionChooserComponent implements OnInit, OnDestroy {
|
||||
|
||||
ngOnInit(): void {
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user