Skip to content

Commit ebcb2c9

Browse files
committed
Add orange/blue colours for FileSystemView
1 parent 6b06445 commit ebcb2c9

File tree

10 files changed

+102
-26
lines changed

10 files changed

+102
-26
lines changed

src/commons/fileSystem/FileSystemActions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
DELETE_ALL_PERSISTENCE_FILES, DELETE_GITHUB_SAVE_INFO,
1111
DELETE_PERSISTENCE_FILE,
1212
SET_IN_BROWSER_FILE_SYSTEM,
13-
UPDATE_GITHUB_SAVE_INFO } from './FileSystemTypes';
13+
UPDATE_GITHUB_SAVE_INFO,
14+
SET_PERSISTENCE_FILE_LAST_EDIT_BY_PATH } from './FileSystemTypes';
1415

1516
export const setInBrowserFileSystem = createAction(
1617
SET_IN_BROWSER_FILE_SYSTEM,
@@ -52,3 +53,8 @@ export const deleteAllPersistenceFiles = createAction(
5253
DELETE_ALL_PERSISTENCE_FILES,
5354
() => ({ payload: {} })
5455
);
56+
57+
export const setPersistenceFileLastEditByPath = createAction(
58+
SET_PERSISTENCE_FILE_LAST_EDIT_BY_PATH,
59+
(path: string, date: Date) => ({ payload: {path, date}})
60+
);

src/commons/fileSystem/FileSystemReducer.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
deleteAllGithubSaveInfo,
1010
deleteAllPersistenceFiles, deleteGithubSaveInfo,
1111
deletePersistenceFile,
12-
setInBrowserFileSystem } from './FileSystemActions';
12+
setInBrowserFileSystem,
13+
setPersistenceFileLastEditByPath} from './FileSystemActions';
1314
import { FileSystemState } from './FileSystemTypes';
1415

1516
export const FileSystemReducer: Reducer<FileSystemState, SourceActionType> = createReducer(
@@ -57,5 +58,15 @@ export const FileSystemReducer: Reducer<FileSystemState, SourceActionType> = cre
5758
.addCase(deleteAllPersistenceFiles, (state, action) => {
5859
state.persistenceFileArray = [];
5960
})
61+
.addCase(setPersistenceFileLastEditByPath, (state, action) => {
62+
const filesState = state['persistenceFileArray'];
63+
const persistenceFileFindIndex = filesState.findIndex(e => e.path === action.payload.path);
64+
if (persistenceFileFindIndex === -1) {
65+
return;
66+
}
67+
const newPersistenceFile = {...filesState[persistenceFileFindIndex], lastEdit: action.payload.date};
68+
filesState[persistenceFileFindIndex] = newPersistenceFile;
69+
state.persistenceFileArray = filesState;
70+
})
6071
}
6172
);

src/commons/fileSystem/FileSystemTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const DELETE_PERSISTENCE_FILE = 'DELETE_PERSISTENCE_FILE';
1010
export const DELETE_ALL_GITHUB_SAVE_INFO = 'DELETE_ALL_GITHUB_SAVE_INFO';
1111
export const UPDATE_GITHUB_SAVE_INFO = 'UPDATE_GITHUB_SAVE_INFO';
1212
export const DELETE_ALL_PERSISTENCE_FILES = 'DELETE_ALL_PERSISTENCE_FILES';
13+
export const SET_PERSISTENCE_FILE_LAST_EDIT_BY_PATH = 'SET_PERSISTENCE_FILE_LAST_EDIT_BY_PATH';
1314

