Use File id in Redux Actions - Fixes #842 (#844)

Prevents file name collisions that are possible with the folder
system.
This commit is contained in:
Oliver Wright 2019-02-25 17:57:10 +00:00 committed by Cassie Tarakajian
parent 03d7533e2a
commit 5fdcd08add
3 changed files with 6 additions and 6 deletions

View file

@ -29,10 +29,10 @@ function createUniqueName(name, parentId, files) {
return testName;
}
export function updateFileContent(name, content) {
export function updateFileContent(id, content) {
return {
type: ActionTypes.UPDATE_FILE_CONTENT,
name,
id,
content
};
}
@ -206,7 +206,7 @@ export function hideFolderChildren(id) {
export function setBlobUrl(file, blobURL) {
return {
type: ActionTypes.SET_BLOB_URL,
name: file.name,
id: file.id,
blobURL
};
}

View file

@ -116,7 +116,7 @@ class Editor extends React.Component {
this._cm.on('change', debounce(() => {
this.props.setUnsavedChanges(true);
this.props.updateFileContent(this.props.file.name, this._cm.getValue());
this.props.updateFileContent(this.props.file.id, this._cm.getValue());
if (this.props.autorefresh && this.props.isPlaying) {
this.props.clearConsole();
this.props.startRefreshSketch();

View file

@ -118,7 +118,7 @@ const files = (state, action) => {
switch (action.type) {
case ActionTypes.UPDATE_FILE_CONTENT:
return state.map((file) => {
if (file.name !== action.name) {
if (file.id !== action.id) {
return file;
}
@ -126,7 +126,7 @@ const files = (state, action) => {
});
case ActionTypes.SET_BLOB_URL:
return state.map((file) => {
if (file.name !== action.name) {
if (file.id !== action.id) {
return file;
}
return Object.assign({}, file, { blobURL: action.blobURL });