Skip to content

Commit d244c46

Browse files
committed
Use one loading function
1 parent 36bf1e4 commit d244c46

File tree

2 files changed

+34
-83
lines changed

2 files changed

+34
-83
lines changed

src/contents.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,8 @@ export class Drive implements Contents.IDrive {
221221
): Promise<Contents.IModel> {
222222
let data: Contents.IModel;
223223

224-
this._loadingContents.emit({
225-
type: 'loading',
226-
path: localPath,
227-
driveName: this._name,
228-
itemType: 'directory'
229-
});
230-
231224
if (localPath !== '') {
232-
console.log('debug: get() called with localPath:', localPath);
225+
console.log('debug: IF get() called with localPath:', localPath);
233226
const currentDrive = extractCurrentDrive(localPath, this._drivesList);
234227

235228
// when accessed the first time, mount drive
@@ -251,6 +244,13 @@ export class Drive implements Contents.IDrive {
251244
registeredFileTypes: this._registeredFileTypes
252245
});
253246

247+
this._loadingContents.emit({
248+
type: 'loading',
249+
path: localPath,
250+
driveName: this._name,
251+
itemType: result.isDir ? 'directory' : 'file'
252+
});
253+
254254
data = {
255255
name: result.isDir
256256
? currentPath
@@ -275,6 +275,15 @@ export class Drive implements Contents.IDrive {
275275
type: result.isDir ? 'directory' : result.type!
276276
};
277277
} else {
278+
console.log('debug: ELSE get() called with localPath:', localPath);
279+
280+
this._loadingContents.emit({
281+
type: 'loading',
282+
path: localPath,
283+
driveName: this._name,
284+
itemType: 'directory'
285+
});
286+
278287
// retriving list of contents from root
279288
// in our case: list available drives
280289
const drivesListInfo: Contents.IModel[] = [];

src/plugins/driveBrowserPlugin.ts

Lines changed: 17 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -49,53 +49,29 @@ class DriveStatusWidget extends Widget {
4949
this.node.textContent = 'Drives: Ready';
5050
this._currentPath = '';
5151
this._isLoading = false;
52-
53-
// Listen for custom events from getContents
54-
window.addEventListener('drive-status-update', (event: Event) => {
55-
const customEvent = event as CustomEvent;
56-
this.handleStatusUpdate(customEvent.detail);
57-
});
5852
}
5953

6054
updateStatus(text: string) {
6155
this.node.textContent = `Drives: ${text}`;
6256
}
6357

64-
setDriveCount(count: number) {
65-
this.node.textContent = `Drives: ${count} connected`;
66-
}
67-
68-
setError(message: string) {
69-
this.node.textContent = `Drives: ${message}`;
70-
this.addClass('jp-drive-status-error');
71-
}
72-
73-
clearError() {
74-
this.removeClass('jp-drive-status-error');
75-
}
76-
7758
/**
78-
* Update status when navigating to a directory
59+
* Update status when loading a directory or file
7960
*/
80-
setDirectoryLoading(path: string) {
81-
console.log('[DEBUG] Setting directory loading:', path);
61+
setLoading(path: string, type: 'directory' | 'file' = 'directory') {
62+
console.log('[DEBUG] Setting loading:', path, 'type:', type);
8263
this._isLoading = true;
8364
this._currentPath = path;
84-
const displayPath =
85-
path === '' ? 'Root' : path.split('/').pop() || 'Directory';
86-
this.node.textContent = `Drives: Opening ${displayPath}...`;
87-
this.addClass('jp-drive-status-loading');
88-
}
8965

90-
/**
91-
* Update status when a file is being opened
92-
*/
93-
setFileLoading(path: string) {
94-
console.log('[DEBUG] Setting file loading:', path);
95-
this._isLoading = true;
96-
this._currentPath = path;
97-
const fileName = path.split('/').pop() || 'File';
98-
this.node.textContent = `Drives: Opening ${fileName}...`;
66+
if (type === 'directory') {
67+
const displayPath =
68+
path === '' ? 'Root' : path.split('/').pop() || 'Directory';
69+
this.node.textContent = `Drives: Opening ${displayPath}...`;
70+
} else {
71+
const fileName = path.split('/').pop() || 'File';
72+
this.node.textContent = `Drives: Opening ${fileName}...`;
73+
}
74+
9975
this.addClass('jp-drive-status-loading');
10076
}
10177

@@ -131,31 +107,6 @@ class DriveStatusWidget extends Widget {
131107
return this._isLoading;
132108
}
133109

134-
/**
135-
* Handle status updates from getContents function
136-
*/
137-
private handleStatusUpdate(detail: any) {
138-
console.log('[DEBUG] Status update received:', detail);
139-
140-
if (detail.type === 'loading') {
141-
const fullPath = detail.driveName + '/' + detail.path;
142-
if (detail.path === '') {
143-
this.setDirectoryLoading('');
144-
} else {
145-
// Determine if it's a directory or file based on path
146-
const isDirectory = detail.path.endsWith('/') || detail.path === '';
147-
if (isDirectory) {
148-
this.setDirectoryLoading(fullPath);
149-
} else {
150-
this.setFileLoading(fullPath);
151-
}
152-
}
153-
} else if (detail.type === 'loaded') {
154-
const fullPath = detail.driveName + '/' + detail.path;
155-
this.setLoaded(fullPath, detail.itemType);
156-
}
157-
}
158-
159110
private _currentPath: string;
160111
private _isLoading: boolean;
161112
}
@@ -265,23 +216,14 @@ export const driveFileBrowser: JupyterFrontEndPlugin<void> = {
265216

266217
// Listen for drive changes and update status
267218
drive.loadingContents.connect((sender, args) => {
268-
const path = driveBrowser.model.path;
219+
const { path, type, itemType } = args;
269220
console.log('[DEBUG] Path changed:', path, 'args:', args);
270-
if (args.type === 'loading') {
271-
driveStatusWidget.setDirectoryLoading(path);
272-
} else if (args.type === 'loaded') {
221+
if (type === 'loading') {
222+
driveStatusWidget.setLoading(path, itemType);
223+
} else if (type === 'loaded') {
273224
console.log('loaded');
274-
// driveStatusWidget.setLoaded(path, args.itemType);
225+
// driveStatusWidget.setLoaded(path, itemType);
275226
}
276-
// Status updates are now handled by custom events from getContents
277-
});
278-
279-
// Listen for model changes to update drive count
280-
drive.loadingContents.connect(() => {
281-
console.log('[DEBUG] Model refreshed');
282-
// const items = driveBrowser.model.items();
283-
// const driveCount = Array.from(items).length;
284-
// driveStatusWidget.setDriveCount(driveCount);
285227
});
286228
}
287229

0 commit comments

Comments
 (0)