Skip to content

Commit cac7c80

Browse files
committed
Fix yarn format
1 parent f82aee2 commit cac7c80

File tree

8 files changed

+337
-251
lines changed

8 files changed

+337
-251
lines changed

src/commons/fileSystem/FileSystemActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const setInBrowserFileSystem = createAction(
2424

2525
export const addGithubSaveInfo = createAction(
2626
ADD_GITHUB_SAVE_INFO,
27-
(persistenceFile: PersistenceFile) => ({ payload: { persistenceFile }})
27+
(persistenceFile: PersistenceFile) => ({ payload: { persistenceFile } })
2828
);
2929

3030
export const deleteGithubSaveInfo = createAction(

src/commons/fileSystem/FileSystemReducer.ts

Lines changed: 93 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ export const FileSystemReducer: Reducer<FileSystemState, SourceActionType> = cre
2727
.addCase(setInBrowserFileSystem, (state, action) => {
2828
state.inBrowserFileSystem = action.payload.inBrowserFileSystem;
2929
})
30-
.addCase(addGithubSaveInfo, (state, action) => { // TODO rewrite
30+
.addCase(addGithubSaveInfo, (state, action) => {
31+
// TODO rewrite
3132
const persistenceFilePayload = action.payload.persistenceFile;
3233
const persistenceFileArray = state['persistenceFileArray'];
3334

3435
const saveInfoIndex = persistenceFileArray.findIndex(e => {
35-
return e.path === persistenceFilePayload.path &&
36-
e.repoName === persistenceFilePayload.repoName;
36+
return (
37+
e.path === persistenceFilePayload.path && e.repoName === persistenceFilePayload.repoName
38+
);
3739
});
3840
if (saveInfoIndex === -1) {
3941
persistenceFileArray[persistenceFileArray.length] = {
@@ -56,87 +58,104 @@ export const FileSystemReducer: Reducer<FileSystemState, SourceActionType> = cre
5658
};
5759
}
5860
state.persistenceFileArray = persistenceFileArray;
59-
})
60-
.addCase(deleteGithubSaveInfo, (state, action) => { // TODO rewrite - refer to deletePersistenceFile below
61-
const newPersistenceFileArray = state['persistenceFileArray'].filter(e => e.path !== action.payload.path);
62-
const isGDriveSyncing = action.payload.id ? true: false;
63-
if (isGDriveSyncing) {
64-
const newPersFile = {
65-
id: action.payload.id,
66-
name: action.payload.name,
67-
lastEdit: action.payload.lastEdit,
68-
lastSaved: action.payload.lastSaved,
69-
parentId: action.payload.parentId,
70-
path: action.payload.path
71-
};
72-
const newPersFileArray = newPersistenceFileArray.concat(newPersFile);
73-
state.persistenceFileArray = newPersFileArray;
74-
} else {
75-
state.persistenceFileArray = newPersistenceFileArray;
76-
}
77-
})
78-
.addCase(deleteAllGithubSaveInfo, (state, action) => {
79-
if (state.persistenceFileArray.length !== 0) {
80-
const isGDriveSyncing = state.persistenceFileArray[0].id ? true: false;
81-
const newPersistenceFileArray = state.persistenceFileArray;
61+
})
62+
.addCase(deleteGithubSaveInfo, (state, action) => {
63+
// TODO rewrite - refer to deletePersistenceFile below
64+
const newPersistenceFileArray = state['persistenceFileArray'].filter(
65+
e => e.path !== action.payload.path
66+
);
67+
const isGDriveSyncing = action.payload.id ? true : false;
8268
if (isGDriveSyncing) {
83-
newPersistenceFileArray.forEach(
84-
(persistenceFile, index) => {
69+
const newPersFile = {
70+
id: action.payload.id,
71+
name: action.payload.name,
72+
lastEdit: action.payload.lastEdit,
73+
lastSaved: action.payload.lastSaved,
74+
parentId: action.payload.parentId,
75+
path: action.payload.path
76+
};
77+
const newPersFileArray = newPersistenceFileArray.concat(newPersFile);
78+
state.persistenceFileArray = newPersFileArray;
79+
} else {
80+
state.persistenceFileArray = newPersistenceFileArray;
81+
}
82+
})
83+
.addCase(deleteAllGithubSaveInfo, (state, action) => {
84+
if (state.persistenceFileArray.length !== 0) {
85+
const isGDriveSyncing = state.persistenceFileArray[0].id ? true : false;
86+
const newPersistenceFileArray = state.persistenceFileArray;
87+
if (isGDriveSyncing) {
88+
newPersistenceFileArray.forEach((persistenceFile, index) => {
8589
newPersistenceFileArray[index] = {
8690
id: persistenceFile.id,
8791
name: persistenceFile.name,
8892
lastEdit: persistenceFile.lastEdit,
8993
lastSaved: persistenceFile.lastSaved,
9094
parentId: persistenceFile.parentId,
9195
path: persistenceFile.path
92-
}
93-
}
94-
)
95-
state.persistenceFileArray = newPersistenceFileArray;
96+
};
97+
});
98+
state.persistenceFileArray = newPersistenceFileArray;
99+
} else {
100+
state.persistenceFileArray = [];
101+
}
102+
}
103+
})
104+
.addCase(addPersistenceFile, (state, action) => {
105+
// TODO rewrite
106+
const persistenceFilePayload = action.payload;
107+
const persistenceFileArray = state['persistenceFileArray'];
108+
const persistenceFileIndex = persistenceFileArray.findIndex(
109+
e => e.id === persistenceFilePayload.id
110+
);
111+
if (persistenceFileIndex === -1) {
112+
persistenceFileArray[persistenceFileArray.length] = persistenceFilePayload;
96113
} else {
97-
state.persistenceFileArray = [];
114+
persistenceFileArray[persistenceFileIndex] = persistenceFilePayload;
98115
}
99-
}
100-
})
101-
.addCase(addPersistenceFile, (state, action) => { // TODO rewrite
102-
const persistenceFilePayload = action.payload;
103-
const persistenceFileArray = state['persistenceFileArray'];
104-
const persistenceFileIndex = persistenceFileArray.findIndex(e => e.id === persistenceFilePayload.id);
105-
if (persistenceFileIndex === -1) {
106-
persistenceFileArray[persistenceFileArray.length] = persistenceFilePayload;
107-
} else {
108-
persistenceFileArray[persistenceFileIndex] = persistenceFilePayload;
109-
}
110-
state.persistenceFileArray = persistenceFileArray;
111-
})
112-
.addCase(deletePersistenceFile, (state, action) => {
113-
const newPersistenceFileArray = state['persistenceFileArray'].filter(e => e.id !== action.payload.id);
114-
const isGitHubSyncing = action.payload.repoName ? true : false;
115-
if (isGitHubSyncing) {
116-
const newPersFile = {id: '', name: '', repoName: action.payload.repoName, path: action.payload.path};
117-
const newPersFileArray = newPersistenceFileArray.concat(newPersFile);
118-
state.persistenceFileArray = newPersFileArray;
119-
} else {
120-
state.persistenceFileArray = newPersistenceFileArray;
121-
}
122-
})
123-
.addCase(deleteAllPersistenceFiles, (state, action) => {
124-
state.persistenceFileArray = [];
125-
})
126-
.addCase(updatePersistenceFilePathAndNameByPath, (state, action) => {
127-
const filesState = state['persistenceFileArray'];
128-
const persistenceFileFindIndex = filesState.findIndex(e => e.path === action.payload.oldPath);
129-
if (persistenceFileFindIndex === -1) {
130-
return;
131-
}
132-
const newPersistenceFile = {...filesState[persistenceFileFindIndex], path: action.payload.newPath, name: action.payload.newFileName};
133-
filesState[persistenceFileFindIndex] = newPersistenceFile;
134-
state.persistenceFileArray = filesState;
135-
})
136-
.addCase(updatePersistenceFolderPathAndNameByPath, (state, action) => {
137-
const filesState = state['persistenceFileArray'];
138-
// get current level of folder
139-
const regexResult = /^(.*[\\\/])?(\.*.*?)(\.[^.]+?|)$/.exec(action.payload.newPath)!;
116+
state.persistenceFileArray = persistenceFileArray;
117+
})
118+
.addCase(deletePersistenceFile, (state, action) => {
119+
const newPersistenceFileArray = state['persistenceFileArray'].filter(
120+
e => e.id !== action.payload.id
121+
);
122+
const isGitHubSyncing = action.payload.repoName ? true : false;
123+
if (isGitHubSyncing) {
124+
const newPersFile = {
125+
id: '',
126+
name: '',
127+
repoName: action.payload.repoName,
128+
path: action.payload.path
129+
};
130+
const newPersFileArray = newPersistenceFileArray.concat(newPersFile);
131+
state.persistenceFileArray = newPersFileArray;
132+
} else {
133+
state.persistenceFileArray = newPersistenceFileArray;
134+
}
135+
})
136+
.addCase(deleteAllPersistenceFiles, (state, action) => {
137+
state.persistenceFileArray = [];
138+
})
139+
.addCase(updatePersistenceFilePathAndNameByPath, (state, action) => {
140+
const filesState = state['persistenceFileArray'];
141+
const persistenceFileFindIndex = filesState.findIndex(
142+
e => e.path === action.payload.oldPath
143+
);
144+
if (persistenceFileFindIndex === -1) {
145+
return;
146+
}
147+
const newPersistenceFile = {
148+
...filesState[persistenceFileFindIndex],
149+
path: action.payload.newPath,
150+
name: action.payload.newFileName
151+
};
152+
filesState[persistenceFileFindIndex] = newPersistenceFile;
153+
state.persistenceFileArray = filesState;
154+
})
155+
.addCase(updatePersistenceFolderPathAndNameByPath, (state, action) => {
156+
const filesState = state['persistenceFileArray'];
157+
// get current level of folder
158+
const regexResult = filePathRegex.exec(action.payload.newPath)!;
140159

141160
const currFolderSplit: string[] = regexResult[0].slice(1).split('/');
142161
const currFolderIndex = currFolderSplit.length - 1;

src/commons/fileSystem/FileSystemUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export const getGithubSaveInfo = () => {
285285
(persistenceFileArray[0] === undefined ? '' : persistenceFileArray[0].repoName)
286286
};
287287
return githubSaveInfo;
288-
}
288+
};
289289

290290
export const getPersistenceFile = (filePath: string) => {
291291
const persistenceFileArray = store.getState().fileSystem.persistenceFileArray;
@@ -294,6 +294,6 @@ export const getPersistenceFile = (filePath: string) => {
294294
return persistenceFile;
295295
}
296296
const persistenceFile = persistenceFileArray.find(e => e.path === filePath);
297-
297+
298298
return persistenceFile;
299-
}
299+
};

src/commons/fileSystemView/FileSystemViewDirectoryNode.tsx

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import { FSModule } from 'browserfs/dist/node/core/FS';
44
import path from 'path';
55
import React from 'react';
66
import { useDispatch } from 'react-redux';
7-
import { persistenceCreateFolder, persistenceDeleteFolder } from 'src/features/persistence/PersistenceActions';
7+
import { githubCreateFile, githubDeleteFolder } from 'src/features/github/GitHubActions';
8+
import {
9+
persistenceCreateFolder,
10+
persistenceDeleteFolder
11+
} from 'src/features/persistence/PersistenceActions';
12+
import { PersistenceFile } from 'src/features/persistence/PersistenceTypes';
813
import classes from 'src/styles/FileSystemView.module.scss';
914

1015
import { rmdirRecursively } from '../fileSystem/FileSystemUtils';
@@ -149,25 +154,25 @@ const FileSystemViewDirectoryNode: React.FC<Props> = ({
149154
}
150155

151156
dispatch(persistenceCreateFolder(newDirectoryPath));
152-
function informUserGithubCannotCreateFolder() {
153-
return showSimpleConfirmDialog({
154-
contents: (
155-
<div>
156-
<p>
157-
Warning: Github is unable to create empty directories. When you create your first
158-
file in this folder, Github will automatically sync this folder and the first
159-
file.
160-
</p>
161-
<p>Please click 'Confirm' to continue.</p>
162-
</div>
163-
),
164-
positiveIntent: 'primary',
165-
positiveLabel: 'Confirm'
166-
});
167-
}
168-
informUserGithubCannotCreateFolder();
169-
dispatch(enableFileSystemContextMenus());
170-
forceRefreshFileSystemViewList();
157+
// function informUserGithubCannotCreateFolder() {
158+
// return showSimpleConfirmDialog({
159+
// contents: (
160+
// <div>
161+
// <p>
162+
// Warning: Github is unable to create empty directories. When you create your first
163+
// file in this folder, Github will automatically sync this folder and the first
164+
// file.
165+
// </p>
166+
// <p>Please click 'Confirm' to continue.</p>
167+
// </div>
168+
// ),
169+
// positiveIntent: 'primary',
170+
// positiveLabel: 'Confirm'
171+
// });
172+
// }
173+
// informUserGithubCannotCreateFolder();
174+
// dispatch(enableFileSystemContextMenus());
175+
// forceRefreshFileSystemViewList();
171176
});
172177
});
173178
};

