11import { Component , HostBinding , OnInit } from '@angular/core' ;
22import { GlobeViewComponent } from './globe-view/globe-view.component' ;
3+ import type { GlobeRadioSelection } from './radio.models' ;
34import type { GlobeStreamPoint } from './stream.models' ;
45import { StreamSidebarComponent } from './stream-sidebar/stream-sidebar.component' ;
56
@@ -11,24 +12,39 @@ import { StreamSidebarComponent } from './stream-sidebar/stream-sidebar.componen
1112} )
1213export class AppComponent implements OnInit {
1314 selectedStream : GlobeStreamPoint | null = null ;
15+ selectedRadio : GlobeRadioSelection | null = null ;
1416 /** True while dragging the sidebar width — globe width must not ease */
1517 sidebarPanelResizing = false ;
1618 /** Pixels reserved on the right for the fixed sidebar; drives globe host width */
1719 @HostBinding ( 'style.--sidebar-inset.px' )
1820 sidebarInsetPx = 0 ;
1921 /** From `?stream=` on first load; globe selects + focuses after streams load */
2022 initialStreamQuery : string | null = null ;
23+ initialRadioQuery : string | null = null ;
24+
25+ get sidebarOpen ( ) : boolean {
26+ return this . selectedStream !== null || this . selectedRadio !== null ;
27+ }
2128
2229 ngOnInit ( ) : void {
2330 if ( typeof window === 'undefined' ) return ;
24- const raw = new URL ( window . location . href ) . searchParams . get ( 'stream' ) ;
25- this . initialStreamQuery = raw ?. trim ( ) ? raw . trim ( ) : null ;
31+ const u = new URL ( window . location . href ) ;
32+ const rawStream = u . searchParams . get ( 'stream' ) ;
33+ const rawRadio = u . searchParams . get ( 'radio' ) ;
34+ this . initialStreamQuery = rawStream ?. trim ( ) ? rawStream . trim ( ) : null ;
35+ this . initialRadioQuery = rawRadio ?. trim ( ) ? rawRadio . trim ( ) : null ;
2636 }
2737
2838 onStreamSelected ( stream : GlobeStreamPoint ) : void {
2939 this . selectedStream = stream ;
3040 this . sidebarInsetPx = 640 ;
31- this . syncStreamQueryParam ( ) ;
41+ this . syncUrlQueryParams ( ) ;
42+ }
43+
44+ onRadioSelected ( sel : GlobeRadioSelection ) : void {
45+ this . selectedRadio = sel ;
46+ this . sidebarInsetPx = 640 ;
47+ this . syncUrlQueryParams ( ) ;
3248 }
3349
3450 /** Start of close animation: globe expands while panel slides off */
@@ -38,21 +54,27 @@ export class AppComponent implements OnInit {
3854
3955 onSidebarClosed ( ) : void {
4056 this . selectedStream = null ;
41- this . syncStreamQueryParam ( ) ;
57+ this . selectedRadio = null ;
58+ this . syncUrlQueryParams ( ) ;
4259 }
4360
4461 onSidebarLayoutWidth ( px : number ) : void {
4562 this . sidebarInsetPx = Math . max ( 0 , Math . round ( px ) ) ;
4663 }
4764
48- private syncStreamQueryParam ( ) : void {
65+ private syncUrlQueryParams ( ) : void {
4966 if ( typeof window === 'undefined' ) return ;
5067 const u = new URL ( window . location . href ) ;
5168 if ( this . selectedStream ?. channelLogin ) {
5269 u . searchParams . set ( 'stream' , this . selectedStream . channelLogin ) ;
5370 } else {
5471 u . searchParams . delete ( 'stream' ) ;
5572 }
73+ if ( this . selectedRadio ?. station . stationuuid ) {
74+ u . searchParams . set ( 'radio' , this . selectedRadio . station . stationuuid ) ;
75+ } else {
76+ u . searchParams . delete ( 'radio' ) ;
77+ }
5678 window . history . replaceState ( window . history . state , '' , u . toString ( ) ) ;
5779 }
5880}
0 commit comments