Skip to content

Commit b840cb5

Browse files
authored
Merge pull request #177 from Open-STEM/kq-bugs
Kq bugs
2 parents ff2c1f3 + 3abfd00 commit b840cb5

5 files changed

Lines changed: 45 additions & 13 deletions

File tree

src/components/navbar.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function NavBar({ layoutref }: NavBarProps) {
8484
const [isConnected, setConnected] = useState(false);
8585
const [isLogin, setLogin] = useState(false);
8686
const [isRunning, setRunning] = useState(false);
87+
const [isStopping, setIsStopping] = useState(false);
8788
const [isBlockly, setBlockly] = useState(false);
8889
const [isOtherTab, setIsOtherTab] = useState(false);
8990
const dialogRef = useRef<HTMLDialogElement>(null);
@@ -798,6 +799,15 @@ function NavBar({ layoutref }: NavBarProps) {
798799
async function onRunBtnClicked() {
799800
console.log('onRunBtnClicked');
800801

802+
const resetRunButtonStates = () => {
803+
AppMgr.getInstance().on(EventType.EVENT_PROGRAM_EXECUTED, () => {
804+
setRunning(false);
805+
setIsStopping(false);
806+
broadcastRunningState(false);
807+
AppMgr.getInstance().eventOff(EventType.EVENT_PROGRAM_EXECUTED);
808+
});
809+
}
810+
801811
if (!isRunning) {
802812
if (!isConnected) {
803813
setDialogContent(
@@ -852,9 +862,7 @@ function NavBar({ layoutref }: NavBarProps) {
852862
.updateMainFile(session.path)
853863
.then(async (lines) => {
854864
await CommandToXRPMgr.getInstance().executeLines(lines);
855-
setRunning(false);
856-
broadcastRunningState(false);
857-
865+
resetRunButtonStates();
858866
});
859867
});
860868
});
@@ -863,8 +871,7 @@ function NavBar({ layoutref }: NavBarProps) {
863871
.updateMainFile(session.path)
864872
.then(async (lines) => {
865873
await CommandToXRPMgr.getInstance().executeLines(lines);
866-
setRunning(false);
867-
broadcastRunningState(false);
874+
resetRunButtonStates();
868875
});
869876
}
870877
}
@@ -908,8 +915,7 @@ function NavBar({ layoutref }: NavBarProps) {
908915
}
909916
});
910917
} else {
911-
setRunning(false);
912-
broadcastRunningState(false);
918+
setIsStopping(true);
913919
CommandToXRPMgr.getInstance().stopProgram();
914920
}
915921
}
@@ -1197,6 +1203,7 @@ function NavBar({ layoutref }: NavBarProps) {
11971203
id="runBtn"
11981204
className={`text-white h-full w-[120] items-center justify-center rounded-3xl px-4 py-2 ${isRunning ? 'bg-cinnabar-600' : 'bg-chateau-green-500'} ${isConnected ? 'flex' : 'hidden'}`}
11991205
onClick={onRunBtnClicked}
1206+
disabled={isStopping}
12001207
>
12011208
{isRunning ? (
12021209
<>

src/managers/appmgr.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ export enum EventType {
4646
EVENT_GAMEPAD_STATUS = 'gamepad-status', // Gamepad status on/off
4747
EVENT_ALERT = 'alert', // Alert dialog event
4848
EVENT_ISRUNNING = 'is-running', // XRP is running user code
49-
EVENT_LOGIN_STATUS = 'login-status' // Google login status
49+
EVENT_LOGIN_STATUS = 'login-status', // Google login status
50+
EVENT_PROGRAM_EXECUTED = 'runstop-complete' // Run/Stop command complete
5051
}
5152

5253
type Events = {
@@ -80,6 +81,7 @@ type Events = {
8081
[EventType.EVENT_ALERT]: string;
8182
[EventType.EVENT_ISRUNNING]: string;
8283
[EventType.EVENT_LOGIN_STATUS]: string;
84+
[EventType.EVENT_PROGRAM_EXECUTED]: string;
8385
};
8486

8587
/**

src/managers/commandstoxrpmgr.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,10 @@ export class CommandToXRPMgr {
983983

984984
// Make sure to update the filesystem as there is a small chance that the program saved something like a log file.
985985
setTimeout(() => {
986-
this.getOnBoardFSTree();
986+
this.getOnBoardFSTree().then(() => {
987+
// File system tree updated after execution
988+
AppMgr.getInstance().emit(EventType.EVENT_PROGRAM_EXECUTED, '');
989+
});
987990
});
988991
}
989992

src/managers/editormgr.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { StorageKeys } from "@/utils/localstorage";
66
import { Constants } from "@/utils/constants";
77
import { Workspace } from "react-blockly";
88
import i18n from "@/utils/i18n";
9+
import { GoogleDriveFile } from "@/services/google-drive";
910

1011
/**
1112
* EditorSession - Editor session object
@@ -478,9 +479,6 @@ export default class EditorMgr {
478479
return; // Can't save if not logged in
479480
}
480481

481-
// Show progress dialog
482-
AppMgr.getInstance().emit(EventType.EVENT_SHOWPROGRESS, Constants.SHOW_PROGRESS);
483-
484482
try {
485483
// Get a list of all files in Google Drive parent directory
486484
const parentId = session.gparentId;
@@ -490,6 +488,9 @@ export default class EditorMgr {
490488

491489
const fileList = await AppMgr.getInstance().driveService.getFileListByFolderId(parentId);
492490

491+
const googleFilesTobeUploadedToXRP: GoogleDriveFile[] = [];
492+
493+
// Iterate through files and upload to XRP if modified since last save
493494
for (let i = 0; i < fileList.length; i++) {
494495
const file = fileList[i];
495496
const fileName = file.name;
@@ -508,6 +509,26 @@ export default class EditorMgr {
508509
continue;
509510
}
510511

512+
googleFilesTobeUploadedToXRP.push(file);
513+
514+
} catch (error) {
515+
console.error(`Error identifying Google Drive modified file ${fileName} to XRP:`, error);
516+
}
517+
}
518+
519+
if (googleFilesTobeUploadedToXRP.length === 0) {
520+
return; // Nothing to save
521+
}
522+
523+
// Show progress dialog
524+
AppMgr.getInstance().emit(EventType.EVENT_SHOWPROGRESS, Constants.SHOW_PROGRESS);
525+
526+
for (let i = 0; i < googleFilesTobeUploadedToXRP.length; i++) {
527+
const file = googleFilesTobeUploadedToXRP[i];
528+
const fileName = file.name;
529+
AppMgr.getInstance().emit(EventType.EVENT_PROGRESS_ITEM, fileName);
530+
531+
try {
511532
// Get file content from Google Drive
512533
await AppMgr.getInstance().driveService.getFileContents(file.id).then(async (fileContent) => {;
513534
// Determine XRP path

src/utils/localstorage.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const StorageKeys = {
88
LANGUAGE: 'i18nextLng',
99
THEME: 'Theme',
1010
LAST_GOOGLE_DRIVE_TO_XRP_SAVE_TIME: 'LastGoogleDriveToXrpSaveTime',
11-
LAST_GOOGLE_DRIVE_TO_XRP_SAVE_TIME_CONFIG: 'LastGoogleDriveToXrpSaveTimeConfig',
1211
} as const;
1312

1413
export type StorageKeysType = (typeof StorageKeys)[keyof typeof StorageKeys];

0 commit comments

Comments
 (0)