Skip to content

Commit 3ff0503

Browse files
committed
Disable file context menus when saving/loading
1 parent ebcb2c9 commit 3ff0503

12 files changed

+104
-20
lines changed

src/commons/application/ApplicationTypes.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ export const defaultLanguageConfig: SALanguage = getDefaultLanguageConfig();
338338
export const defaultPlayground: PlaygroundState = {
339339
githubSaveInfo: { repoName: '', filePath: '' },
340340
languageConfig: defaultLanguageConfig,
341-
repoName: ''
341+
repoName: '',
342+
isFileSystemContextMenusDisabled: false
342343
};
343344

344345
export const defaultEditorValue = '// Type your program in here!';
@@ -349,7 +350,7 @@ export const defaultEditorValue = '// Type your program in here!';
349350
*
350351
* @param workspaceLocation the location of the workspace, used for context
351352
*/
352-
export const createDefaultWorkspace = (workspaceLocation: WorkspaceLocation): WorkspaceState => ({
353+
export const createDefaultWorkspace = (workspaceLocation: WorkspaceLocation): WorkspaceState => ({ // TODO remove default js
353354
autogradingResults: [],
354355
context: createContext<WorkspaceLocation>(
355356
Constants.defaultSourceChapter,
@@ -403,7 +404,7 @@ const defaultFileName = 'program.js';
403404
export const getDefaultFilePath = (workspaceLocation: WorkspaceLocation) =>
404405
`${WORKSPACE_BASE_PATHS[workspaceLocation]}/${defaultFileName}`;
405406

406-
export const defaultWorkspaceManager: WorkspaceManagerState = {
407+
export const defaultWorkspaceManager: WorkspaceManagerState = { // TODO default
407408
assessment: {
408409
...createDefaultWorkspace('assessment'),
409410
currentAssessment: undefined,

src/commons/controlBar/ControlBarToggleFolderModeButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export const ControlBarToggleFolderModeButton: React.FC<Props> = ({
3232
iconColor: isFolderModeEnabled ? Colors.BLUE4 : undefined
3333
}}
3434
onClick={toggleFolderMode}
35-
isDisabled={isSessionActive || isPersistenceActive}
35+
isDisabled ={false}
36+
//isDisabled={isSessionActive || isPersistenceActive}
3637
/>
3738
</Tooltip2>
3839
);

src/commons/fileSystemView/FileSystemView.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ type Props = {
1616
workspaceLocation: WorkspaceLocation;
1717
basePath: string;
1818
lastEditedFilePath: string;
19+
isContextMenuDisabled: boolean;
1920
};
2021

21-
const FileSystemView: React.FC<Props> = ({ workspaceLocation, basePath, lastEditedFilePath }) => {
22+
const FileSystemView: React.FC<Props> = ({ workspaceLocation, basePath, lastEditedFilePath, isContextMenuDisabled }) => {
2223
const fileSystem = useTypedSelector(state => state.fileSystem.inBrowserFileSystem);
2324
const persistenceFileArray = useTypedSelector(state => state.fileSystem.persistenceFileArray);
2425

@@ -106,6 +107,7 @@ const FileSystemView: React.FC<Props> = ({ workspaceLocation, basePath, lastEdit
106107
lastEditedFilePath={lastEditedFilePath}
107108
persistenceFileArray={persistenceFileArray}
108109
indentationLevel={0}
110+
isContextMenuDisabled={isContextMenuDisabled}
109111
/>
110112
{isAddingNewFile && (
111113
<div className={classes['file-system-view-node-container']}>
@@ -131,6 +133,7 @@ const FileSystemView: React.FC<Props> = ({ workspaceLocation, basePath, lastEdit
131133
className={classes['file-system-view-empty-space']}
132134
createNewFile={handleCreateNewFile}
133135
createNewDirectory={handleCreateNewDirectory}
136+
isContextMenuDisabled={isContextMenuDisabled}
134137
/>
135138
</div>
136139
);

src/commons/fileSystemView/FileSystemViewContextMenu.tsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import classes from 'src/styles/ContextMenu.module.scss';
77
type Props = {
88
children?: JSX.Element;
99
className?: string;
10+
isContextMenuDisabled: boolean;
1011
createNewFile?: () => void;
1112
createNewDirectory?: () => void;
1213
open?: () => void;
@@ -17,6 +18,7 @@ type Props = {
1718
const FileSystemViewContextMenu: React.FC<Props> = ({
1819
children,
1920
className,
21+
isContextMenuDisabled,
2022
createNewFile,
2123
createNewDirectory,
2224
open,
@@ -42,27 +44,47 @@ const FileSystemViewContextMenu: React.FC<Props> = ({
4244
onClose={() => toggleMenu(false)}
4345
>
4446
{createNewFile && (
45-
<MenuItem className={classes['context-menu-item']} onClick={createNewFile}>
47+
<MenuItem
48+
className={isContextMenuDisabled ? classes['context-menu-item-disabled'] : classes['context-menu-item']}
49+
onClick={createNewFile}
50+
disabled={isContextMenuDisabled}
51+
>
4652
New File
4753
</MenuItem>
4854
)}
4955
{createNewDirectory && (
50-
<MenuItem className={classes['context-menu-item']} onClick={createNewDirectory}>
56+
<MenuItem
57+
className={isContextMenuDisabled ? classes['context-menu-item-disabled'] : classes['context-menu-item']}
58+
onClick={createNewDirectory}
59+
disabled={isContextMenuDisabled}
60+
>
5161
New Directory
5262
</MenuItem>
5363
)}
5464
{open && (
55-
<MenuItem className={classes['context-menu-item']} onClick={open}>
65+
<MenuItem
66+
className={isContextMenuDisabled ? classes['context-menu-item-disabled'] : classes['context-menu-item']}
67+
onClick={open}
68+
disabled={isContextMenuDisabled}
69+
>
5670
Open
5771
</MenuItem>
5872
)}
5973
{rename && (
60-
<MenuItem className={classes['context-menu-item']} onClick={rename}>
74+
<MenuItem
75+
className={isContextMenuDisabled ? classes['context-menu-item-disabled'] : classes['context-menu-item']}
76+
onClick={rename}
77+
disabled={isContextMenuDisabled}
78+
>
6179
Rename
6280
</MenuItem>
6381
)}
6482
{remove && (
65-
<MenuItem className={classes['context-menu-item']} onClick={remove}>
83+
<MenuItem
84+
className={isContextMenuDisabled ? classes['context-menu-item-disabled'] : classes['context-menu-item']}
85+
onClick={remove}
86+
disabled={isContextMenuDisabled}
87+
>
6688
Delete
6789
</MenuItem>
6890
)}

src/commons/fileSystemView/FileSystemViewDirectoryNode.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Props = {
2727
directoryName: string;
2828
indentationLevel: number;
2929
refreshParentDirectory: () => void;
30+
isContextMenuDisabled: boolean;
3031
};
3132

3233
const FileSystemViewDirectoryNode: React.FC<Props> = ({
@@ -37,11 +38,12 @@ const FileSystemViewDirectoryNode: React.FC<Props> = ({
3738
persistenceFileArray,
3839
directoryName,
3940
indentationLevel,
40-
refreshParentDirectory
41+
refreshParentDirectory,
42+
isContextMenuDisabled
4143
}) => {
4244
const fullPath = path.join(basePath, directoryName);
4345

44-
const [isExpanded, setIsExpanded] = React.useState(false);
46+
const [isExpanded, setIsExpanded] = React.useState(true);
4547
const [isEditing, setIsEditing] = React.useState(false);
4648
const [isAddingNewFile, setIsAddingNewFile] = React.useState(false);
4749
const [isAddingNewDirectory, setIsAddingNewDirectory] = React.useState(false);
@@ -158,6 +160,7 @@ const FileSystemViewDirectoryNode: React.FC<Props> = ({
158160
createNewDirectory={handleCreateNewDirectory}
159161
rename={handleRenameDirectory}
160162
remove={handleRemoveDirectory}
163+
isContextMenuDisabled={isContextMenuDisabled}
161164
>
162165
<div className={classes['file-system-view-node-container']} onClick={toggleIsExpanded}>
163166
<FileSystemViewIndentationPadding indentationLevel={indentationLevel} />
@@ -204,6 +207,7 @@ const FileSystemViewDirectoryNode: React.FC<Props> = ({
204207
lastEditedFilePath={lastEditedFilePath}
205208
persistenceFileArray={persistenceFileArray}
206209
indentationLevel={indentationLevel + 1}
210+
isContextMenuDisabled={isContextMenuDisabled}
207211
/>
208212
)}
209213
</div>

src/commons/fileSystemView/FileSystemViewFileNode.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Props = {
2424
fileName: string;
2525
indentationLevel: number;
2626
refreshDirectory: () => void;
27+
isContextMenuDisabled: boolean;
2728
};
2829

2930
const FileSystemViewFileNode: React.FC<Props> = ({
@@ -34,7 +35,8 @@ const FileSystemViewFileNode: React.FC<Props> = ({
3435
persistenceFileArray,
3536
fileName,
3637
indentationLevel,
37-
refreshDirectory
38+
refreshDirectory,
39+
isContextMenuDisabled
3840
}) => {
3941
const [currColor, setCurrColor] = React.useState<string | undefined>(undefined);
4042

@@ -123,6 +125,7 @@ const FileSystemViewFileNode: React.FC<Props> = ({
123125
open={handleOpenFile}
124126
rename={handleRenameFile}
125127
remove={handleRemoveFile}
128+
isContextMenuDisabled={isContextMenuDisabled}
126129
>
127130
<div className={classes['file-system-view-node-container']} onClick={onClick}>
128131
<FileSystemViewIndentationPadding indentationLevel={indentationLevel} />

src/commons/fileSystemView/FileSystemViewList.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Props = {
1717
lastEditedFilePath: string;
1818
persistenceFileArray: PersistenceFile[];
1919
indentationLevel: number;
20+
isContextMenuDisabled: boolean;
2021
};
2122

2223
export let refreshFileView: () => any; // TODO jank
@@ -27,7 +28,8 @@ const FileSystemViewList: React.FC<Props> = ({
2728
basePath,
2829
lastEditedFilePath,
2930
persistenceFileArray,
30-
indentationLevel
31+
indentationLevel,
32+
isContextMenuDisabled
3133
}) => {
3234
const [dirNames, setDirNames] = React.useState<string[] | undefined>(undefined);
3335
const [fileNames, setFileNames] = React.useState<string[] | undefined>(undefined);
@@ -98,6 +100,7 @@ const FileSystemViewList: React.FC<Props> = ({
98100
directoryName={dirName}
99101
indentationLevel={indentationLevel}
100102
refreshParentDirectory={readDirectory}
103+
isContextMenuDisabled={isContextMenuDisabled}
101104
/>
102105
);
103106
})}
@@ -113,6 +116,7 @@ const FileSystemViewList: React.FC<Props> = ({
113116
fileName={fileName}
114117
indentationLevel={indentationLevel}
115118
refreshDirectory={readDirectory}
119+
isContextMenuDisabled={isContextMenuDisabled}
116120
/>
117121
);
118122
})}

src/commons/sagas/PersistenceSaga.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ export function* persistenceSaga(): SagaIterator {
126126
return;
127127
}
128128

129+
// Close folder mode TODO disable the button
130+
//yield call(store.dispatch, actions.setFolderMode("playground", false));
131+
yield call(store.dispatch, actions.disableFileSystemContextMenus());
132+
129133
// Note: for mimeType, text/plain -> file, application/vnd.google-apps.folder -> folder
130134

131135
if (mimeType === "application/vnd.google-apps.folder") { // handle folders
@@ -151,6 +155,8 @@ export function* persistenceSaga(): SagaIterator {
151155
}
152156
yield call(console.log, "there is a filesystem");
153157

158+
// Begin
159+
154160
// rm everything TODO replace everything hardcoded with playground?
155161
yield call(rmFilesInDirRecursively, fileSystem, "/playground");
156162

@@ -172,8 +178,9 @@ export function* persistenceSaga(): SagaIterator {
172178
'playground'
173179
)
174180
);
175-
// open folder mode
176-
yield call(store.dispatch, actions.setFolderMode("playground", true));
181+
// open folder mode TODO enable button
182+
//yield call(store.dispatch, actions.setFolderMode("playground", true));
183+
yield call(store.dispatch, actions.enableFileSystemContextMenus());
177184

178185
// DDDDDDDDDDDDDDDebug
179186
const test = yield select((state: OverallState) => state.fileSystem.persistenceFileArray);
@@ -436,6 +443,11 @@ export function* persistenceSaga(): SagaIterator {
436443
return;
437444
}
438445

446+
// Start actually saving
447+
// Turn off folder mode TODO disable folder mode
448+
//yield call (store.dispatch, actions.setFolderMode("playground", false));
449+
yield call(store.dispatch, actions.disableFileSystemContextMenus());
450+
439451
if (topLevelFolderName !== currFolderObject.name) {
440452
// top level folder name has been renamed
441453
yield call(console.log, "TLFN changed from ", currFolderObject.name, " to ", topLevelFolderName);
@@ -492,7 +504,6 @@ export function* persistenceSaga(): SagaIterator {
492504
currPersistenceFile.lastSaved = new Date();
493505
yield put(actions.addPersistenceFile(currPersistenceFile));
494506

495-
yield put(actions.playgroundUpdatePersistenceFolder({ id: currFolderObject.id, name: currFolderObject.name, parentId: currFolderObject.parentId, lastSaved: new Date() })); // TODO wut is this
496507
yield call(showSuccessMessage, `${currFileName} successfully saved to Google Drive.`, 1000);
497508

498509
// TODO: create getFileIdRecursively, that uses currFileParentFolderId
@@ -505,8 +516,13 @@ export function* persistenceSaga(): SagaIterator {
505516
}
506517

507518
// Ddededededebug
508-
const t: PersistenceFile[] = yield select((state: OverallState) => state.fileSystem.persistenceFileArray);
509-
yield call(console.log, t);
519+
//const t: PersistenceFile[] = yield select((state: OverallState) => state.fileSystem.persistenceFileArray);
520+
yield put(actions.playgroundUpdatePersistenceFolder({ id: currFolderObject.id, name: currFolderObject.name, parentId: currFolderObject.parentId, lastSaved: new Date() })); // TODO wut is this
521+
//yield call(console.log, t);
522+
523+
// Turn on folder mode TODO enable folder mode
524+
//yield call (store.dispatch, actions.setFolderMode("playground", true));
525+
yield call(store.dispatch, actions.enableFileSystemContextMenus());
510526

511527

512528
// Case 1: Open picker to select location for saving, similar to save all

src/features/playground/PlaygroundActions.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { SALanguage } from 'src/commons/application/ApplicationTypes';
44
import { PersistenceFile } from '../persistence/PersistenceTypes';
55
import {
66
CHANGE_QUERY_STRING,
7+
DISABLE_FILE_SYSTEM_CONTEXT_MENUS,
8+
ENABLE_FILE_SYSTEM_CONTEXT_MENUS,
79
GENERATE_LZ_STRING,
810
PLAYGROUND_UPDATE_GITHUB_SAVE_INFO,
911
PLAYGROUND_UPDATE_LANGUAGE_CONFIG,
@@ -51,3 +53,13 @@ export const playgroundUpdateRepoName = createAction(
5153
PLAYGROUND_UPDATE_REPO_NAME,
5254
(repoName: string) => ({ payload: repoName })
5355
);
56+
57+
export const disableFileSystemContextMenus = createAction(
58+
DISABLE_FILE_SYSTEM_CONTEXT_MENUS,
59+
() => ({ payload: {} })
60+
);
61+
62+
export const enableFileSystemContextMenus = createAction(
63+
ENABLE_FILE_SYSTEM_CONTEXT_MENUS,
64+
() => ({ payload: {} })
65+
);

src/features/playground/PlaygroundReducer.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
PLAYGROUND_UPDATE_PERSISTENCE_FILE,
1010
PLAYGROUND_UPDATE_PERSISTENCE_FOLDER,
1111
PLAYGROUND_UPDATE_REPO_NAME,
12+
DISABLE_FILE_SYSTEM_CONTEXT_MENUS,
13+
ENABLE_FILE_SYSTEM_CONTEXT_MENUS,
1214
PlaygroundState,
1315
UPDATE_SHORT_URL
1416
} from './PlaygroundTypes';
@@ -53,6 +55,16 @@ export const PlaygroundReducer: Reducer<PlaygroundState, SourceActionType> = (
5355
...state,
5456
repoName: action.payload
5557
}
58+
case DISABLE_FILE_SYSTEM_CONTEXT_MENUS:
59+
return {
60+
...state,
61+
isFileSystemContextMenusDisabled: true
62+
}
63+
case ENABLE_FILE_SYSTEM_CONTEXT_MENUS:
64+
return {
65+
...state,
66+
isFileSystemContextMenusDisabled: false
67+
}
5668
default:
5769
return state;
5870
}

0 commit comments

Comments
 (0)