Skip to content

Commit af32c59

Browse files
sumomomomomolinedoestrolling
authored andcommitted
Skeleton for Google Drive Save All button
1 parent 6a45e2b commit af32c59

File tree

6 files changed

+59
-32
lines changed

6 files changed

+59
-32
lines changed

src/commons/controlBar/ControlBarGoogleDriveButtons.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Props = {
2121
isDirty?: boolean;
2222
onClickOpen?: () => any;
2323
onClickSave?: () => any;
24+
onClickSaveAll?: () => any;
2425
onClickSaveAs?: () => any;
2526
onClickLogOut?: () => any;
2627
onClickLogIn?: () => any;
@@ -71,7 +72,7 @@ export const ControlBarGoogleDriveButtons: React.FC<Props> = props => {
7172
<ControlButton
7273
label="Save All"
7374
icon={IconNames.DOUBLE_CHEVRON_UP}
74-
onClick={props.onClickSaveAs}
75+
onClick={props.onClickSaveAll}
7576
isDisabled={props.accessToken ? false : true}
7677
/>
7778
);

src/commons/sagas/PersistenceSaga.tsx

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { call, put, select } from 'redux-saga/effects';
77
import {
88
PERSISTENCE_INITIALISE,
99
PERSISTENCE_OPEN_PICKER,
10+
PERSISTENCE_SAVE_ALL,
1011
PERSISTENCE_SAVE_FILE,
1112
PERSISTENCE_SAVE_FILE_AS,
1213
PersistenceFile
@@ -100,10 +101,30 @@ export function* persistenceSaga(): SagaIterator {
100101
return;
101102
}
102103

104+
105+
const confirmOpen: boolean = yield call(showSimpleConfirmDialog, {
106+
title: 'Opening from Google Drive',
107+
contents: (
108+
<p>
109+
Opening <strong>{name}</strong> will overwrite the current contents of your workspace.
110+
Are you sure?
111+
</p>
112+
),
113+
positiveLabel: 'Open',
114+
negativeLabel: 'Cancel'
115+
});
116+
if (!confirmOpen) {
117+
return;
118+
}
119+
103120
// Note: for mimeType, text/plain -> file, application/vnd.google-apps.folder -> folder
104121

105122
if (mimeType === "application/vnd.google-apps.folder") { // handle folders
106-
yield call(console.log, "is folder");
123+
toastKey = yield call(showMessage, {
124+
message: 'Opening folder...',
125+
timeout: 0,
126+
intent: Intent.PRIMARY
127+
});
107128

108129
const fileList = yield call(getFilesOfFolder, id, name); // this needed the extra scope mimetypes to have every file
109130
// TODO: add type for each resp?
@@ -126,43 +147,30 @@ export function* persistenceSaga(): SagaIterator {
126147

127148

128149
for (const currFile of fileList) {
129-
// TODO add code to actually load contents here
130150
const contents = yield call([gapi.client.drive.files, 'get'], { fileId: currFile.id, alt: 'media' });
131151
yield call(writeFileRecursively, fileSystem, "/playground" + currFile.path, contents.body);
132152
}
133153

134-
135-
136-
137-
138-
139-
140-
141-
142-
143-
144-
154+
// set source to chapter 4 TODO is there a better way of handling this
155+
yield put(
156+
actions.chapterSelect(
157+
parseInt('4', 10) as Chapter,
158+
Variant.DEFAULT,
159+
'playground'
160+
)
161+
);
162+
// open folder mode
163+
yield call(store.dispatch, actions.setFolderMode("playground", true));
145164

146165
// refresh needed
147-
yield put(store.dispatch(actions.removeEditorTabsForDirectory("playground", "/"))); // deletes all active tabs
148-
yield call(refreshFileView); // refreshes folder view TODO super jank
149-
150-
return;
151-
}
166+
yield call(store.dispatch, actions.removeEditorTabsForDirectory("playground", "/")); // deletes all active tabs
167+
// TODO find a file to open instead of deleting all active tabs?
168+
// TODO without modifying WorkspaceReducer in one function this would cause errors - called by onChange of Playground.tsx?
169+
// TODO change behaviour of WorkspaceReducer to not create program.js every time folder mode changes with 0 tabs existing?
170+
yield call(refreshFileView); // refreshes folder view TODO super jank?
152171

172+
yield call(showSuccessMessage, `Loaded folder ${name}.`, 1000);
153173

154-
const confirmOpen: boolean = yield call(showSimpleConfirmDialog, {
155-
title: 'Opening from Google Drive',
156-
contents: (
157-
<p>
158-
Opening <strong>{name}</strong> will overwrite the current contents of your workspace.
159-
Are you sure?
160-
</p>
161-
),
162-
positiveLabel: 'Open',
163-
negativeLabel: 'Cancel'
164-
});
165-
if (!confirmOpen) {
166174
return;
167175
}
168176

@@ -335,6 +343,13 @@ export function* persistenceSaga(): SagaIterator {
335343
}
336344
});
337345

346+
yield takeEvery(
347+
PERSISTENCE_SAVE_ALL,
348+
function* () {
349+
yield console.log("pers save all!");
350+
}
351+
);
352+
338353
yield takeEvery(
339354
PERSISTENCE_SAVE_FILE,
340355
function* ({ payload: { id, name } }: ReturnType<typeof actions.persistenceSaveFile>) {

src/commons/workspace/WorkspaceReducer.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,11 @@ const oldWorkspaceReducer: Reducer<WorkspaceManagerState, SourceActionType> = (
746746
throw new Error('Editor tab index must be non-negative!');
747747
}
748748
if (editorTabIndex >= state[workspaceLocation].editorTabs.length) {
749+
// TODO WHY DOES THIS GET CALLED????????????????????? its from Playground.tsx onChange?
750+
if (editorTabIndex === 0) {
751+
console.log("Warning: editorTabIndex = 0");
752+
return {...state};
753+
}
749754
throw new Error('Editor tab index must have a corresponding editor tab!');
750755
}
751756

src/features/persistence/PersistenceActions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import { createAction } from '@reduxjs/toolkit';
33
import {
44
PERSISTENCE_INITIALISE,
55
PERSISTENCE_OPEN_PICKER,
6+
PERSISTENCE_SAVE_ALL,
67
PERSISTENCE_SAVE_FILE,
78
PERSISTENCE_SAVE_FILE_AS,
89
PersistenceFile
910
} from './PersistenceTypes';
1011

1112
export const persistenceOpenPicker = createAction(PERSISTENCE_OPEN_PICKER, () => ({ payload: {} }));
1213

14+
export const persistenceSaveAll = createAction(PERSISTENCE_SAVE_ALL, () => ({ payload: {} }));
15+
1316
export const persistenceSaveFile = createAction(PERSISTENCE_SAVE_FILE, (file: PersistenceFile) => ({
1417
payload: file
1518
}));

src/features/persistence/PersistenceTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export const PERSISTENCE_OPEN_PICKER = 'PERSISTENCE_OPEN_PICKER';
2+
export const PERSISTENCE_SAVE_ALL = 'PERSISTENCE_SAVE_ALL';
23
export const PERSISTENCE_SAVE_FILE_AS = 'PERSISTENCE_SAVE_FILE_AS';
34
export const PERSISTENCE_SAVE_FILE = 'PERSISTENCE_SAVE_FILE';
45
export const PERSISTENCE_INITIALISE = 'PERSISTENCE_INITIALISE';

src/pages/playground/Playground.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import {
7676
persistenceInitialise,
7777
persistenceOpenPicker,
7878
persistenceSaveFile,
79+
persistenceSaveAll,
7980
persistenceSaveFileAs
8081
} from 'src/features/persistence/PersistenceActions';
8182
import {
@@ -582,7 +583,7 @@ const Playground: React.FC<PlaygroundProps> = props => {
582583
[handleReplEval, isRunning, selectedTab]
583584
);
584585

585-
// Compute this here to avoid re-rendering the button every keystroke
586+
// Compute this here to avoid re-rendering the button every keystroke
586587
const persistenceIsDirty =
587588
persistenceFile && (!persistenceFile.lastSaved || persistenceFile.lastSaved < lastEdit);
588589
const persistenceButtons = useMemo(() => {
@@ -595,6 +596,7 @@ const Playground: React.FC<PlaygroundProps> = props => {
595596
accessToken={googleAccessToken}
596597
key="googledrive"
597598
onClickSaveAs={() => dispatch(persistenceSaveFileAs())}
599+
onClickSaveAll={() => dispatch(persistenceSaveAll())}
598600
onClickOpen={() => dispatch(persistenceOpenPicker())}
599601
onClickSave={
600602
persistenceFile ? () => dispatch(persistenceSaveFile(persistenceFile)) : undefined

0 commit comments

Comments
 (0)