Skip to content

Commit 292b1ef

Browse files
streamlining ui behaviouor for github wip
1 parent 808ee63 commit 292b1ef

File tree

10 files changed

+306
-456
lines changed

10 files changed

+306
-456
lines changed

src/commons/controlBar/github/ControlBarGitHubButtons.tsx

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

9-
import { GitHubSaveInfo } from '../../../features/github/GitHubTypes';
109
import ControlButton from '../../ControlButton';
1110

1211
type Props = {
1312
isFolderModeEnabled: boolean;
1413
workspaceLocation: string;
1514
currPersistenceFile?: PersistenceFile;
1615
loggedInAs?: Octokit;
17-
githubSaveInfo: GitHubSaveInfo;
18-
isDirty: boolean;
16+
isDirty?: boolean;
1917
isGDriveSynced: boolean;
2018
onClickOpen?: () => void;
2119
onClickSave?: () => void;
@@ -34,9 +32,10 @@ type Props = {
3432
export const ControlBarGitHubButtons: React.FC<Props> = props => {
3533
const { isMobileBreakpoint } = useResponsive();
3634

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

39-
const isNotPlayground = props.workspaceLocation !== "playground";
38+
const isNotPlayground = props.workspaceLocation !== 'playground';
4039

4140
const isLoggedIn = props.loggedInAs !== undefined;
4241
const shouldDisableButtons = !isLoggedIn;

src/commons/fileSystem/FileSystemReducer.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ export const FileSystemReducer: Reducer<FileSystemState, SourceActionType> = cre
134134
state.persistenceFileArray = newPersistenceFileArray;
135135
}
136136
})
137-
.addCase(deletePersistenceFolderAndChildren, (state, action) => { // check if github is syncing?
137+
.addCase(deletePersistenceFolderAndChildren, (state, action) => {
138+
// check if github is syncing?
138139
const newPersistenceFileArray = state['persistenceFileArray'].filter(
139140
e => e.id !== action.payload.id
140141
);
@@ -151,7 +152,6 @@ export const FileSystemReducer: Reducer<FileSystemState, SourceActionType> = cre
151152
.filter(e => {
152153
const r = filePathRegex.exec(e.path!)!;
153154
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,15 +192,12 @@ 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-
197195
// update all files that are its children
198196
state.persistenceFileArray = filesState
199197
.filter(e => e.path)
200198
.map(e => {
201199
const r = filePathRegex.exec(e.path!)!;
202200
const currParentFolders = r[0].slice(1).split('/');
203-
console.log('currParentFolders', currParentFolders, 'folderLevel', currFolderLevel);
204201
if (currParentFolders.length <= currFolderLevel) {
205202
return e; // not a child of folder
206203
}
@@ -211,7 +208,6 @@ export const FileSystemReducer: Reducer<FileSystemState, SourceActionType> = cre
211208
currParentFolders[currFolderLevel] = action.payload.newFolderName;
212209
currParentFolders[0] = '/' + currParentFolders[0];
213210
const newPath = currParentFolders.join('/');
214-
console.log('from', e.path, 'to', newPath);
215211
return { ...e, path: newPath };
216212
});
217213
})

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

+5-31
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 { isGDriveSyncing, isGithubSyncing, rmdirRecursively } from '../fileSystem/FileSystemUtils';
16+
import { rmdirRecursively } from '../fileSystem/FileSystemUtils';
1717
import { showSimpleConfirmDialog, showSimpleErrorDialog } from '../utils/DialogHelper';
1818
import { removeEditorTabsForDirectory } from '../workspace/WorkspaceActions';
1919
import { WorkspaceLocation } from '../workspace/WorkspaceTypes';
@@ -90,12 +90,8 @@ const FileSystemViewDirectoryNode: React.FC<Props> = ({
9090
if (!shouldProceed) {
9191
return;
9292
}
93-
if (isGDriveSyncing()) {
94-
dispatch(persistenceDeleteFolder(fullPath));
95-
}
96-
if (isGithubSyncing()) {
97-
dispatch(githubDeleteFolder(fullPath));
98-
}
93+
dispatch(persistenceDeleteFolder(fullPath));
94+
dispatch(githubDeleteFolder(fullPath));
9995
dispatch(removeEditorTabsForDirectory(workspaceLocation, fullPath));
10096
rmdirRecursively(fileSystem, fullPath).then(refreshParentDirectory);
10197
});
@@ -128,12 +124,8 @@ const FileSystemViewDirectoryNode: React.FC<Props> = ({
128124
if (err) {
129125
console.error(err);
130126
}
131-
if (isGDriveSyncing()) {
132-
dispatch(persistenceCreateFile(newFilePath));
133-
}
134-
if (isGithubSyncing()) {
135-
dispatch(githubCreateFile(newFilePath));
136-
}
127+
dispatch(persistenceCreateFile(newFilePath));
128+
dispatch(githubCreateFile(newFilePath));
137129
forceRefreshFileSystemViewList();
138130
});
139131
});
@@ -163,24 +155,6 @@ const FileSystemViewDirectoryNode: React.FC<Props> = ({
163155
}
164156

165157
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());
184158
forceRefreshFileSystemViewList();
185159
});
186160
});

