diff --git a/frontend/src/app/_services/shared-data.service.ts b/frontend/src/app/_services/shared-data.service.ts index 1b49f95..598139d 100644 --- a/frontend/src/app/_services/shared-data.service.ts +++ b/frontend/src/app/_services/shared-data.service.ts @@ -4,42 +4,15 @@ import { ForumData } from '../_interfaces/forumdata'; @Injectable() export class SharedDataService { - private dataBS: BehaviorSubject = 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 = 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 { + return this.dataBS.asObservable(); } } diff --git a/frontend/src/app/front-page/front-page.component.ts b/frontend/src/app/front-page/front-page.component.ts index 2cc8fab..2e56493 100644 --- a/frontend/src/app/front-page/front-page.component.ts +++ b/frontend/src/app/front-page/front-page.component.ts @@ -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']); + }); } } diff --git a/frontend/src/app/main-view/discussion-chooser/discussion-chooser.component.html b/frontend/src/app/main-view/discussion-chooser/discussion-chooser.component.html index 5d0b550..7849762 100644 --- a/frontend/src/app/main-view/discussion-chooser/discussion-chooser.component.html +++ b/frontend/src/app/main-view/discussion-chooser/discussion-chooser.component.html @@ -1,7 +1,9 @@ -
-

Wybierz dyskusjÄ™ z {{ data.name }}:

+
+

+ Wybierz dyskusjÄ™ z {{ data.name }}: +

diff --git a/frontend/src/app/main-view/discussion-chooser/discussion-chooser.component.ts b/frontend/src/app/main-view/discussion-chooser/discussion-chooser.component.ts index 0b09f16..102287f 100644 --- a/frontend/src/app/main-view/discussion-chooser/discussion-chooser.component.ts +++ b/frontend/src/app/main-view/discussion-chooser/discussion-chooser.component.ts @@ -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); + } }); }