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
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { Injectable, signal } from '@angular/core';
|
|
import { logger } from '@isa/core/logging';
|
|
|
|
/**
|
|
* Service for managing the collapsed/expanded state of the shell tabs bar.
|
|
*
|
|
* The tabs bar can switch between compact (collapsed) and expanded modes
|
|
* based on user proximity. This service provides a centralized state
|
|
* that can be accessed by both the tabs component and the shell layout.
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* readonly tabsCollapsed = inject(TabsCollapsedService);
|
|
*
|
|
* // Read current state
|
|
* const isCollapsed = this.tabsCollapsed.get();
|
|
*
|
|
* // Set state
|
|
* this.tabsCollapsed.set(true);
|
|
*
|
|
* // Toggle state
|
|
* this.tabsCollapsed.toggle();
|
|
* ```
|
|
*/
|
|
@Injectable({ providedIn: 'root' })
|
|
export class TabsCollapsedService {
|
|
#logger = logger({ service: 'TabsService' });
|
|
#state = signal<boolean>(false);
|
|
|
|
/** Readonly signal exposing the current collapsed state. */
|
|
readonly get = this.#state.asReadonly();
|
|
|
|
/** Toggles the collapsed state between true and false. */
|
|
toggle(): void {
|
|
this.#state.update((state) => !state);
|
|
this.#logger.debug('Tabs toggled', () => ({ isOpen: this.#state() }));
|
|
}
|
|
|
|
/**
|
|
* Sets the collapsed state to a specific value.
|
|
* No-op if the state is already equal to the provided value.
|
|
*
|
|
* @param state - The new collapsed state (true = collapsed, false = expanded)
|
|
*/
|
|
set(state: boolean): void {
|
|
if (this.#state() === state) {
|
|
return;
|
|
}
|
|
|
|
this.#logger.debug('Tabs state set', () => ({ state }));
|
|
this.#state.set(state);
|
|
}
|
|
}
|