Skip to content

Commit ff360f4

Browse files
committed
refactored CodeEditor to use content of open files
1 parent 41a3e8d commit ff360f4

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

src/public/containers/editor/CodeEditor.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import { MonacoEditor } from '../../components/editor/MonacoEditor';
66

77

88
const mapStateToProps = (state: SockscodeState) => {
9-
return { code: state.code };
9+
const { open } = state.fileList;
10+
if (open) {
11+
const file = state.fileList.files.get(open);
12+
return { code: file.content };
13+
}
14+
15+
return { code: '' };
1016
}
1117

1218
const mapDispatchToProps = (dispatch: Dispatch<{}>) => {

src/public/containers/files/FileItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface FileItemState {
3434
@CSSModules(styles)
3535
class FileItem extends React.Component<FileItemProps, FileItemState>{
3636
render() {
37-
const { onExpandCollapse, onFileOpen, fileId, file, ...other } = this.props;
37+
const { onExpandCollapse, onFileOpen, fileId, file, parentFileId, ...other } = this.props;
3838
return <ListItem
3939
key={fileId}
4040
value={fileId}

src/public/reducers/Code.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/public/reducers/FileList.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { EXPAND_COLLAPSE, OPEN_FILE, FileListActions } from '../actions/FileListActions';
2+
import { CodeChangedLocalAction, CodeChangedRemoteAction, CODE_CHANGED_LOCAL, CODE_CHANGED_REMOTE } from '../actions/Actions';
23
import { Map, fromJS } from "immutable";
34

45
export interface TreeFile {
@@ -251,19 +252,28 @@ let filesFiles = Map<FileId, File>().withMutations((map) => {
251252
const dummyState: FileListState = { files: filesFiles, open: null };
252253
(window as any).zzz = dummyState;
253254

254-
const reducer = (state = dummyState, action: FileListActions) => {
255+
const reducer = (state = dummyState, action: FileListActions | CodeChangedLocalAction | CodeChangedRemoteAction) => {
255256
console.log(action);
256257
switch (action.type) {
257-
case EXPAND_COLLAPSE:
258+
case EXPAND_COLLAPSE: {
258259
const { fileId } = action;
259260
const file = state.files.get(fileId);
260261
const newFile: File = Object.assign({}, file, { isExpanded: !file.isExpanded });
261262
return Object.assign({}, state, { files: state.files.set(fileId, newFile) });
262-
case OPEN_FILE:
263+
}
264+
case OPEN_FILE: {
263265
return Object.assign({}, state, { open: action.fileId });
264-
default:
265-
return state;
266+
}
267+
case CODE_CHANGED_LOCAL: case CODE_CHANGED_REMOTE: {
268+
const openFileId = state.open;
269+
if (openFileId) {
270+
const openFile = state.files.get(openFileId);
271+
const newFile: File = Object.assign({}, openFile, { content: action.code });
272+
return Object.assign({}, state, { files: state.files.set(openFileId, newFile) });
273+
}
274+
}
266275
}
276+
return state;
267277
}
268278

269279
export const fileList = reducer;

src/public/reducers/Reducers.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { combineReducers } from 'redux'
22

3-
import { code } from './Code';
43
import { roomUuid } from './Room';
54
import { fileList, FileListState } from './FileList';
65

76
export interface SockscodeState {
8-
code: string,
97
roomUuid: string,
108
fileList: FileListState
119
}
1210

1311
export const sockscodeApp = combineReducers({
14-
code, roomUuid, fileList
12+
roomUuid, fileList
1513
});

0 commit comments

Comments
 (0)