1415
export type FileSystemState = {
1516
inBrowserFileSystem: FSModule | null;

src/commons/fileSystemView/FileSystemView.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ import FileSystemViewPlaceholderNode from './FileSystemViewPlaceholderNode';
1515
type Props = {
1616
workspaceLocation: WorkspaceLocation;
1717
basePath: string;
18+
lastEditedFilePath: string;
1819
};
1920

20-
const FileSystemView: React.FC<Props> = ({ workspaceLocation, basePath }) => {
21+
const FileSystemView: React.FC<Props> = ({ workspaceLocation, basePath, lastEditedFilePath }) => {
2122
const fileSystem = useTypedSelector(state => state.fileSystem.inBrowserFileSystem);
23+
const persistenceFileArray = useTypedSelector(state => state.fileSystem.persistenceFileArray);
24+
25+
console.log("lefp", lastEditedFilePath, "pfa", persistenceFileArray);
2226

2327
const [isAddingNewFile, setIsAddingNewFile] = React.useState(false);
2428
const [isAddingNewDirectory, setIsAddingNewDirectory] = React.useState(false);
@@ -99,6 +103,8 @@ const FileSystemView: React.FC<Props> = ({ workspaceLocation, basePath }) => {
99103
key={fileSystemViewListKey}
100104
fileSystem={fileSystem}
101105
basePath={basePath}
106+
lastEditedFilePath={lastEditedFilePath}
107+
persistenceFileArray={persistenceFileArray}
102108
indentationLevel={0}
103109
/>
104110
{isAddingNewFile && (

src/commons/fileSystemView/FileSystemViewDirectoryNode.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ import FileSystemViewFileName from './FileSystemViewFileName';
1616
import FileSystemViewIndentationPadding from './FileSystemViewIndentationPadding';
1717
import FileSystemViewList from './FileSystemViewList';
1818
import FileSystemViewPlaceholderNode from './FileSystemViewPlaceholderNode';
19+
import { PersistenceFile } from 'src/features/persistence/PersistenceTypes';
1920

2021
type Props = {
2122
workspaceLocation: WorkspaceLocation;
2223
fileSystem: FSModule;
2324
basePath: string;
25+
lastEditedFilePath: string;
26+
persistenceFileArray: PersistenceFile[];
2427
directoryName: string;
2528
indentationLevel: number;
2629
refreshParentDirectory: () => void;
@@ -30,6 +33,8 @@ const FileSystemViewDirectoryNode: React.FC<Props> = ({
3033
workspaceLocation,
3134
fileSystem,
3235
basePath,
36+
lastEditedFilePath,
37+
persistenceFileArray,
3338
directoryName,
3439
indentationLevel,
3540
refreshParentDirectory
@@ -196,6 +201,8 @@ const FileSystemViewDirectoryNode: React.FC<Props> = ({
196201
key={fileSystemViewListKey}
197202
fileSystem={fileSystem}
198203
basePath={fullPath}
204+
lastEditedFilePath={lastEditedFilePath}
205+
persistenceFileArray={persistenceFileArray}
199206
indentationLevel={indentationLevel + 1}
200207
/>
201208
)}

src/commons/fileSystemView/FileSystemViewFileNode.tsx

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
import { Icon } from '@blueprintjs/core';
1+
import { Colors, Icon } from '@blueprintjs/core';
22
import { IconNames } from '@blueprintjs/icons';
33
import { FSModule } from 'browserfs/dist/node/core/FS';
44
import path from 'path';
55
import React from 'react';
6-
import { useDispatch, useStore } from 'react-redux';
6+
import { useDispatch } from 'react-redux';
77
import { persistenceDeleteFile } from 'src/features/persistence/PersistenceActions';
88
import classes from 'src/styles/FileSystemView.module.scss';
99

10-
import { OverallState } from '../application/ApplicationTypes';
1110
import { showSimpleConfirmDialog } from '../utils/DialogHelper';
1211
import { addEditorTab, removeEditorTabForFile } from '../workspace/WorkspaceActions';
1312
import { WorkspaceLocation } from '../workspace/WorkspaceTypes';
1413
import FileSystemViewContextMenu from './FileSystemViewContextMenu';
1514
import FileSystemViewFileName from './FileSystemViewFileName';
1615
import FileSystemViewIndentationPadding from './FileSystemViewIndentationPadding';
16+
import { PersistenceFile } from 'src/features/persistence/PersistenceTypes';
1717

1818
type Props = {
1919
workspaceLocation: WorkspaceLocation;
2020
fileSystem: FSModule;
2121
basePath: string;
22+
lastEditedFilePath: string;
23+
persistenceFileArray: PersistenceFile[];
2224
fileName: string;
2325
indentationLevel: number;
2426
refreshDirectory: () => void;
@@ -28,13 +30,34 @@ const FileSystemViewFileNode: React.FC<Props> = ({
2830
workspaceLocation,
2931
fileSystem,
3032
basePath,
33+
lastEditedFilePath,
34+
persistenceFileArray,
3135
fileName,
3236
indentationLevel,
3337
refreshDirectory
3438
}) => {
39+
const [currColor, setCurrColor] = React.useState<string | undefined>(undefined);
40+
41+
React.useEffect(() => {
42+
const myFileMetadata = persistenceFileArray.filter(e => e.path === basePath+"/"+fileName)?.at(0);
43+
const checkColor = (myFileMetadata: PersistenceFile | undefined) =>
44+
myFileMetadata
45+
? myFileMetadata.lastSaved
46+
? myFileMetadata.lastEdit
47+
? myFileMetadata.lastEdit > myFileMetadata.lastSaved
48+
? Colors.ORANGE4
49+
: Colors.BLUE4
50+
: Colors.BLUE4
51+
: Colors.BLUE4
52+
: undefined;
53+
setCurrColor(checkColor(myFileMetadata));
54+
}, [lastEditedFilePath]);
55+
56+
3557
const [isEditing, setIsEditing] = React.useState(false);
3658
const dispatch = useDispatch();
37-
const store = useStore<OverallState>();
59+
// const store = useStore<OverallState>();
60+
3861

3962
const fullPath = path.join(basePath, fileName);
4063

@@ -47,12 +70,12 @@ const FileSystemViewFileNode: React.FC<Props> = ({
4770
throw new Error('File contents are undefined.');
4871
}
4972
dispatch(addEditorTab(workspaceLocation, fullPath, fileContents));
50-
const idx = store.getState().workspaces['playground'].activeEditorTabIndex || 0;
51-
const repoName = store.getState().playground.repoName || '';
52-
const editorFilePath = store.getState().workspaces['playground'].editorTabs[idx].filePath || '';
53-
console.log(repoName);
54-
console.log(editorFilePath);
55-
console.log(store.getState().workspaces['playground'].editorTabs);
73+
// const idx = store.getState().workspaces['playground'].activeEditorTabIndex || 0;
74+
// const repoName = store.getState().playground.repoName || '';
75+
// const editorFilePath = store.getState().workspaces['playground'].editorTabs[idx].filePath || '';
76+
// console.log(repoName);
77+
// console.log(editorFilePath);
78+
// console.log(store.getState().workspaces['playground'].editorTabs);
5679
});
5780
};
5881

@@ -103,7 +126,10 @@ const FileSystemViewFileNode: React.FC<Props> = ({
103126
>
104127
<div className={classes['file-system-view-node-container']} onClick={onClick}>
105128
<FileSystemViewIndentationPadding indentationLevel={indentationLevel} />
106-
<Icon icon={IconNames.DOCUMENT} />
129+
<Icon
130+
icon={IconNames.DOCUMENT}
131+
style={{color: currColor}}
132+
/>
107133
<FileSystemViewFileName
108134
workspaceLocation={workspaceLocation}
109135
fileSystem={fileSystem}

src/commons/fileSystemView/FileSystemViewList.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ import Delay from '../delay/Delay';
88
import { WorkspaceLocation } from '../workspace/WorkspaceTypes';
99
import FileSystemViewDirectoryNode from './FileSystemViewDirectoryNode';
1010
import FileSystemViewFileNode from './FileSystemViewFileNode';
11+
import { PersistenceFile } from 'src/features/persistence/PersistenceTypes';
1112

1213
type Props = {
1314
workspaceLocation: WorkspaceLocation;
1415
fileSystem: FSModule;
1516
basePath: string;
17+
lastEditedFilePath: string;
18+
persistenceFileArray: PersistenceFile[];
1619
indentationLevel: number;
1720
};
1821

@@ -22,6 +25,8 @@ const FileSystemViewList: React.FC<Props> = ({
2225
workspaceLocation,
2326
fileSystem,
2427
basePath,
28+
lastEditedFilePath,
29+
persistenceFileArray,
2530
indentationLevel
2631
}) => {
2732
const [dirNames, setDirNames] = React.useState<string[] | undefined>(undefined);
@@ -88,6 +93,8 @@ const FileSystemViewList: React.FC<Props> = ({
8893
key={dirName}
8994
fileSystem={fileSystem}
9095
basePath={basePath}
96+
lastEditedFilePath={lastEditedFilePath}
97+
persistenceFileArray={persistenceFileArray}
9198
directoryName={dirName}
9299
indentationLevel={indentationLevel}
93100
refreshParentDirectory={readDirectory}
@@ -101,6 +108,8 @@ const FileSystemViewList: React.FC<Props> = ({
101108
key={fileName}
102109
fileSystem={fileSystem}
103110
basePath={basePath}
111+
lastEditedFilePath={lastEditedFilePath}
112+
persistenceFileArray={persistenceFileArray}
104113
fileName={fileName}
105114
indentationLevel={indentationLevel}
106115
refreshDirectory={readDirectory}

src/commons/sagas/PersistenceSaga.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
} from '../utils/notifications/NotificationsHelper';
3737
import { AsyncReturnType } from '../utils/TypeHelper';
3838
import { safeTakeEvery as takeEvery, safeTakeLatest as takeLatest } from './SafeEffects';
39+
import { WORKSPACE_BASE_PATHS } from 'src/pages/fileSystem/createInBrowserFileSystem';
3940

4041
const DISCOVERY_DOCS = ['https://www.googleapis.com/discovery/v1/apis/drive/v3/rest'];
4142
const SCOPES =
@@ -179,7 +180,7 @@ export function* persistenceSaga(): SagaIterator {
179180
yield call(console.log, test);
180181

181182
// refresh needed
182-
yield call(store.dispatch, actions.removeEditorTabsForDirectory("playground", "/")); // deletes all active tabs
183+
yield call(store.dispatch, actions.removeEditorTabsForDirectory("playground", WORKSPACE_BASE_PATHS["playground"])); // TODO hardcoded
183184
// TODO find a file to open instead of deleting all active tabs?
184185
// TODO without modifying WorkspaceReducer in one function this would cause errors - called by onChange of Playground.tsx?
185186
// TODO change behaviour of WorkspaceReducer to not create program.js every time folder mode changes with 0 tabs existing?

src/features/persistence/PersistenceTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ export type PersistenceFile = {
1818
name: string;
1919
path?: string; // only for persistenceFileArray
2020
lastSaved?: Date;
21+
lastEdit?: Date;
2122
isFolder?: boolean;
2223
};

src/pages/playground/Playground.tsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ import {
138138
makeSubstVisualizerTabFrom,
139139
mobileOnlyTabIds
140140
} from './PlaygroundTabs';
141+
import { setPersistenceFileLastEditByPath } from 'src/commons/fileSystem/FileSystemActions';
141142

142143
export type PlaygroundProps = {
143144
isSicpEditor?: boolean;
@@ -269,7 +270,7 @@ const Playground: React.FC<PlaygroundProps> = props => {
269270
state => state.playground
270271
);
271272
const githubSaveInfo = getGithubSaveInfo();
272-
console.log(githubSaveInfo);
273+
//console.log(githubSaveInfo);
273274
const {
274275
sourceChapter: courseSourceChapter,
275276
sourceVariant: courseSourceVariant,
@@ -408,15 +409,21 @@ const Playground: React.FC<PlaygroundProps> = props => {
408409
[isGreen]
409410
);
410411

411-
const onEditorValueChange = React.useCallback(
412-
(editorTabIndex: number, newEditorValue: string) => {
413-
setLastEdit(new Date());
414-
// TODO change editor tab label to reflect path of opened file?
415-
416-
handleEditorValueChange(editorTabIndex, newEditorValue);
417-
},
418-
[handleEditorValueChange]
419-
);
412+
const [lastEditedFilePath, setLastEditedFilePath] = useState<string>("");
413+
414+
const onEditorValueChange = (editorTabIndex: number, newEditorValue: string) => {
415+
const filePath = editorTabs[editorTabIndex]?.filePath;
416+
const editDate = new Date();
417+
if (filePath) {
418+
//console.log(editorTabs);
419+
console.log("dispatched " + filePath);
420+
dispatch(setPersistenceFileLastEditByPath(filePath, editDate));
421+
setLastEditedFilePath(filePath);
422+
}
423+
setLastEdit(editDate);
424+
// TODO change editor tab label to reflect path of opened file?
425+
handleEditorValueChange(editorTabIndex, newEditorValue);
426+
};
420427

421428
// const onChangeTabs = useCallback(
422429
// (
@@ -993,6 +1000,7 @@ const Playground: React.FC<PlaygroundProps> = props => {
9931000
<FileSystemView
9941001
workspaceLocation="playground"
9951002
basePath={WORKSPACE_BASE_PATHS[workspaceLocation]}
1003+
lastEditedFilePath={lastEditedFilePath}
9961004
/>
9971005
),
9981006
iconName: IconNames.FOLDER_CLOSE,
@@ -1002,7 +1010,7 @@ const Playground: React.FC<PlaygroundProps> = props => {
10021010
: [])
10031011
]
10041012
};
1005-
}, [isFolderModeEnabled, workspaceLocation]);
1013+
}, [isFolderModeEnabled, workspaceLocation, lastEditedFilePath]);
10061014

10071015
const workspaceProps: WorkspaceProps = {
10081016
controlBarProps: {

0 commit comments

Comments
 (0)