@@ -20,14 +20,17 @@ const render = (globalProps: GlobalProps, notebooks: Notebook[]) => {
2020 ) ;
2121} ;
2222
23- const renderDropdown = ( globalProps : GlobalProps , notebooks : Notebook [ ] , label : string , popupVisible : boolean ) => {
23+ const renderDropdown = ( globalProps : GlobalProps , notebooks : Notebook [ ] ) => {
24+ const dropdownLabel = ! globalProps . globals . selectedId ?
25+ 'Select Section' :
26+ findItemName ( globalProps . globals . notebookListUpdater ! . get ( ) , globalProps . globals . selectedId ) ;
27+
2428 ReactDOM . render (
25- < OneNotePickerDropdown globals = { globalProps . globals } notebooks = { notebooks } dropdownLabel = { label } popupDirection = { 'bottom' } popupVisible = { popupVisible } /> ,
29+ < OneNotePickerDropdown globals = { globalProps . globals } notebooks = { notebooks } dropdownLabel = { dropdownLabel } popupDirection = { 'bottom' } /> ,
2630 document . getElementById ( 'oneNotePickerDropdown' ) as HTMLElement
2731 ) ;
2832} ;
2933
30- export let defaultDropdownLabel = "" ;
3134
3235oneNoteDataProvider . getNotebooks ( ) . then ( ( notebooks ) => {
3336 for ( let i = 0 ; i < notebooks . length ; i ++ ) {
@@ -38,6 +41,7 @@ oneNoteDataProvider.getNotebooks().then((notebooks) => {
3841
3942 const initialSelectedId = '0-752C1AAF7737895C!515' ;
4043 OneNoteItemUtils . expandTo ( notebooks , item => item . id === initialSelectedId ) ;
44+ let dropdownLabel = '' ;
4145
4246 const globalProps : GlobalProps = {
4347 globals : {
@@ -46,39 +50,34 @@ oneNoteDataProvider.getNotebooks().then((notebooks) => {
4650 notebookListUpdater : updater ,
4751 callbacks : {
4852 onNotebookHierarchyUpdated : ( newNotebookHierarchy ) => {
49- let latestNotebook = newNotebookHierarchy [ newNotebookHierarchy . length - 1 ] . name ;
50- if ( defaultDropdownLabel === "" )
51- defaultDropdownLabel = latestNotebook ;
53+
5254 render ( globalProps , newNotebookHierarchy ) ;
53- renderDropdown ( globalProps , newNotebookHierarchy , defaultDropdownLabel , true ) ;
55+ renderDropdown ( globalProps , newNotebookHierarchy ) ;
5456 } ,
5557 onSectionSelected : ( section , breadcrumbs ) => {
5658 globalProps . globals . selectedId = section . id ;
57- defaultDropdownLabel = section . name ;
59+
5860 // tslint:disable-next-line:no-console
5961 console . log ( breadcrumbs . map ( x => x . name ) . join ( ' > ' ) ) ;
6062
6163 render ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) ) ;
62- renderDropdown ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) , defaultDropdownLabel , false ) ;
64+ renderDropdown ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) ) ;
6365 } ,
6466 onPageSelected : ( page , breadcrumbs ) => {
6567 globalProps . globals . selectedId = page . id ;
66- defaultDropdownLabel = page . name ;
68+
6769 // tslint:disable-next-line:no-console
6870 console . log ( breadcrumbs . map ( x => x . name ) . join ( ' > ' ) ) ;
69- console . log ( breadcrumbs [ breadcrumbs . length - 1 ] . name )
7071
7172 render ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) ) ;
72- renderDropdown ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) , defaultDropdownLabel , false ) ;
73+ renderDropdown ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) ) ;
7374 } ,
7475 onAccessibleSelection : ( selectedItemId : string ) => {
7576 globalProps . globals . ariaSelectedId = selectedItemId ;
76- let notebookName = findNotebook ( notebooks , selectedItemId ) ;
77- if ( defaultDropdownLabel === "" )
78- defaultDropdownLabel = notebookName ;
77+
7978 // todo this changes the label but you can't click to make a selection?
8079 render ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) ) ;
81- renderDropdown ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) , defaultDropdownLabel , true ) ;
80+ renderDropdown ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) ) ;
8281 } ,
8382 onNotebookCreated : ( notebook : Notebook ) => {
8483 // Allow max one creation
@@ -111,15 +110,14 @@ oneNoteDataProvider.getNotebooks().then((notebooks) => {
111110 ariaSelectedId : initialSelectedId
112111 }
113112 } ;
114- let notebookName = findNotebook ( notebooks , initialSelectedId )
115113 render ( globalProps , notebooks ) ;
116- renderDropdown ( globalProps , notebooks , notebookName , false ) ;
114+ renderDropdown ( globalProps , notebooks ) ;
117115} ) . catch ( ( value ) => {
118116 // tslint:disable-next-line:no-console
119117 console . error ( value ) ;
120118} ) ;
121119
122- export function findNotebook ( notebooks , itemid ) {
120+ export function findItemName ( notebooks , itemid ) {
123121 let notebook = OneNoteItemUtils . find ( notebooks , item => item . id === itemid ) ;
124- return notebook ? notebook . name : "" ;
122+ return notebook ? notebook . name : '' ;
125123}
0 commit comments