Refactor application structure to use WorkspaceService for state management
- Removed direct state management from components and centralized it in WorkspaceService. - Updated ApartmentsPage, TenantsPage, LeasesPage, and DashboardPage to utilize WorkspaceService for data handling. - Introduced SessionService to manage user session state and authentication. - Simplified component templates to reflect new service-based architecture. - Removed unused ConfigService and its tests. - Added lease.html template for lease document generation. - Created app.routes.spec.ts for route mapping tests.
This commit is contained in:
1 parent
be1f680a62
commit
82f339e209
33 files changed
+292
-929
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable, inject, signal } from '@angular/core';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class SessionService {
|
||||
private readonly http = inject(HttpClient);
|
||||
readonly isLoggedIn = signal(false);
|
||||
readonly username = signal('');
|
||||
readonly email = signal('');
|
||||
|
||||
refresh(): void {
|
||||
this.http.get<{ authenticated: boolean; username?: string; email?: string }>('/api/user').subscribe({
|
||||
next: (user) => {
|
||||
this.isLoggedIn.set(user.authenticated);
|
||||
this.username.set(user.authenticated ? (user.username || 'User') : '');
|
||||
this.email.set(user.authenticated ? (user.email || '') : '');
|
||||
},
|
||||
error: () => {
|
||||
this.isLoggedIn.set(false);
|
||||
this.username.set('');
|
||||
this.email.set('');
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user