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; return testName;
} }
export function updateFileContent(name, content) { export function updateFileContent(id, content) {
return { return {
type: ActionTypes.UPDATE_FILE_CONTENT, type: ActionTypes.UPDATE_FILE_CONTENT,
name, id,
content content
}; };
} }
@ -206,7 +206,7 @@ export function hideFolderChildren(id) {
export function setBlobUrl(file, blobURL) { export function setBlobUrl(file, blobURL) {
return { return {
type: ActionTypes.SET_BLOB_URL, type: ActionTypes.SET_BLOB_URL,
name: file.name, id: file.id,
blobURL blobURL
}; };
} }

View File

@ -116,7 +116,7 @@ class Editor extends React.Component {
this._cm.on('change', debounce(() => { this._cm.on('change', debounce(() => {
this.props.setUnsavedChanges(true); 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) { if (this.props.autorefresh && this.props.isPlaying) {
this.props.clearConsole(); this.props.clearConsole();
this.props.startRefreshSketch(); this.props.startRefreshSketch();

View File

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