mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
- Add @isa/core/logging to services and components with actions - Add comprehensive JSDoc documentation with @example blocks - Fix typo: TabsCollabsedService → TabsCollapsedService - Add error handling with try/catch for async operations - Add tap operator for logging in NetworkStatusService
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { Injectable, signal } from '@angular/core';
|
|
import { logger } from '@isa/core/logging';
|
|
|
|
/**
|
|
* Service for managing the navigation sidebar visibility state.
|
|
*
|
|
* Controls whether the sidebar navigation panel is open or closed,
|
|
* primarily used for responsive mobile/tablet layouts where the
|
|
* navigation can be toggled via a hamburger menu.
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* readonly navigationService = inject(NavigationService);
|
|
*
|
|
* // Check if navigation is open
|
|
* const isOpen = this.navigationService.get();
|
|
*
|
|
* // Toggle navigation
|
|
* this.navigationService.toggle();
|
|
*
|
|
* // Explicitly set state
|
|
* this.navigationService.set(false); // Close navigation
|
|
* ```
|
|
*/
|
|
@Injectable({ providedIn: 'root' })
|
|
export class NavigationService {
|
|
#logger = logger({ service: 'NavigationService' });
|
|
#state = signal<boolean>(false);
|
|
|
|
/** Readonly signal exposing the current navigation open/closed state. */
|
|
readonly get = this.#state.asReadonly();
|
|
|
|
/** Toggles the navigation state between open and closed. */
|
|
toggle(): void {
|
|
this.#state.update((state) => !state);
|
|
this.#logger.debug('Navigation toggled', () => ({ isOpen: this.#state() }));
|
|
}
|
|
|
|
/**
|
|
* Sets the navigation visibility state.
|
|
* @param state - True to open navigation, false to close
|
|
*/
|
|
set(state: boolean): void {
|
|
this.#logger.debug('Navigation state set', () => ({ state }));
|
|
this.#state.set(state);
|
|
}
|
|
}
|