Skip to content

Commit 370fd9e

Browse files
authored
Merge pull request #105 from OneNoteDev/FixPublish
Support not passing oneNoteDataProvider and notebookListUpdater
2 parents fd0a215 + c16a8f7 commit 370fd9e

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "onenotepicker",
3-
"version": "2.3.0",
3+
"version": "2.3.2",
4+
"files": [
5+
"dist/**/*"
6+
],
47
"dependencies": {
58
"bulma": "^0.4.2",
69
"onenoteapi": "^2.0.1",

sampleApp/sample.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ oneNoteDataProvider.getNotebooks().then((notebooks) => {
4242

4343
console.log(breadcrumbs.map(x => x.name).join(' > '));
4444

45-
render(globalProps, globalProps.globals.notebookListUpdater.get());
45+
render(globalProps, globalProps.globals.notebookListUpdater!.get());
4646
},
4747
onPageSelected: (page, breadcrumbs) => {
4848
globalProps.globals.selectedId = page.id;
4949

5050
console.log(breadcrumbs.map(x => x.name).join(' > '));
5151

52-
render(globalProps, globalProps.globals.notebookListUpdater.get());
52+
render(globalProps, globalProps.globals.notebookListUpdater!.get());
5353
},
5454
onAccessibleSelection: (selectedItemId: string) => {
5555
globalProps.globals.ariaSelectedId = selectedItemId;
5656

57-
render(globalProps, globalProps.globals.notebookListUpdater.get());
57+
render(globalProps, globalProps.globals.notebookListUpdater!.get());
5858
}
5959
},
6060
selectedId: initialSelectedId

src/components/sharedNotebookRenderStrategy.tsx

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -115,36 +115,37 @@ export class SharedNotebookRenderStrategy implements ExpandableNodeRenderStrateg
115115
}
116116

117117
private onExpand() {
118-
if (this.isExpandable()) {
119-
if (!this.notebook.apiProperties && !this.notebook.startedLoading) {
120-
// This notebook was made known to us by GetRecentNotebooks, but we haven't
121-
// fetched any metadata or children info
122-
this.notebook.startedLoading = true;
123-
const depth = this.globals.notebookExpandDepth || 5;
124-
this.globals.oneNoteDataProvider.getSpNotebookProperties(this.notebook, depth, true).then((apiProperties) => {
125-
if (!apiProperties) {
126-
this.notebook.apiHttpErrorCode = 404;
127-
return;
128-
}
129-
130-
this.notebook.apiProperties = apiProperties;
131-
132-
if (this.globals.notebookListUpdater) {
133-
this.globals.notebookListUpdater.updateNotebookList([this.notebook]);
134-
}
135-
}).catch((xhrs: XMLHttpRequest[]) => {
136-
let max = 0;
137-
for (let i = 0; i < xhrs.length; i++) {
138-
max = Math.max(xhrs[i].status, max);
139-
}
140-
this.notebook.apiHttpErrorCode = max;
141-
}).then(() => {
142-
let { onSharedNotebookInfoReturned } = this.globals.callbacks;
143-
if (!!onSharedNotebookInfoReturned) {
144-
onSharedNotebookInfoReturned(this.notebook);
145-
}
146-
});
147-
}
118+
// Check if the picker is expandable
119+
if ((this.globals.callbacks.onSectionSelected || !!this.globals.callbacks.onPageSelected) &&
120+
!this.notebook.apiProperties && !this.notebook.startedLoading && this.globals.oneNoteDataProvider) {
121+
// This notebook was made known to us by GetRecentNotebooks, but we haven't
122+
// fetched any metadata or children info
123+
this.notebook.startedLoading = true;
124+
const depth = this.globals.notebookExpandDepth || 5;
125+
126+
this.globals.oneNoteDataProvider.getSpNotebookProperties(this.notebook, depth, true).then((apiProperties) => {
127+
if (!apiProperties) {
128+
this.notebook.apiHttpErrorCode = 404;
129+
return;
130+
}
131+
132+
this.notebook.apiProperties = apiProperties;
133+
134+
if (this.globals.notebookListUpdater) {
135+
this.globals.notebookListUpdater.updateNotebookList([this.notebook]);
136+
}
137+
}).catch((xhrs: XMLHttpRequest[]) => {
138+
let max = 0;
139+
for (let i = 0; i < xhrs.length; i++) {
140+
max = Math.max(xhrs[i].status, max);
141+
}
142+
this.notebook.apiHttpErrorCode = max;
143+
}).then(() => {
144+
let { onSharedNotebookInfoReturned } = this.globals.callbacks;
145+
if (!!onSharedNotebookInfoReturned) {
146+
onSharedNotebookInfoReturned(this.notebook);
147+
}
148+
});
148149
}
149150
}
150151

@@ -153,8 +154,4 @@ export class SharedNotebookRenderStrategy implements ExpandableNodeRenderStrateg
153154
let split = url.split('/');
154155
return split.slice(3, -1).map(decodeURIComponent).join('/');
155156
}
156-
157-
private isExpandable(): boolean {
158-
return !!this.globals.callbacks.onSectionSelected || !!this.globals.callbacks.onPageSelected;
159-
}
160157
}

src/props/globalProps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface GlobalProps {
1616
export interface InnerGlobals {
1717
focusOnMount: boolean;
1818

19-
oneNoteDataProvider: OneNoteDataProvider;
20-
notebookListUpdater: NotebookListUpdater;
19+
oneNoteDataProvider: OneNoteDataProvider | undefined;
20+
notebookListUpdater: NotebookListUpdater | undefined;
2121
callbacks: OneNotePickerCallbacks;
2222

2323
strings?: {};

0 commit comments

Comments
 (0)