Skip to content

Commit d6c1ce7

Browse files
github reading files wip
1 parent 6508dc7 commit d6c1ce7

File tree

13 files changed

+63
-17
lines changed

13 files changed

+63
-17
lines changed

src/commons/application/ApplicationTypes.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ export const defaultLanguageConfig: SALanguage = getDefaultLanguageConfig();
337337

338338
export const defaultPlayground: PlaygroundState = {
339339
githubSaveInfo: { repoName: '', filePath: '' },
340-
languageConfig: defaultLanguageConfig
340+
languageConfig: defaultLanguageConfig,
341+
repoName: ''
341342
};
342343

343344
export const defaultEditorValue = '// Type your program in here!';
@@ -365,7 +366,8 @@ export const createDefaultWorkspace = (workspaceLocation: WorkspaceLocation): Wo
365366
: undefined,
366367
value: ['playground', 'sourcecast'].includes(workspaceLocation) ? defaultEditorValue : '',
367368
highlightedLines: [],
368-
breakpoints: []
369+
breakpoints: [],
370+
githubSaveInfo: { repoName:'', filePath:''}
369371
}
370372
],
371373
programPrependValue: '',
@@ -433,7 +435,8 @@ export const defaultWorkspaceManager: WorkspaceManagerState = {
433435
filePath: getDefaultFilePath('playground'),
434436
value: defaultEditorValue,
435437
highlightedLines: [],
436-
breakpoints: []
438+
breakpoints: [],
439+
githubSaveInfo: {repoName:'', filePath:''}
437440
}
438441
]
439442
},
@@ -487,7 +490,8 @@ export const defaultWorkspaceManager: WorkspaceManagerState = {
487490
filePath: getDefaultFilePath('sicp'),
488491
value: defaultEditorValue,
489492
highlightedLines: [],
490-
breakpoints: []
493+
breakpoints: [],
494+
githubSaveInfo: {repoName:'', filePath:''}
491495
}
492496
]
493497
},

