diff --git a/client/src/app/user-doorboard/user-doorboard.component.html b/client/src/app/user-doorboard/user-doorboard.component.html new file mode 100644 index 0000000..e69de29 diff --git a/client/src/app/user-doorboard/user-doorboard.component.scss b/client/src/app/user-doorboard/user-doorboard.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/client/src/app/user-doorboard/user-doorboard.component.spec.ts b/client/src/app/user-doorboard/user-doorboard.component.spec.ts new file mode 100644 index 0000000..e69de29 diff --git a/client/src/app/user-doorboard/user-doorboard.component.ts b/client/src/app/user-doorboard/user-doorboard.component.ts new file mode 100644 index 0000000..dcadb39 --- /dev/null +++ b/client/src/app/user-doorboard/user-doorboard.component.ts @@ -0,0 +1,47 @@ +import { Component, OnInit, OnDestroy} from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { User } from '../user'; +import { UserService } from '../user.service'; +import { Subscription } from 'rxjs'; +import { Note } from '../note'; +import { NotesService } from '../notes.service'; + + +@Component({ + selector: 'app-user-doorboard', + templateUrl: './user-doorboard.component.html', + styleUrls: ['./user-doorboard.component.scss'] +}) +// starting structure taken from https://github.com/UMM-CSci-3601-S20/it-1-knights-who-say-ni + +// This class has access to the user of the doorboard, and all the notes that said user has made +export class UserDoorBoardComponent implements OnInit, OnDestroy { + constructor(private route: ActivatedRoute, private notesService: NotesService, + private userService: UserService) { } + notes: Note[]; + user: User; + id: string; + getNotesSub: Subscription; + getUserSub: Subscription; + ngOnInit(): void { + // We subscribe to the parameter map here so we'll be notified whenever + // that changes (i.e., when the URL changes) so this component will update + // to display the newly requested user. + this.route.paramMap.subscribe((pmap) => { + this.id = pmap.get('id'); + this.getUserSub = this.userService.getUserById(this.id).subscribe(user => this.user = user); + this.getNotesSub = this.notesService.getUserNotes({ user_id: this.id }).subscribe(notes => this.notes = notes.reverse()); + + }); + } + + ngOnDestroy(): void { + if (this.getNotesSub) { + this.getNotesSub.unsubscribe(); + } + if (this.getUserSub) { + this.getUserSub.unsubscribe(); + } + } + +} diff --git a/client/src/app/user-service.spec.ts b/client/src/app/user.service.spec.ts similarity index 97% rename from client/src/app/user-service.spec.ts rename to client/src/app/user.service.spec.ts index f2751b6..5fe84d2 100644 --- a/client/src/app/user-service.spec.ts +++ b/client/src/app/user.service.spec.ts @@ -3,7 +3,7 @@ import { HttpClientTestingModule, HttpTestingController } from '@angular/common/ import { TestBed } from '@angular/core/testing'; import { User } from './user'; import { NotesService } from './notes.service'; -import { UserService } from './user-service'; +import { UserService } from './user.service'; describe('Note service:', () => { // pulled these from https://github.com/UMM-CSci-3601-S20/it-1-knights-who-say-ni diff --git a/client/src/app/user-service.ts b/client/src/app/user.service.ts similarity index 81% rename from client/src/app/user-service.ts rename to client/src/app/user.service.ts index a8fff96..de9fbec 100644 --- a/client/src/app/user-service.ts +++ b/client/src/app/user.service.ts @@ -5,9 +5,7 @@ import { User } from './user'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; -@Injectable({ - providedIn: 'root' -}) +@Injectable() export class UserService { @@ -19,6 +17,11 @@ export class UserService { return this.httpClient.get(this.userUrl); } + // needed for getting the user doorboards (we grab the user id from the url, and we need to get the actual user from that as well) + getUserById() { + return null; + } + // adding stub addUser(newUser: User): Observable { return null;