import { Component, OnInit } from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {DataloaderService} from '../../services/dataloader.service';
import {Post} from '../../model/post';
import {StateService} from '../../services/state.service';

@Component({
  selector: 'app-fullpost',
  templateUrl: './fullpost.component.html',
  styleUrls: ['./fullpost.component.scss']
})
export class FullpostComponent implements OnInit {

  post: Post;

  constructor(private route: ActivatedRoute, private dataloaderService: DataloaderService, private stateService: StateService) { }

  ngOnInit() {
    //get the id of the post from the route
    this.route.paramMap.subscribe(params=>{
      let id = params.get('id');
      console.log('the fullpost component gets id: '+id);

      //fetch the posts and make sure you get the right one
      this.dataloaderService.getPosts().subscribe(posts => {
        posts.forEach(post=>{
          if(post.id = id) {
            this.post = post;
          }
        });
      });
    });
  }

}
