Skip to content

Commit d7804dc

Browse files
Revert "Merge branch 'folders-public-wip' of github.com:source-academy/frontend into folders-public-wip"
This reverts commit f45e429, reversing changes made to 9ce24c8.
1 parent 725ba18 commit d7804dc

File tree

10 files changed

+432
-301
lines changed

10 files changed

+432
-301
lines changed

src/commons/controlBar/github/ControlBarGitHubButtons.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import React from 'react';
55
import { useResponsive } from 'src/commons/utils/Hooks';
66
import { PersistenceFile } from 'src/features/persistence/PersistenceTypes';
77

8+
import { GitHubSaveInfo } from '../../../features/github/GitHubTypes';
89
import ControlButton from '../../ControlButton';
910

1011
type Props = {
1112
isFolderModeEnabled: boolean;
1213
workspaceLocation: string;
1314
currPersistenceFile?: PersistenceFile;
1415
loggedInAs?: Octokit;
15-
isDirty?: boolean;
16+
githubSaveInfo: GitHubSaveInfo;
17+
isDirty: boolean;
1618
isGDriveSynced: boolean;
1719
onClickOpen?: () => void;
1820
onClickSave?: () => void;
@@ -31,10 +33,9 @@ type Props = {
3133
export const ControlBarGitHubButtons: React.FC<Props> = props => {
3234
const { isMobileBreakpoint } = useResponsive();
3335

34-
const filePath = props.currPersistenceFile ? props.currPersistenceFile.path : '';
35-
console.log(filePath);
36+
const filePath = props.githubSaveInfo.filePath || '';
3637

37-
const isNotPlayground = props.workspaceLocation !== 'playground';
38+
const isNotPlayground = props.workspaceLocation !== "playground";
3839

3940
const isLoggedIn = props.loggedInAs !== undefined;
4041
const shouldDisableButtons = !isLoggedIn;

src/commons/fileSystem/FileSystemReducer.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ export const FileSystemReducer: Reducer<FileSystemState, SourceActionType> = cre
134134
state.persistenceFileArray = newPersistenceFileArray;
135135
}
136136
})
137-
.addCase(deletePersistenceFolderAndChildren, (state, action) => {
138-
// check if github is syncing?
137+
.addCase(deletePersistenceFolderAndChildren, (state, action) => { // check if github is syncing?
139138
const newPersistenceFileArray = state['persistenceFileArray'].filter(
140139
e => e.id !== action.payload.id
141140
);
@@ -152,6 +151,7 @@ export const FileSystemReducer: Reducer<FileSystemState, SourceActionType> = cre
152151
.filter(e => {
153152
const r = filePathRegex.exec(e.path!)!;
154153
const currParentFolders = r[0].slice(1).split('/');
154+
console.log('currParentFolders', currParentFolders, 'folderLevel', currFolderLevel);
155155
if (currParentFolders.length <= currFolderLevel) {
156156
return true; // not a child of folder
157157
}
@@ -192,12 +192,15 @@ export const FileSystemReducer: Reducer<FileSystemState, SourceActionType> = cre
192192
// /fold1/fold2/ becomes ["fold1", "fold2"]
193193
// If in top level folder, becomes [""]
194194

195+
console.log(regexResult, currFolderSplit, 'a1');
196+
195197
// update all files that are its children
196198
state.persistenceFileArray = filesState
197199
.filter(e => e.path)
198200
.map(e => {
199201
const r = filePathRegex.exec(e.path!)!;
200202
const currParentFolders = r[0].slice(1).split('/');
203+
console.log('currParentFolders', currParentFolders, 'folderLevel', currFolderLevel);
201204
if (currParentFolders.length <= currFolderLevel) {
202205
return e; // not a child of folder
203206
}
@@ -208,6 +211,7 @@ export const FileSystemReducer: Reducer<FileSystemState, SourceActionType> = cre
208211
currParentFolders[currFolderLevel] = action.payload.newFolderName;
209212
currParentFolders[0] = '/' + currParentFolders[0];
210213
const newPath = currParentFolders.join('/');
214+
console.log('from', e.path, 'to', newPath);
211215
return { ...e, path: newPath };
212216
});
213217
})

src/commons/fileSystem/FileSystemUtils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ export const isGDriveSyncing = () => {
312312
}
313313

314314
return true;
315-
};
315+
}
316316

317317
export const isGithubSyncing = () => {
318318
const persistenceFileArray = store.getState().fileSystem.persistenceFileArray;
@@ -326,4 +326,4 @@ export const isGithubSyncing = () => {
326326
}
327327

328328
return true;
329-
};
329+
}

src/commons/fileSystemView/FileSystemViewDirectoryNode.tsx

+31-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { PersistenceFile } from 'src/features/persistence/PersistenceTypes';
1414
import classes from 'src/styles/FileSystemView.module.scss';
1515

16-
import { rmdirRecursively } from '../fileSystem/FileSystemUtils';
16+
import { isGDriveSyncing, isGithubSyncing, rmdirRecursively } from '../fileSystem/FileSystemUtils';
1717
import { showSimpleConfirmDialog, showSimpleErrorDialog } from '../utils/DialogHelper';
1818
import { removeEditorTabsForDirectory } from '../workspace/WorkspaceActions';
1919
import { WorkspaceLocation } from '../workspace/WorkspaceTypes';
@@ -90,8 +90,12 @@ const FileSystemViewDirectoryNode: React.FC<Props> = ({
9090
if (!shouldProceed) {
9191
return;
9292
}
93-
dispatch(persistenceDeleteFolder(fullPath));
94-
dispatch(githubDeleteFolder(fullPath));
93+
if (isGDriveSyncing()) {
94+
dispatch(persistenceDeleteFolder(fullPath));
95+
}
96+
if (isGithubSyncing()) {
97+
dispatch(githubDeleteFolder(fullPath));
98+
}
9599
dispatch(removeEditorTabsForDirectory(workspaceLocation, fullPath));
96100
rmdirRecursively(fileSystem, fullPath).then(refreshParentDirectory);
97101
});
@@ -124,8 +128,12 @@ const FileSystemViewDirectoryNode: React.FC<Props> = ({
124128
if (err) {
125129
console.error(err);
126130
}
127-
dispatch(persistenceCreateFile(newFilePath));
128-
dispatch(githubCreateFile(newFilePath));
131+
if (isGDriveSyncing()) {
132+
dispatch(persistenceCreateFile(newFilePath));
133+
}
134+
if (isGithubSyncing()) {
135+
dispatch(githubCreateFile(newFilePath));
136+
}
129137
forceRefreshFileSystemViewList();
130138
});
131139
});
@@ -155,6 +163,24 @@ const FileSystemViewDirectoryNode: React.FC<Props> = ({
155163
}
156164

157165
dispatch(persistenceCreateFolder(newDirectoryPath));
166+
// function informUserGithubCannotCreateFolder() {
167+
// return showSimpleConfirmDialog({
168+
// contents: (
169+
// <div>
170+
// <p>
171+
// Warning: Github is unable to create empty directories. When you create your first
172+
// file in this folder, Github will automatically sync this folder and the first
173+
// file.
174+
// </p>
175+
// <p>Please click 'Confirm' to continue.</p>
176+
// </div>
177+
// ),
178+
// positiveIntent: 'primary',
179+
// positiveLabel: 'Confirm'
180+
// });
181+
// }
182+
// informUserGithubCannotCreateFolder();
183+
// dispatch(enableFileSystemContextMenus());
158184
forceRefreshFileSystemViewList();
159185
});
160186
});

