Warn editors before their session expires
Angular · Angular · beginner · modification
Adds a session-expiry banner to the editor page. `SessionBannerComponent` keeps the current time in a signal that an RxJS `interval` updates once a second, derives the time left from `SessionService.expiresAt()`, and shows a countdown in the last five minutes, then an expired message. Screen readers get one announcement per state change through a status region instead of the ticking countdown. `EditorPageComponent` renders the banner above the editor.
Angular 21 app: standalone components, signals, zoneless change detection (`provideZonelessChangeDetection()` in `app.config.ts`, unchanged). `SessionService` (`src/app/core/session.service.ts`, `providedIn: 'root'`, unchanged) exposes `expiresAt: Signal<number>`, the session's expiry time in epoch milliseconds, already on the device clock; it moves later when the session is extended. `EditorPageComponent` is the routed component for `/docs/:id/edit`; the router creates it on every visit and destroys it (and the banner inside it) when the user navigates away, since the app has no route reuse strategy. `DocumentEditorComponent` is unchanged. Colours are the theme tokens from `styles.scss`; the app has no global visually-hidden class, so the component defines its own.
Requirements
- The editor page (`EditorPageComponent`, route `/docs/:id/edit`) shows a banner above the editor when the session has less than 5 minutes left: "Your session expires in M:SS. Save your work.", counting down once a second (minutes and seconds left, rounded down, so `0:00` shows during the last second). Once the session has expired it reads "Your session has expired. Sign in again to keep working." With 5 minutes or more left there is no banner.
- The time left is `SessionService.expiresAt()` minus the device clock (`Date.now()`). When the session is extended (`expiresAt` moves later), the banner goes away until the session is again in its last 5 minutes.
- Screen readers do not hear the per-second countdown. A status region that is in the component from the start (not created with the banner) says "Your session expires in less than 5 minutes. Save your work." each time the session enters its last 5 minutes and the expired message when it expires; its text does not change in between. When the page opens already in the last 5 minutes or after expiry, the region simply starts with that message; no announcement is required on page open.
- The banner's once-a-second work belongs to the editor page: when the user leaves the page and the banner is destroyed, its timer stops. People move between the document list and the editor dozens of times a day in the same tab, so nothing the banner starts may keep running after it is gone.
- Unchanged: the editor itself (`DocumentEditorComponent`) and the rest of the page.
Files touched
- src/app/editor/editor-page.component.ts
- src/app/session/session-banner.component.ts