Newer
Older
Website / src / app / home / home.component.ts
@lukas lukas on 5 Apr 962 bytes add user statuses
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { environment } from 'src/environments/environment';

class UserStatus {
  constructor(public user: string, public message: string) {}
}

class UserStatusAnswer {
  constructor(public success: boolean = false, public userStatuses: UserStatus[] = []) {}
}

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
  userStatuses: UserStatus[] = []
  loading = true

  constructor(private http: HttpClient) { }

  ngOnInit(): void {
    this.http.get(`${environment.apiURL}/users/status`).subscribe((answer) => {
      var userStatusAnswer = Object.assign(new UserStatusAnswer(), answer)
      this.loading = !userStatusAnswer.success
      if (!this.loading) {
        this.userStatuses = userStatusAnswer.userStatuses
      }
    }
    )
  }
}