update dashboard

This commit is contained in:
Kenta420-Poom 2023-09-21 15:57:35 +07:00
parent 325020fd37
commit 8228a4f46c
3 changed files with 211 additions and 22 deletions

View file

@ -2,19 +2,28 @@ import { Component, OnInit } from '@angular/core';
import { UserService } from 'src/app/core/services/user.service';
import { HttpClient } from '@angular/common/http';
import { User } from 'src/app/core/models/user.model';
import { NgIf } from '@angular/common';
import { NgFor, NgIf } from '@angular/common';
import { initFlowbite } from 'flowbite';
import { environment } from 'src/environments/environment';
import { delay } from 'rxjs';
import { Recipe } from 'src/app/core/models/recipe.model';
@Component({
selector: 'app-dashboard',
standalone: true,
imports: [NgIf],
imports: [NgIf, NgFor],
templateUrl: './dashboard.component.html',
})
export class DashboardComponent implements OnInit {
userInfo: User | null = null;
recipes: Recipe[] | null = null;
tableHeads: string[] = ['Name', 'Other Name', 'Description', 'Last Updated'];
isLoaded: boolean = false;
constructor(private _userService: UserService) {}
constructor(
private _userService: UserService,
private _httpClient: HttpClient
) {}
ngOnInit(): void {
initFlowbite();
@ -22,10 +31,15 @@ export class DashboardComponent implements OnInit {
this._userService.currentUser.subscribe((user) => {
this.userInfo = user;
});
}
logout() {
console.log('logout');
this._userService.logout();
this._httpClient
.get<{ Recipe01: Recipe[] }>(environment.api + '/recipes', {
withCredentials: true,
})
.subscribe(({ Recipe01 }) => {
this.recipes = Recipe01.slice(0, 10);
console.log(this.recipes);
this.isLoaded = true;
});
}
}