Merge branches 'main' and 'main' of https://github.com/Poomipat-Ch/taobin_recipe_manager
This commit is contained in:
commit
503186e733
2 changed files with 32 additions and 4 deletions
|
|
@ -22,14 +22,13 @@
|
||||||
{{ user.username }}
|
{{ user.username }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="relative">
|
<div class="relative" #dropdownMenu>
|
||||||
<img
|
<img
|
||||||
class="h-16 rounded-full cursor-pointer"
|
class="h-16 rounded-full cursor-pointer"
|
||||||
src="{{ user.image }}"
|
src="{{ user.image }}"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
alt="profile picture"
|
alt="profile picture"
|
||||||
(click)="toggleDropdown()"
|
(click)="toggleDropdown()"
|
||||||
[class.open]="isMenuOpen"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Dropdown Items -->
|
<!-- Dropdown Items -->
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,13 @@
|
||||||
import { DatePipe, NgIf } from '@angular/common';
|
import { DatePipe, NgIf } from '@angular/common';
|
||||||
import { Component, OnInit } from '@angular/core';
|
import {
|
||||||
|
AfterViewInit,
|
||||||
|
ChangeDetectorRef,
|
||||||
|
Component,
|
||||||
|
ElementRef,
|
||||||
|
HostListener,
|
||||||
|
OnInit,
|
||||||
|
ViewChild,
|
||||||
|
} from '@angular/core';
|
||||||
import { User } from '../models/user.model';
|
import { User } from '../models/user.model';
|
||||||
import { GoogleButtonComponent } from 'src/app/shared/googleButton/googleButton.component';
|
import { GoogleButtonComponent } from 'src/app/shared/googleButton/googleButton.component';
|
||||||
import { UserService } from '../services/user.service';
|
import { UserService } from '../services/user.service';
|
||||||
|
|
@ -14,15 +22,36 @@ export class HeaderComponent implements OnInit {
|
||||||
user: User | null = null;
|
user: User | null = null;
|
||||||
date: Date = new Date();
|
date: Date = new Date();
|
||||||
isMenuOpen = false;
|
isMenuOpen = false;
|
||||||
|
@ViewChild('dropdownMenu') dropdownMenu: ElementRef | undefined;
|
||||||
|
|
||||||
constructor(private userService: UserService) {}
|
constructor(
|
||||||
|
private userService: UserService,
|
||||||
|
private changeDetector: ChangeDetectorRef
|
||||||
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.userService.currentUser.subscribe((user) => (this.user = user));
|
this.userService.currentUser.subscribe((user) => (this.user = user));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@HostListener('document:click', ['$event'])
|
||||||
|
handleDocumentClick(event: Event) {
|
||||||
|
if (!this.dropdownMenu) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const targetNode = event.target as Node;
|
||||||
|
if (this.dropdownMenu.nativeElement.contains(targetNode)) {
|
||||||
|
// Click occurred inside the dropdown, do nothing
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Click occurred outside the dropdown, close it
|
||||||
|
this.isMenuOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
toggleDropdown() {
|
toggleDropdown() {
|
||||||
this.isMenuOpen = !this.isMenuOpen;
|
this.isMenuOpen = !this.isMenuOpen;
|
||||||
|
this.changeDetector.detectChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
logout(): void {
|
logout(): void {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue