@@ -20,14 +20,17 @@ const render = (globalProps: GlobalProps, notebooks: Notebook[]) => {
20
20
) ;
21
21
} ;
22
22
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
+
24
28
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' } /> ,
26
30
document . getElementById ( 'oneNotePickerDropdown' ) as HTMLElement
27
31
) ;
28
32
} ;
29
33
30
- export let defaultDropdownLabel = "" ;
31
34
32
35
oneNoteDataProvider . getNotebooks ( ) . then ( ( notebooks ) => {
33
36
for ( let i = 0 ; i < notebooks . length ; i ++ ) {
@@ -38,6 +41,7 @@ oneNoteDataProvider.getNotebooks().then((notebooks) => {
38
41
39
42
const initialSelectedId = '0-752C1AAF7737895C!515' ;
40
43
OneNoteItemUtils . expandTo ( notebooks , item => item . id === initialSelectedId ) ;
44
+ let dropdownLabel = '' ;
41
45
42
46
const globalProps : GlobalProps = {
43
47
globals : {
@@ -46,39 +50,34 @@ oneNoteDataProvider.getNotebooks().then((notebooks) => {
46
50
notebookListUpdater : updater ,
47
51
callbacks : {
48
52
onNotebookHierarchyUpdated : ( newNotebookHierarchy ) => {
49
- let latestNotebook = newNotebookHierarchy [ newNotebookHierarchy . length - 1 ] . name ;
50
- if ( defaultDropdownLabel === "" )
51
- defaultDropdownLabel = latestNotebook ;
53
+
52
54
render ( globalProps , newNotebookHierarchy ) ;
53
- renderDropdown ( globalProps , newNotebookHierarchy , defaultDropdownLabel , true ) ;
55
+ renderDropdown ( globalProps , newNotebookHierarchy ) ;
54
56
} ,
55
57
onSectionSelected : ( section , breadcrumbs ) => {
56
58
globalProps . globals . selectedId = section . id ;
57
- defaultDropdownLabel = section . name ;
59
+
58
60
// tslint:disable-next-line:no-console
59
61
console . log ( breadcrumbs . map ( x => x . name ) . join ( ' > ' ) ) ;
60
62
61
63
render ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) ) ;
62
- renderDropdown ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) , defaultDropdownLabel , false ) ;
64
+ renderDropdown ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) ) ;
63
65
} ,
64
66
onPageSelected : ( page , breadcrumbs ) => {
65
67
globalProps . globals . selectedId = page . id ;
66
- defaultDropdownLabel = page . name ;
68
+
67
69
// tslint:disable-next-line:no-console
68
70
console . log ( breadcrumbs . map ( x => x . name ) . join ( ' > ' ) ) ;
69
- console . log ( breadcrumbs [ breadcrumbs . length - 1 ] . name )
70
71
71
72
render ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) ) ;
72
- renderDropdown ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) , defaultDropdownLabel , false ) ;
73
+ renderDropdown ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) ) ;
73
74
} ,
74
75
onAccessibleSelection : ( selectedItemId : string ) => {
75
76
globalProps . globals . ariaSelectedId = selectedItemId ;
76
- let notebookName = findNotebook ( notebooks , selectedItemId ) ;
77
- if ( defaultDropdownLabel === "" )
78
- defaultDropdownLabel = notebookName ;
77
+
79
78
// todo this changes the label but you can't click to make a selection?
80
79
render ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) ) ;
81
- renderDropdown ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) , defaultDropdownLabel , true ) ;
80
+ renderDropdown ( globalProps , globalProps . globals . notebookListUpdater ! . get ( ) ) ;
82
81
} ,
83
82
onNotebookCreated : ( notebook : Notebook ) => {
84
83
// Allow max one creation
@@ -111,15 +110,14 @@ oneNoteDataProvider.getNotebooks().then((notebooks) => {
111
110
ariaSelectedId : initialSelectedId
112
111
}
113
112
} ;
114
- let notebookName = findNotebook ( notebooks , initialSelectedId )
115
113
render ( globalProps , notebooks ) ;
116
- renderDropdown ( globalProps , notebooks , notebookName , false ) ;
114
+ renderDropdown ( globalProps , notebooks ) ;
117
115
} ) . catch ( ( value ) => {
118
116
// tslint:disable-next-line:no-console
119
117
console . error ( value ) ;
120
118
} ) ;
121
119
122
- export function findNotebook ( notebooks , itemid ) {
120
+ export function findItemName ( notebooks , itemid ) {
123
121
let notebook = OneNoteItemUtils . find ( notebooks , item => item . id === itemid ) ;
124
- return notebook ? notebook . name : "" ;
122
+ return notebook ? notebook . name : '' ;
125
123
}
0 commit comments