src/commons/gitHubOverlay/FileExplorerDialog.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import {
2626
performMultipleCreatingSave,
2727
performOverwritingSaveForSaveAs
2828
} from '../../features/github/GitHubUtils';
29+
import { getPersistenceFile } from '../fileSystem/FileSystemUtils';
2930
import { GitHubFileNodeData } from './GitHubFileNodeData';
3031
import { GitHubTreeNodeCreator } from './GitHubTreeNodeCreator';
31-
import { getPersistenceFile } from '../fileSystem/FileSystemUtils';
3232

3333
export type FileExplorerDialogProps = {
3434
repoName: string;
@@ -123,8 +123,18 @@ const FileExplorerDialog: React.FC<FileExplorerDialogProps> = props => {
123123
if (props.pickerType === 'Save All') {
124124
if (await checkIsFile(props.octokit, githubLoginID, props.repoName, filePath)) {
125125
} else {
126-
if (await checkFolderLocationIsValid(props.octokit, githubLoginID, props.repoName, filePath)) {
127-
performMultipleCreatingSave(props.octokit, githubLoginID, props.repoName, filePath, githubName, githubEmail, '');
126+
if (
127+
await checkFolderLocationIsValid(props.octokit, githubLoginID, props.repoName, filePath)
128+
) {
129+
performMultipleCreatingSave(
130+
props.octokit,
131+
githubLoginID,
132+
props.repoName,
133+
filePath,
134+
githubName,
135+
githubEmail,
136+
''
137+
);
128138
}
129139
}
130140
}
@@ -154,11 +164,14 @@ const FileExplorerDialog: React.FC<FileExplorerDialogProps> = props => {
154164
if (saveType === 'Create') {
155165
const persistenceFile = getPersistenceFile(filePath);
156166
if (persistenceFile === undefined) {
157-
throw new Error("persistence file not found for this filepath: " + filePath);
167+
throw new Error('persistence file not found for this filepath: ' + filePath);
158168
}
159169
const parentFolderPath = persistenceFile.parentFolderPath;
160170
if (parentFolderPath === undefined) {
161-
throw new Error("repository name or parentfolderpath not found for this persistencefile: " + persistenceFile);
171+
throw new Error(
172+
'repository name or parentfolderpath not found for this persistencefile: ' +
173+
persistenceFile
174+
);
162175
}
163176
performCreatingSave(
164177
props.octokit,

0 commit comments

Comments
 (0)