Skip to content

Commit 0e06fb1

Browse files
committed
Clear persfilearray on logout GDrive; Fix Save As behaviour for single file mode GDrive
1 parent 4f9185a commit 0e06fb1

File tree

2 files changed

+49
-32
lines changed

2 files changed

+49
-32
lines changed

src/commons/controlBar/ControlBarGoogleDriveButtons.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ export const ControlBarGoogleDriveButtons: React.FC<Props> = props => {
8383
);
8484

8585
const loginButton = props.accessToken ? (
86-
<Tooltip2 content={`Logged in as ${props.loggedInAs}`} disabled={!props.loggedInAs}>
86+
<Tooltip content={`Logged in as ${props.loggedInAs}`} disabled={!props.loggedInAs}>
8787
<ControlButton label="Log Out" icon={IconNames.LOG_OUT} onClick={props.onClickLogOut} />
88-
</Tooltip2>
88+
</Tooltip>
8989
) : (
9090
<ControlButton label="Log In" icon={IconNames.LOG_IN} onClick={props.onClickLogIn} />
9191
);

src/commons/sagas/PersistenceSaga.tsx

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function* googleLogin() {
8282
export function* persistenceSaga(): SagaIterator {
8383
yield takeLatest(LOGOUT_GOOGLE, function* (): any {
8484
yield put(actions.playgroundUpdatePersistenceFile(undefined));
85+
yield call(store.dispatch, actions.deleteAllPersistenceFiles());
8586
yield call(ensureInitialised);
8687
yield call(gapi.client.setToken, null);
8788
yield put(actions.removeGoogleUserAndAccessToken());
@@ -348,23 +349,23 @@ export function* persistenceSaga(): SagaIterator {
348349
}
349350

350351
yield call(store.dispatch, actions.disableFileSystemContextMenus());
352+
353+
const [chapter, variant, external] = yield select((state: OverallState) => [
354+
state.workspaces.playground.context.chapter,
355+
state.workspaces.playground.context.variant,
356+
state.workspaces.playground.externalLibrary
357+
]);
358+
const config: IPlaygroundConfig = {
359+
chapter,
360+
variant,
361+
external
362+
};
351363
// Case: Picked a file to overwrite
352364
if (currPersistenceFile && currPersistenceFile.isFolder) {
353365
yield call(console.log, 'folder opened, handling save_as differently! overwriting file');
354366
// First case: Chosen location is within TLRF - so need to call methods to update PersistenceFileArray
355367
// Other case: Chosen location is outside TLRF - don't care
356368

357-
const [chapter, variant, external] = yield select((state: OverallState) => [
358-
state.workspaces.playground.context.chapter,
359-
state.workspaces.playground.context.variant,
360-
state.workspaces.playground.externalLibrary
361-
]);
362-
const config: IPlaygroundConfig = {
363-
chapter,
364-
variant,
365-
external
366-
};
367-
368369
yield call(
369370
console.log,
370371
'curr pers file ',
@@ -381,7 +382,6 @@ export function* persistenceSaga(): SagaIterator {
381382
timeout: 0,
382383
intent: Intent.PRIMARY
383384
});
384-
// identical to just saving a file locally
385385
const fileSystem: FSModule | null = yield select(
386386
(state: OverallState) => state.fileSystem.inBrowserFileSystem
387387
);
@@ -424,7 +424,13 @@ export function* persistenceSaga(): SagaIterator {
424424
})
425425
);
426426
}
427+
// Check if any editor tab is that updated file, and update contents
428+
const targetEditorTabIndex = (editorTabs as EditorTabState[]).findIndex(e => e.filePath === localFileTarget.path!);
429+
if (targetEditorTabIndex !== -1) {
430+
yield put(actions.updateEditorValue('playground', targetEditorTabIndex, code));
431+
}
427432
} else {
433+
// User overwriting file outside TLRF
428434
yield call(updateFile, pickedFile.id, pickedFile.name, MIME_SOURCE, code, config);
429435
}
430436
yield call(
@@ -434,10 +440,33 @@ export function* persistenceSaga(): SagaIterator {
434440
);
435441
return;
436442
}
437-
// Single file mode case
438-
const singleFileModePersFile: PersistenceFile = {...pickedFile, lastSaved: new Date(), path: '/playground/' + pickedFile.name};
439-
yield put(actions.playgroundUpdatePersistenceFile(singleFileModePersFile));
440-
yield put(actions.persistenceSaveFile(singleFileModePersFile));
443+
444+
// Chose to overwrite file - single file case
445+
if (currPersistenceFile && currPersistenceFile.id === pickedFile.id) {
446+
// User chose to overwrite the tracked file
447+
const newPersFile: PersistenceFile = {...pickedFile, lastSaved: new Date(), path: "/playground/" + pickedFile.name};
448+
// Update playground persistenceFile
449+
yield put(actions.playgroundUpdatePersistenceFile(newPersFile));
450+
// Update entry in persFileArray
451+
yield put(actions.addPersistenceFile(newPersFile));
452+
453+
}
454+
455+
// Save in Google Drive
456+
yield call(
457+
updateFile,
458+
pickedFile.id,
459+
pickedFile.name,
460+
MIME_SOURCE,
461+
code,
462+
config
463+
);
464+
465+
yield call(
466+
showSuccessMessage,
467+
`${pickedFile.name} successfully saved to Google Drive.`,
468+
1000
469+
);
441470
} else {
442471
const response: AsyncReturnType<typeof showSimplePromptDialog> = yield call(
443472
showSimplePromptDialog,
@@ -539,20 +568,8 @@ export function* persistenceSaga(): SagaIterator {
539568
}
540569

541570

542-
// Single file case
543-
const newPersFile: PersistenceFile = {...newFile, lastSaved: new Date(), path: "/playground/" + newFile.name};
544-
if (!currPersistenceFile) { // no file loaded prior
545-
// update playground pers file
546-
yield put(actions.playgroundUpdatePersistenceFile(newPersFile));
547-
// add new pers file to persFileArray
548-
} else { // file loaded prior
549-
// update playground pers file
550-
yield put(actions.playgroundUpdatePersistenceFile(newPersFile));
551-
// remove old pers file from persFileArray
552-
// add new pers file to persFileArray
553-
}
554-
555-
//
571+
// Case where playground PersistenceFile is in single file mode
572+
// Does nothing
556573
yield call(
557574
showSuccessMessage,
558575
`${response.value} successfully saved to Google Drive.`,

0 commit comments

Comments
 (0)