import { Component } from '@angular/core';
import { Router } from '@angular/router';
import * as Parse from "parse";

@Component({
  selector: 'app-page-add',
  templateUrl: './page-add.component.html',
  styleUrls: ['./page-add.component.scss']
})
export class PageAddComponent {
  userAdd: any = {
    name: '',
    tag: '',
    desc: ''
  };

  constructor(
    private router: Router
  ) {}

  async saveAdd() {
    const Contact = Parse.Object.extend('Contact');
    const newContact = new Contact();

    newContact.set('name', this.userAdd.name);
    newContact.set('tag', this.userAdd.tag);
    newContact.set('desc', this.userAdd.desc);
    // 设置其他联系人信息...

    try {
      await newContact.save();
      console.log('New contact saved successfully');
      this.router.navigate(['/lesson/me/userFollow']); // 导航到联系人列表页面
    } catch (error) {
      console.error('Error while saving new contact', error);
    }
  }
}