src/commons/fileSystemView/FileSystemViewFileName.tsx

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

2019
type Props = {
2120
workspaceLocation: WorkspaceLocation;
@@ -75,20 +74,12 @@ const FileSystemViewFileName: React.FC<Props> = ({
7574
}
7675

7776
if (isDirectory) {
78-
if (isGDriveSyncing()) {
79-
dispatch(persistenceRenameFolder({ oldFolderPath: oldPath, newFolderPath: newPath }));
80-
}
81-
if (isGithubSyncing()) {
82-
dispatch(githubRenameFolder(oldPath, newPath));
83-
}
77+
dispatch(persistenceRenameFolder({ oldFolderPath: oldPath, newFolderPath: newPath }));
78+
dispatch(githubRenameFolder(oldPath, newPath));
8479
dispatch(renameEditorTabsForDirectory(workspaceLocation, oldPath, newPath));
8580
} else {
86-
if (isGDriveSyncing()) {
87-
dispatch(persistenceRenameFile({ oldFilePath: oldPath, newFilePath: newPath }));
88-
}
89-
if (isGithubSyncing()) {
90-
dispatch(githubRenameFile(oldPath, newPath));
91-
}
81+
dispatch(persistenceRenameFile({ oldFilePath: oldPath, newFilePath: newPath }));
82+
dispatch(githubRenameFile(oldPath, newPath));
9283
dispatch(renameEditorTabForFile(workspaceLocation, oldPath, newPath));
9384
}
9485
refreshDirectory();

src/commons/fileSystemView/FileSystemViewFileNode.tsx

+2-14
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ 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';
1918

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

6261
const [isEditing, setIsEditing] = React.useState(false);
6362
const dispatch = useDispatch();
64-
// const store = useStore<OverallState>();
6563

6664
const fullPath = path.join(basePath, fileName);
6765

@@ -74,12 +72,6 @@ const FileSystemViewFileNode: React.FC<Props> = ({
7472
throw new Error('File contents are undefined.');
7573
}
7674
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);
8375
});
8476
};
8577

@@ -108,12 +100,8 @@ const FileSystemViewFileNode: React.FC<Props> = ({
108100
if (err) {
109101
console.error(err);
110102
}
111-
if (isGDriveSyncing()) {
112-
dispatch(persistenceDeleteFile(fullPath));
113-
}
114-
if (isGithubSyncing()) {
115-
dispatch(githubDeleteFile(fullPath));
116-
}
103+
dispatch(persistenceDeleteFile(fullPath));
104+
dispatch(githubDeleteFile(fullPath));
117105
dispatch(removeEditorTabForFile(workspaceLocation, fullPath));
118106
refreshDirectory();
119107
});

0 commit comments

Comments
 (0)