Skip to content

Commit ff2c1f3

Browse files
authored
Merge pull request #174 from Open-STEM/kq-bugs
Changed the logic for checking file upload from Google Drive to XRP
2 parents d15e64d + 338a0fc commit ff2c1f3

6 files changed

Lines changed: 49 additions & 28 deletions

File tree

src/components/navbar.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ function NavBar({ layoutref }: NavBarProps) {
117117
// subscribe to the connection event
118118
AppMgr.getInstance().on(EventType.EVENT_CONNECTION_STATUS, async (state: string) => {
119119
if (state === ConnectionState.Connected.toString()) {
120+
// clear the existing last file save time for Google Drive files
121+
EditorMgr.getInstance().clearLastFileSaveTime();
120122
setConnected(true);
121123
setRunning(false);
122124
} else if (state === ConnectionState.Disconnected.toString()) {
@@ -832,7 +834,7 @@ function NavBar({ layoutref }: NavBarProps) {
832834
const beginExecution = async () => {
833835
try {
834836
// Save all unsaved editors before running
835-
await EditorMgr.getInstance().saveAllUnsavedEditors();
837+
await EditorMgr.getInstance().saveAllUnsavedEditors(activeTab);
836838

837839
// Update the main.js
838840
const session: EditorSession | undefined =
@@ -850,6 +852,9 @@ function NavBar({ layoutref }: NavBarProps) {
850852
.updateMainFile(session.path)
851853
.then(async (lines) => {
852854
await CommandToXRPMgr.getInstance().executeLines(lines);
855+
setRunning(false);
856+
broadcastRunningState(false);
857+
853858
});
854859
});
855860
});
@@ -858,16 +863,14 @@ function NavBar({ layoutref }: NavBarProps) {
858863
.updateMainFile(session.path)
859864
.then(async (lines) => {
860865
await CommandToXRPMgr.getInstance().executeLines(lines);
866+
setRunning(false);
867+
broadcastRunningState(false);
861868
});
862869
}
863870
}
864871
} catch (err) {
865872
console.log(err);
866873
}
867-
// When returning from the execute switch back to RUN mode. This happens when the program ends
868-
// naturaly.
869-
setRunning(false);
870-
broadcastRunningState(false);
871874
}
872875

873876
const handlePowerSwitchOK = async () => {

src/managers/editormgr.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ export default class EditorMgr {
372372
* Save all unsaved editors to the robot with progress tracking
373373
* @returns Promise that resolves when all editors are saved
374374
*/
375-
public async saveAllUnsavedEditors(): Promise<void> {
375+
public async saveAllUnsavedEditors(activeTab: string): Promise<void> {
376376
const isConnected = AppMgr.getInstance().getConnection()?.isConnected() ?? false;
377377
if (!isConnected) {
378378
return; // Can't save if not connected
@@ -431,6 +431,10 @@ export default class EditorMgr {
431431
console.warn(`Failed to save ${failedFiles.length} file(s): ${failedFiles.join(', ')}`);
432432
}
433433

434+
if (unsavedSessions.length > 0) {
435+
this.SelectEditorTab(activeTab);
436+
}
437+
434438
// Set progress to 100%
435439
AppMgr.getInstance().emit(EventType.EVENT_PROGRESS, '100');
436440

@@ -444,24 +448,21 @@ export default class EditorMgr {
444448
}
445449
}
446450

451+
/**
452+
* clearLastFileSaveTime - clear the last file save time for Google Drive files
453+
*/
454+
public clearLastFileSaveTime() {
455+
localStorage.removeItem(StorageKeys.LAST_GOOGLE_DRIVE_TO_XRP_SAVE_TIME);
456+
}
457+
447458
/**
448459
* saveAllFilesInGoogleDriveToXRP
449460
* @param sessionId
450461
* @returns
451462
*/
452463
public async saveAllFilesInGoogleDriveToXRP(sessionId: string): Promise<void> {
453-
// check when was the last time we saved to XRP from local storage
454-
const lastSaveConfig = parseInt(localStorage.getItem(StorageKeys.LAST_GOOGLE_DRIVE_TO_XRP_SAVE_TIME_CONFIG) || Constants.LASTSAVETIME_CONFG);
455464
const lastSaveTime = localStorage.getItem(StorageKeys.LAST_GOOGLE_DRIVE_TO_XRP_SAVE_TIME);
456-
if (lastSaveTime) {
457-
const lastSaveDate = new Date(parseInt(lastSaveTime));
458-
const now = new Date();
459-
const timeDiff = now.getTime() - lastSaveDate.getTime();
460-
const hoursDiff = timeDiff / (1000 * 60 * 60);
461-
if (hoursDiff < lastSaveConfig ? lastSaveConfig : 1) {
462-
return; // Skip saving if last save was within the past configured hours
463-
}
464-
}
465+
const lastSaveDate = lastSaveTime ? new Date(parseInt(lastSaveTime)) : null;
465466

466467
const session = this.editorSessions.get(sessionId);
467468
if (!session) {
@@ -487,9 +488,6 @@ export default class EditorMgr {
487488
return;
488489
}
489490

490-
// Update the last save time in local storage
491-
localStorage.setItem(StorageKeys.LAST_GOOGLE_DRIVE_TO_XRP_SAVE_TIME, Date.now().toString());
492-
493491
const fileList = await AppMgr.getInstance().driveService.getFileListByFolderId(parentId);
494492

495493
for (let i = 0; i < fileList.length; i++) {
@@ -503,6 +501,13 @@ export default class EditorMgr {
503501
// Skip folders
504502
continue;
505503
}
504+
505+
const fileModifiedDateTime = new Date(file.modifiedTime || '');
506+
if (lastSaveDate && fileModifiedDateTime <= lastSaveDate) {
507+
// Skip files that have not been modified since last save
508+
continue;
509+
}
510+
506511
// Get file content from Google Drive
507512
await AppMgr.getInstance().driveService.getFileContents(file.id).then(async (fileContent) => {;
508513
// Determine XRP path
@@ -516,6 +521,9 @@ export default class EditorMgr {
516521
}
517522
}
518523

524+
// Update the last save time in local storage
525+
localStorage.setItem(StorageKeys.LAST_GOOGLE_DRIVE_TO_XRP_SAVE_TIME, Date.now().toString());
526+
519527
// Set progress to 100%
520528
AppMgr.getInstance().emit(EventType.EVENT_PROGRESS, '100');
521529
// Close progress dialog

src/services/google-drive.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export interface GoogleDriveFile {
2222
thumbnailLink?: string;
2323
parents?: string[];
2424
children?: GoogleDriveFile[]
25-
// createdTime?: string;
26-
// modifiedTime?: string;
25+
createdTime?: string;
26+
modifiedTime?: string;
2727
};
2828

2929
/**
@@ -175,7 +175,7 @@ class GoogleDriveService {
175175
*/
176176
async getFileListByFolderId(folderId: string): Promise<GoogleDriveFile[]> {
177177
const query = `'${folderId}' in parents and trashed = false`;
178-
const fields = 'files(id, name, mimeType, parents)';
178+
const fields = 'files(id, name, mimeType, parents, createdTime, modifiedTime, kind)';
179179
const url = new URL(this._driveApiUrl);
180180
url.searchParams.append('q', query);
181181
url.searchParams.append('fields', fields);
@@ -196,6 +196,8 @@ class GoogleDriveService {
196196
id: file.id,
197197
name: file.name,
198198
mimeType: file.mimeType,
199+
createdTime: file.createdTime,
200+
modifiedTime: file.modifiedTime,
199201
parents: file.parents || undefined
200202
}));
201203
}
@@ -222,6 +224,8 @@ class GoogleDriveService {
222224
name: file.name,
223225
kind: file.kind,
224226
mimeType: file.mimeType,
227+
createdTime: file.createdTime,
228+
modifiedTime: file.modifiedTime,
225229
parents: file.parents || undefined
226230
};
227231

@@ -252,6 +256,8 @@ class GoogleDriveService {
252256
mimeType: foundFolder.mimeType,
253257
kind: foundFolder.kind,
254258
parents: foundFolder.parents,
259+
createdTime: foundFolder.createdTime,
260+
modifiedTime: foundFolder.modifiedTime,
255261
children: await this.getChildren(foundFolder.id),
256262
};
257263

@@ -376,7 +382,7 @@ class GoogleDriveService {
376382
*/
377383
async findFolderByName(folderName: string, parentFolderId?: string): Promise<GoogleDriveFile | null> {
378384
let query = `name = '${folderName}' and mimeType = 'application/vnd.google-apps.folder' and trashed = false`;
379-
const fields = 'files(id, name, kind, mimeType)';
385+
const fields = 'files(id, name, kind, mimeType, createdTime, modifiedTime, parents)';
380386
if (parentFolderId) {
381387
query += ` and '${parentFolderId}' in parents`;
382388
}
@@ -513,7 +519,7 @@ class GoogleDriveService {
513519
existingFileId?: string,
514520
parentFolderId?: string,
515521
): Promise<GoogleDriveFile | null> {
516-
const fieldsToReturn = 'id,name,mimeType,webViewLink,webContentLink,thumbnailLink';
522+
const fieldsToReturn = 'id,name,mimeType,webViewLink,webContentLink,thumbnailLink, createdTime, modifiedTime, parents';
517523

518524
let method: 'POST' | 'PATCH' = 'POST';
519525
try {

src/utils/blockly-locales.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import * as EsMsg from 'blockly/msg/es';
1313

1414
// Map of language codes to their Blockly message objects
1515
// Add new languages here - they will automatically be supported
16-
const localeMessages: Record<string, typeof EnMsg> = {
16+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
17+
const localeMessages: Record<string, any> = {
1718
en: EnMsg,
1819
es: EsMsg,
1920
};
@@ -37,7 +38,7 @@ export function isLanguageSupported(language: string): boolean {
3738
* Falls back to 'en' if language is not supported
3839
*/
3940
export function setBlocklyLocale(language: string): void {
40-
const supportedLanguages = getSupportedLanguages();
41+
// const supportedLanguages = getSupportedLanguages();
4142
const defaultLanguage = 'en';
4243

4344
// Validate and fallback to default if needed
@@ -53,4 +54,3 @@ export function setBlocklyLocale(language: string): void {
5354
Blockly.setLocale(localeMessages[defaultLanguage]);
5455
}
5556
}
56-

src/utils/google-utils.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const transformGDriveTreeToFolderTree = (username: string, path: string, driveIt
2020
gparentId: driveItem.parents ? driveItem.parents[0] : undefined,
2121
isReadOnly: false,
2222
path: path,
23+
createdTime: driveItem.createdTime,
24+
modifiedTime: driveItem.modifiedTime,
2325
children: itemType === 'folder' ? [] : null,
2426
}
2527

src/utils/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export interface FolderItem {
3434
path: string;
3535
fileId?: string; // Google Drive file ID
3636
gparentId?: string; // Google Drive parent IDxs
37+
createdTime?: string;
38+
modifiedTime?: string;
3739
parent?: FolderItem;
3840
children: FolderItem[] | null;
3941
};

0 commit comments

Comments
 (0)