From 5400c5438d7d65e03a485da5cf17f6f4fac5e7b6 Mon Sep 17 00:00:00 2001 From: Chneemann Date: Fri, 15 Nov 2024 17:22:50 +0100 Subject: [PATCH] docs: add JSDoc comments to SidebarComponent --- .../sidebar-mobile.component.ts | 16 ++++++++++++++++ .../components/sidebar/sidebar.component.ts | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/app/shared/components/sidebar/sidebar-mobile/sidebar-mobile.component.ts b/src/app/shared/components/sidebar/sidebar-mobile/sidebar-mobile.component.ts index 994095f..bcec79d 100644 --- a/src/app/shared/components/sidebar/sidebar-mobile/sidebar-mobile.component.ts +++ b/src/app/shared/components/sidebar/sidebar-mobile/sidebar-mobile.component.ts @@ -15,10 +15,21 @@ export class SidebarMobileComponent { 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 { 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 { return ( 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() { this.router.events.subscribe((event) => { if (event instanceof NavigationEnd) { diff --git a/src/app/shared/components/sidebar/sidebar.component.ts b/src/app/shared/components/sidebar/sidebar.component.ts index be7375a..eb07007 100644 --- a/src/app/shared/components/sidebar/sidebar.component.ts +++ b/src/app/shared/components/sidebar/sidebar.component.ts @@ -23,14 +23,33 @@ export class SidebarComponent implements OnInit { 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 { 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() { 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() { this.router.events.subscribe((event) => { if (event instanceof NavigationEnd) {