docs: add JSDoc comments to SidebarComponent

This commit is contained in:
Chneemann 2024-11-15 17:22:50 +01:00
parent d2f9734b83
commit 5400c5438d
2 changed files with 35 additions and 0 deletions

View file

@ -15,10 +15,21 @@ export class SidebarMobileComponent {
constructor(private router: Router) {} constructor(private router: Router) {}
/**
* Lifecycle hook that is called after the component has been initialized.
*
* Calls the getCurrentPath method to set the currentPath property to the current route's url.
*/
ngOnInit(): void { ngOnInit(): void {
this.getCurrentPath(); this.getCurrentPath();
} }
/**
* Returns true if the current route is one of the add-task routes (add-task, add-task/none, add-task/todo, add-task/inprogress, add-task/awaitfeedback, add-task/done).
*
* This is used to conditionally render the add-task button in the sidebar.
* @returns true if the current route is one of the add-task routes, false otherwise.
*/
isAddTask(): boolean { isAddTask(): boolean {
return ( return (
this.currentPath === 'add-task' || this.currentPath === 'add-task' ||
@ -30,6 +41,11 @@ export class SidebarMobileComponent {
); );
} }
/**
* Subscribes to router events and updates the currentPath property
* with the current route's URL, excluding the leading slash, whenever
* a navigation ends.
*/
getCurrentPath() { getCurrentPath() {
this.router.events.subscribe((event) => { this.router.events.subscribe((event) => {
if (event instanceof NavigationEnd) { if (event instanceof NavigationEnd) {

View file

@ -23,14 +23,33 @@ export class SidebarComponent implements OnInit {
private firebaseService: FirebaseService private firebaseService: FirebaseService
) {} ) {}
/**
* Lifecycle hook that is called after the component has been initialized.
*
* Calls the getCurrentPath method to set the currentPath property to the current route's url.
*/
ngOnInit(): void { ngOnInit(): void {
this.getCurrentPath(); this.getCurrentPath();
} }
/**
* Logs out the current user and navigates to the login page.
*
* Calls the logout method of the LoginService with the current user ID as
* its argument. This will remove the user ID from the local storage and
* perform any other necessary cleanup operations.
*
* The user is then navigated to the login page.
*/
logout() { logout() {
this.loginService.logout(this.firebaseService.getCurrentUserId()); this.loginService.logout(this.firebaseService.getCurrentUserId());
} }
/**
* Subscribes to router events and updates the currentPath property
* with the current route's URL, excluding the leading slash, whenever
* a navigation ends.
*/
getCurrentPath() { getCurrentPath() {
this.router.events.subscribe((event) => { this.router.events.subscribe((event) => {
if (event instanceof NavigationEnd) { if (event instanceof NavigationEnd) {