Skip to content

Commit 6fe639b

Browse files
committed
feat: loading state on startup
1 parent b8c52a6 commit 6fe639b

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@
14391439
"view/item/context": [
14401440
{
14411441
"command": "deepnote.revealInExplorer",
1442-
"when": "view == deepnoteExplorer",
1442+
"when": "view == deepnoteExplorer && viewItem != loading",
14431443
"group": "inline@2"
14441444
}
14451445
]

src/notebooks/deepnote/deepnoteTreeDataProvider.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
workspace,
88
RelativePattern,
99
Uri,
10-
FileSystemWatcher
10+
FileSystemWatcher,
11+
ThemeIcon
1112
} from 'vscode';
1213
import * as yaml from 'js-yaml';
1314

@@ -26,6 +27,8 @@ export class DeepnoteTreeDataProvider implements TreeDataProvider<DeepnoteTreeIt
2627

2728
private fileWatcher: FileSystemWatcher | undefined;
2829
private cachedProjects: Map<string, DeepnoteProject> = new Map();
30+
private isInitialScanComplete: boolean = false;
31+
private initialScanPromise: Promise<void> | undefined;
2932

3033
constructor() {
3134
this.setupFileWatcher();
@@ -38,6 +41,8 @@ export class DeepnoteTreeDataProvider implements TreeDataProvider<DeepnoteTreeIt
3841

3942
public refresh(): void {
4043
this.cachedProjects.clear();
44+
this.isInitialScanComplete = false;
45+
this.initialScanPromise = undefined;
4146
this._onDidChangeTreeData.fire();
4247
}
4348

@@ -51,6 +56,15 @@ export class DeepnoteTreeDataProvider implements TreeDataProvider<DeepnoteTreeIt
5156
}
5257

5358
if (!element) {
59+
if (!this.isInitialScanComplete) {
60+
if (!this.initialScanPromise) {
61+
this.initialScanPromise = this.performInitialScan();
62+
}
63+
64+
// Show loading item
65+
return [this.createLoadingTreeItem()];
66+
}
67+
5468
return this.getDeepnoteProjectFiles();
5569
}
5670

@@ -61,6 +75,28 @@ export class DeepnoteTreeDataProvider implements TreeDataProvider<DeepnoteTreeIt
6175
return [];
6276
}
6377

78+
private createLoadingTreeItem(): DeepnoteTreeItem {
79+
const loadingItem = new DeepnoteTreeItem(
80+
DeepnoteTreeItemType.Loading,
81+
{ filePath: '', projectId: '' },
82+
null,
83+
TreeItemCollapsibleState.None
84+
);
85+
loadingItem.label = 'Scanning for Deepnote projects...';
86+
loadingItem.iconPath = new ThemeIcon('loading~spin');
87+
return loadingItem;
88+
}
89+
90+
private async performInitialScan(): Promise<void> {
91+
try {
92+
await this.getDeepnoteProjectFiles();
93+
} finally {
94+
this.isInitialScanComplete = true;
95+
this.initialScanPromise = undefined;
96+
this._onDidChangeTreeData.fire();
97+
}
98+
}
99+
64100
private async getDeepnoteProjectFiles(): Promise<DeepnoteTreeItem[]> {
65101
const deepnoteFiles: DeepnoteTreeItem[] = [];
66102

src/notebooks/deepnote/deepnoteTreeItem.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import type { DeepnoteProject, DeepnoteNotebook } from '../../platform/deepnote/
66
*/
77
export enum DeepnoteTreeItemType {
88
ProjectFile = 'projectFile',
9-
Notebook = 'notebook'
9+
Notebook = 'notebook',
10+
Loading = 'loading'
1011
}
1112

1213
/**
@@ -25,16 +26,20 @@ export class DeepnoteTreeItem extends TreeItem {
2526
constructor(
2627
public readonly type: DeepnoteTreeItemType,
2728
public readonly context: DeepnoteTreeItemContext,
28-
public readonly data: DeepnoteProject | DeepnoteNotebook,
29+
public readonly data: DeepnoteProject | DeepnoteNotebook | null,
2930
collapsibleState: TreeItemCollapsibleState
3031
) {
3132
super('', collapsibleState);
3233

3334
this.contextValue = this.type;
34-
this.tooltip = this.getTooltip();
35-
this.iconPath = this.getIcon();
36-
this.label = this.getLabel();
37-
this.description = this.getDescription();
35+
36+
// Skip initialization for loading items as they don't have real data
37+
if (this.type !== DeepnoteTreeItemType.Loading) {
38+
this.tooltip = this.getTooltip();
39+
this.iconPath = this.getIcon();
40+
this.label = this.getLabel();
41+
this.description = this.getDescription();
42+
}
3843

3944
if (this.type === DeepnoteTreeItemType.Notebook) {
4045
this.resourceUri = this.getNotebookUri();

0 commit comments

Comments
 (0)