Skip to content

Commit

Permalink
Fix bug where you couldn't save after forking a notebook (#1781)
Browse files Browse the repository at this point in the history
sets notebookInfo.username to be same as userData.name when a notebook is
forked.
  • Loading branch information
hamilton authored and wlach committed May 6, 2019
1 parent 14fe775 commit d17d2a7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- only show notebooks with 10 or more edits on the server's index page list
- fixes bug where fetch chunks with errors don't halt further evaluation
- adds `arrayBuffer` type to fetch chunks (see docs)
- fix bug where you couldn't save a notebook after forking it

# 0.5.0 (2019-03-28)

Expand Down
11 changes: 10 additions & 1 deletion src/editor/actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export function moveCursorToNextChunk() {

export function createNewNotebookOnServer(options = { forkedFrom: undefined }) {
return async (dispatch, getState) => {
const { forkedFrom } = options;
const state = getState();
try {
const notebook = await createNotebookRequest(
Expand All @@ -261,8 +262,16 @@ export function createNewNotebookOnServer(options = { forkedFrom: undefined }) {
})
);
dispatch({ type: "ADD_NOTEBOOK_ID", id: notebook.id });
window.history.replaceState({}, "", `/notebooks/${notebook.id}`);
window.history.replaceState({}, "", `/notebooks/${notebook.id}/`);
dispatch({ type: "NOTEBOOK_SAVED" });
// update owner info, so we know that we can save
if (forkedFrom) {
dispatch({
type: "SET_NOTEBOOK_OWNER_IN_SESSION",
owner: state.userData,
forkedFrom
});
}
} catch (err) {
dispatch(
updateAppMessages({
Expand Down
11 changes: 11 additions & 0 deletions src/editor/reducers/notebook-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,17 @@ const notebookReducer = (state = newNotebook(), action) => {
});
}

case "SET_NOTEBOOK_OWNER_IN_SESSION": {
const { notebookInfo, userData } = state;
const newNotebookInfo = Object.assign({}, notebookInfo);
newNotebookInfo.username = userData.name;
newNotebookInfo.user_can_save = true;
newNotebookInfo.files = newNotebookInfo.files.map(f =>
Object.assign({}, f)
);
return Object.assign({}, state, { notebookInfo: newNotebookInfo });
}

default: {
return state;
}
Expand Down

0 comments on commit d17d2a7

Please sign in to comment.