src/commons/assessmentWorkspace/AssessmentWorkspace.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ const AssessmentWorkspace: React.FC<AssessmentWorkspaceProps> = props => {
423423
const resetWorkspaceOptions = assertType<WorkspaceState>()({
424424
autogradingResults: options.autogradingResults ?? [],
425425
// TODO: Hardcoded to make use of the first editor tab. Rewrite after editor tabs are added.
426-
editorTabs: [{ value: options.editorValue ?? '', highlightedLines: [], breakpoints: [] }],
426+
editorTabs: [{ value: options.editorValue ?? '', highlightedLines: [], breakpoints: [], githubSaveInfo: {repoName: '', filePath: ''} }],
427427
programPrependValue: options.programPrependValue ?? '',
428428
programPostpendValue: options.programPostpendValue ?? '',
429429
editorTestcases: options.editorTestcases ?? []

src/commons/editingWorkspace/EditingWorkspace.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ const EditingWorkspace: React.FC<EditingWorkspaceProps> = props => {
321321
{
322322
value: editorValue,
323323
highlightedLines: [],
324-
breakpoints: []
324+
breakpoints: [],
325+
githubSaveInfo: {repoName: '', filePath: ''}
325326
}
326327
],
327328
programPrependValue,

src/commons/fileSystemView/FileSystemViewFileNode.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ 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 } from 'react-redux';
6+
import { useDispatch, useStore } from 'react-redux';
77
import classes from 'src/styles/FileSystemView.module.scss';
88

99
import { showSimpleConfirmDialog } from '../utils/DialogHelper';
@@ -12,6 +12,8 @@ import { WorkspaceLocation } from '../workspace/WorkspaceTypes';
1212
import FileSystemViewContextMenu from './FileSystemViewContextMenu';
1313
import FileSystemViewFileName from './FileSystemViewFileName';
1414
import FileSystemViewIndentationPadding from './FileSystemViewIndentationPadding';
15+
import { OverallState } from '../application/ApplicationTypes';
16+
import { actions } from '../utils/ActionsHelper';
1517

1618
type Props = {
1719
workspaceLocation: WorkspaceLocation;
@@ -32,19 +34,32 @@ const FileSystemViewFileNode: React.FC<Props> = ({
3234
}) => {
3335
const [isEditing, setIsEditing] = React.useState(false);
3436
const dispatch = useDispatch();
37+
const store = useStore<OverallState>();
3538

3639
const fullPath = path.join(basePath, fileName);
3740

3841
const handleOpenFile = () => {
39-
fileSystem.readFile(fullPath, 'utf-8', (err, fileContents) => {
42+
fileSystem.readFile(fullPath, 'utf-8', async (err, fileContents) => {
4043
if (err) {
4144
console.error(err);
4245
}
4346
if (fileContents === undefined) {
4447
throw new Error('File contents are undefined.');
4548
}
46-
4749
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+
store.dispatch(actions.updateEditorGithubSaveInfo(
56+
'playground',
57+
idx,
58+
repoName,
59+
editorFilePath,
60+
new Date()
61+
));
62+
console.log(store.getState().workspaces['playground'].editorTabs);
4863
});
4964
};
5065

src/commons/workspace/WorkspaceActions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ import {
7474
UPDATE_WORKSPACE,
7575
WorkspaceLocation,
7676
WorkspaceLocationsWithTools,
77-
WorkspaceState
77+
WorkspaceState,
78+
UPDATE_EDITOR_GITHUB_SAVE_INFO
7879
} from './WorkspaceTypes';
7980

8081
export const setTokenCount = createAction(
@@ -516,3 +517,4 @@ export const updateLastNonDetResult = createAction(
516517
payload: { lastNonDetResult, workspaceLocation }
517518
})
518519
);
520+

src/commons/workspace/WorkspaceReducer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ import {
9292
UPDATE_SUBMISSIONS_TABLE_FILTERS,
9393
UPDATE_WORKSPACE,
9494
WorkspaceLocation,
95-
WorkspaceManagerState
95+
WorkspaceManagerState,
96+
UPDATE_EDITOR_GITHUB_SAVE_INFO
9697
} from './WorkspaceTypes';
9798

9899
const getWorkspaceLocation = (action: any): WorkspaceLocation => {
@@ -837,7 +838,8 @@ const oldWorkspaceReducer: Reducer<WorkspaceManagerState, SourceActionType> = (
837838
filePath,
838839
value: editorValue,
839840
highlightedLines: [],
840-
breakpoints: []
841+
breakpoints: [],
842+
githubSaveInfo: {repoName: '', filePath: ''}
841843
};
842844
const newEditorTabs: EditorTabState[] = [
843845
...state[workspaceLocation].editorTabs,

src/commons/workspace/WorkspaceTypes.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { ExternalLibraryName } from '../application/types/ExternalTypes';
77
import { AutogradingResult, Testcase } from '../assessment/AssessmentTypes';
88
import { HighlightedLines, Position } from '../editor/EditorTypes';
99

10+
import { GitHubSaveInfo } from 'src/features/github/GitHubTypes';
11+
1012
export const ADD_HTML_CONSOLE_ERROR = 'ADD_HTML_CONSOLE_ERROR';
1113
export const BEGIN_CLEAR_CONTEXT = 'BEGIN_CLEAR_CONTEXT';
1214
export const BROWSE_REPL_HISTORY_DOWN = 'BROWSE_REPL_HISTORY_DOWN';
@@ -119,6 +121,7 @@ export type EditorTabState = {
119121
readonly highlightedLines: HighlightedLines[];
120122
readonly breakpoints: string[];
121123
readonly newCursorPosition?: Position;
124+
githubSaveInfo: GitHubSaveInfo;
122125
};
123126

124127
export type WorkspaceState = {
@@ -174,4 +177,4 @@ export type SubmissionsTableFilters = {
174177
export type TeamFormationsTableFilters = {
175178
columnFilters: { id: string; value: unknown }[];
176179
globalFilter: string | null;
177-
};
180+
};

src/features/github/GitHubUtils.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,10 @@ export async function openFolderInFolderMode(
308308
})
309309
})
310310
promise.then(() => {
311-
console.log("promises fulfilled");
311+
store.dispatch(actions.playgroundUpdateRepoName(repoName));
312+
console.log("promises fulfilled");
312313
refreshFileView();
314+
showSuccessMessage('Successfully loaded file!', 1000);
313315
})
314316
}
315317

src/features/playground/PlaygroundActions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
PLAYGROUND_UPDATE_PERSISTENCE_FILE,
1111
PLAYGROUND_UPDATE_PERSISTENCE_FOLDER,
1212
SHORTEN_URL,
13-
UPDATE_SHORT_URL
13+
UPDATE_SHORT_URL,
14+
PLAYGROUND_UPDATE_REPO_NAME
1415
} from './PlaygroundTypes';
1516

1617
export const generateLzString = createAction(GENERATE_LZ_STRING, () => ({ payload: {} }));
@@ -46,3 +47,8 @@ export const playgroundConfigLanguage = createAction(
4647
PLAYGROUND_UPDATE_LANGUAGE_CONFIG,
4748
(languageConfig: SALanguage) => ({ payload: languageConfig })
4849
);
50+
51+
export const playgroundUpdateRepoName = createAction(
52+
PLAYGROUND_UPDATE_REPO_NAME,
53+
(repoName: string) => ({ payload: repoName })
54+
);

src/features/playground/PlaygroundReducer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
PLAYGROUND_UPDATE_LANGUAGE_CONFIG,
99
PLAYGROUND_UPDATE_PERSISTENCE_FILE,
1010
PLAYGROUND_UPDATE_PERSISTENCE_FOLDER,
11+
PLAYGROUND_UPDATE_REPO_NAME,
1112
PlaygroundState,
1213
UPDATE_SHORT_URL
1314
} from './PlaygroundTypes';
@@ -41,12 +42,17 @@ export const PlaygroundReducer: Reducer<PlaygroundState, SourceActionType> = (
4142
return {
4243
...state,
4344
persistenceObject: action.payload
44-
}
45+
};
4546
case PLAYGROUND_UPDATE_LANGUAGE_CONFIG:
4647
return {
4748
...state,
4849
languageConfig: action.payload
4950
};
51+
case PLAYGROUND_UPDATE_REPO_NAME:
52+
return {
53+
...state,
54+
repoName: action.payload
55+
}
5056
default:
5157
return state;
5258
}

0 commit comments

Comments
 (0)