@@ -12,9 +12,12 @@ import { NotebookOpenedIconSvg } from './icons/notebookOpenedIcon.svg';
1212import { NotebookClosedIconSvg } from './icons/notebookClosedIcon.svg' ;
1313import { ChevronSvg } from './icons/chevron.svg' ;
1414import { CreateNewSectionNode } from './createNewSection/createNewSectionNode' ;
15+ import { SpinnerIconSvg } from './icons/spinnerIcon.svg' ;
16+ import { Strings } from '../strings' ;
1517
1618export class NotebookRenderStrategy implements ExpandableNodeRenderStrategy {
1719 onClickBinded = ( ) => { } ;
20+ onExpandBinded = this . onExpand . bind ( this ) ;
1821
1922 constructor ( private notebook : Notebook , private globals : InnerGlobals ) { }
2023
@@ -42,6 +45,23 @@ export class NotebookRenderStrategy implements ExpandableNodeRenderStrategy {
4245 }
4346
4447 getChildren ( childrenLevel : number ) : JSX . Element [ ] {
48+ if ( this . notebook . apiHttpErrorMessage ) {
49+ const errorString = this . notebook . apiHttpErrorMessage ;
50+ return [
51+ < li role = 'status' aria-live = 'polite' aria-label = { errorString } className = 'progress-row' >
52+ < div > { errorString } </ div >
53+ </ li >
54+ ] ;
55+ }
56+
57+ if ( ! this . notebook . sections && ! this . notebook . sectionGroups ) {
58+ return [
59+ < li className = 'progress-row' >
60+ < SpinnerIconSvg />
61+ </ li >
62+ ] ;
63+ }
64+
4565 const createNewSection = this . globals . callbacks . onSectionCreated || this . globals . shouldShowCreateEntityInputs ?
4666 [ < CreateNewSectionNode
4767 key = { this . notebook . id + 'createnewsectionnode' }
@@ -56,6 +76,10 @@ export class NotebookRenderStrategy implements ExpandableNodeRenderStrategy {
5676 </ CreateNewSectionNode > ] :
5777 [ ] ;
5878
79+ if ( ! this . notebook . sections || ! this . notebook . sectionGroups ) {
80+ return [ ...createNewSection ]
81+ }
82+
5983 const setsize = this . notebook . sections . length + this . notebook . sectionGroups . length ;
6084
6185 const sectionGroupRenderStrategies = this . notebook . sectionGroups . map ( sectionGroup => new SectionGroupRenderStrategy ( sectionGroup , this . globals ) ) ;
@@ -65,7 +89,7 @@ export class NotebookRenderStrategy implements ExpandableNodeRenderStrategy {
6589 expanded = { renderStrategy . isExpanded ( ) } node = { renderStrategy } globals = { this . globals }
6690 treeViewId = { Constants . TreeView . id } key = { renderStrategy . getId ( ) }
6791 id = { renderStrategy . getId ( ) } level = { childrenLevel } ariaSelected = { renderStrategy . isAriaSelected ( ) } selected = { renderStrategy . isSelected ( ) }
68- setsize = { setsize } posinset = { this . notebook . sections . length + i + 1 } /> :
92+ setsize = { setsize } posinset = { this . notebook . sections ? this . notebook . sections . length + i + 1 : undefined } /> :
6993 < LeafNode node = { renderStrategy } treeViewId = { Constants . TreeView . id } key = { renderStrategy . getId ( ) } globals = { this . globals }
7094 id = { renderStrategy . getId ( ) } level = { childrenLevel } ariaSelected = { renderStrategy . isAriaSelected ( ) } /> ) ;
7195
@@ -121,4 +145,23 @@ export class NotebookRenderStrategy implements ExpandableNodeRenderStrategy {
121145 private onChevronClick ( ) {
122146 this . expandNode ( ) ;
123147 }
148+
149+ private onExpand ( ) {
150+ if ( ! this . notebook . sections && ! this . notebook . sectionGroups && this . notebook . apiUrl && this . globals . oneNoteDataProvider ) {
151+ this . globals . oneNoteDataProvider . getNotebookBySelfUrl ( this . notebook . apiUrl , 5 ) . then ( ( notebook ) => {
152+ this . notebook . sections = notebook . sections
153+ this . notebook . sectionGroups = notebook . sectionGroups
154+ } ) . catch ( ( apiError : any ) => {
155+ try {
156+ this . notebook . apiHttpErrorMessage = JSON . parse ( apiError . response ) . error . message
157+ } catch ( error ) {
158+ this . notebook . apiHttpErrorMessage = Strings . getError ( apiError . statusCode ) ;
159+ }
160+ } ) . then ( ( ) => {
161+ if ( this . globals . callbacks . onNotebookInfoReturned ) {
162+ this . globals . callbacks . onNotebookInfoReturned ( this . notebook ) ;
163+ }
164+ } )
165+ }
166+ }
124167}
0 commit comments