import { Component, OnInit } from '@angular/core';
import Parse from 'parse';


@Component({
  selector: 'app-article-one',
  templateUrl: './articleone.component.html',
  styleUrls: ['./articleone.component.scss']
})
export class ArticleOneComponent  implements OnInit{
  storiesData: any[] = []; // 给变量一个初始值
  titlesData: any[] = []; // 给变量一个初始值
  authorsData: any[] = []; // 给变量一个初始值
  datesData: any[] = []; // 给变量一个初始值

  constructor() { }

  ngOnInit(): void {
    const Jht430 = Parse.Object.extend('Jht430');
    const query = new Parse.Query(Jht430);

    query.get('ulwYEwd0Xw').then((result) => {
      this.storiesData = result.get('stories');
    }).catch((error) => {
      console.error('Error retrieving stories data: ', error);
    });

    query.get('ulwYEwd0Xw').then((result) => {
      this.titlesData = result.get('titles');
    }).catch((error) => {
      console.error('Error retrieving titles data: ', error);
    });

    query.get('ulwYEwd0Xw').then((result) => {
      this.authorsData = result.get('authors');
    }).catch((error) => {
      console.error('Error retrieving authors data: ', error);
    });
 
    query.get('ulwYEwd0Xw').then((result) => {
      this.datesData = result.get('dates');
    }).catch((error) => {
      console.error('Error retrieving dates data: ', error);
    });
  }

  comments = [
    { user: '阿平', avatar: '../../assets/images/passerby1.jpg', message: '哇塞' },
    { user: '明天在不在', avatar: '../../assets/images/passerby2.jpg', message: '啊啊啊啊啊啊啊啊啊啊啊' },
    { user: '无敌暴龙', avatar: '../../assets/images/passerby3.jpg', message: '在哪里？' }
  ];
  newComment: string = '';

  addComment() {
    if (this.newComment) {
      const newComment = {
        user: '我',
        avatar: '../../assets/images/slide1.jpg',
        message: this.newComment
      };
      this.comments.push(newComment);
      this.newComment = '';
    }
  }

}