src/commons/fileSystemView/FileSystemViewFileName.tsx

+13-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
renameEditorTabsForDirectory
1616
} from '../workspace/WorkspaceActions';
1717
import { WorkspaceLocation } from '../workspace/WorkspaceTypes';
18+
import { isGDriveSyncing, isGithubSyncing } from '../fileSystem/FileSystemUtils';
1819

1920
type Props = {
2021
workspaceLocation: WorkspaceLocation;
@@ -74,12 +75,20 @@ const FileSystemViewFileName: React.FC<Props> = ({
7475
}
7576

7677
if (isDirectory) {
77-
dispatch(persistenceRenameFolder({ oldFolderPath: oldPath, newFolderPath: newPath }));
78-
dispatch(githubRenameFolder(oldPath, newPath));
78+
if (isGDriveSyncing()) {
79+
dispatch(persistenceRenameFolder({ oldFolderPath: oldPath, newFolderPath: newPath }));
80+
}
81+
if (isGithubSyncing()) {
82+
dispatch(githubRenameFolder(oldPath, newPath));
83+
}
7984
dispatch(renameEditorTabsForDirectory(workspaceLocation, oldPath, newPath));
8085
} else {
81-
dispatch(persistenceRenameFile({ oldFilePath: oldPath, newFilePath: newPath }));
82-
dispatch(githubRenameFile(oldPath, newPath));
86+
if (isGDriveSyncing()) {
87+
dispatch(persistenceRenameFile({ oldFilePath: oldPath, newFilePath: newPath }));
88+
}
89+
if (isGithubSyncing()) {
90+
dispatch(githubRenameFile(oldPath, newPath));
91+
}
8392
dispatch(renameEditorTabForFile(workspaceLocation, oldPath, newPath));
8493
}
8594
refreshDirectory();

src/commons/fileSystemView/FileSystemViewFileNode.tsx

+14-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { WorkspaceLocation } from '../workspace/WorkspaceTypes';
1515
import FileSystemViewContextMenu from './FileSystemViewContextMenu';
1616
import FileSystemViewFileName from './FileSystemViewFileName';
1717
import FileSystemViewIndentationPadding from './FileSystemViewIndentationPadding';
18+
import { isGDriveSyncing, isGithubSyncing } from '../fileSystem/FileSystemUtils';
1819

1920
type Props = {
2021
workspaceLocation: WorkspaceLocation;
@@ -60,6 +61,7 @@ const FileSystemViewFileNode: React.FC<Props> = ({
6061

6162
const [isEditing, setIsEditing] = React.useState(false);
6263
const dispatch = useDispatch();
64+
// const store = useStore<OverallState>();
6365

6466
const fullPath = path.join(basePath, fileName);
6567

@@ -72,6 +74,12 @@ const FileSystemViewFileNode: React.FC<Props> = ({
7274
throw new Error('File contents are undefined.');
7375
}
7476
dispatch(addEditorTab(workspaceLocation, fullPath, fileContents));
77+
// const idx = store.getState().workspaces['playground'].activeEditorTabIndex || 0;
78+
// const repoName = store.getState().playground.repoName || '';
79+
// const editorFilePath = store.getState().workspaces['playground'].editorTabs[idx].filePath || '';
80+
// console.log(repoName);
81+
// console.log(editorFilePath);
82+
// console.log(store.getState().workspaces['playground'].editorTabs);
7583
});
7684
};
7785

@@ -100,8 +108,12 @@ const FileSystemViewFileNode: React.FC<Props> = ({
100108
if (err) {
101109
console.error(err);
102110
}
103-
dispatch(persistenceDeleteFile(fullPath));
104-
dispatch(githubDeleteFile(fullPath));
111+
if (isGDriveSyncing()) {
112+
dispatch(persistenceDeleteFile(fullPath));
113+
}
114+
if (isGithubSyncing()) {
115+
dispatch(githubDeleteFile(fullPath));
116+
}
105117
dispatch(removeEditorTabForFile(workspaceLocation, fullPath));
106118
refreshDirectory();
107119
});

0 commit comments

Comments
 (0)