Skip to content

'Back to Editor' links to the last opened project (Fixes #2175) #2178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions client/components/Nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { logoutUser } from '../modules/User/actions';
import getConfig from '../utils/getConfig';
import { metaKeyName, metaKey } from '../utils/metaKey';
import { getIsUserOwner } from '../modules/IDE/selectors/users';
import { selectSketchPath } from '../modules/IDE/selectors/project';

import CaretLeftIcon from '../images/left-arrow.svg';
import TriangleIcon from '../images/down-filled-triangle.svg';
Expand Down Expand Up @@ -245,7 +246,7 @@ class Nav extends React.PureComponent {
/>
</li>
<li className="nav__item nav__item--no-icon">
<Link to="/" className="nav__back-link">
<Link to={this.props.editorLink} className="nav__back-link">
<CaretLeftIcon
className="nav__back-icon"
focusable="false"
Expand Down Expand Up @@ -990,7 +991,8 @@ Nav.propTypes = {
t: PropTypes.func.isRequired,
setLanguage: PropTypes.func.isRequired,
language: PropTypes.string.isRequired,
isUserOwner: PropTypes.bool.isRequired
isUserOwner: PropTypes.bool.isRequired,
editorLink: PropTypes.string
};

Nav.defaultProps = {
Expand All @@ -1003,7 +1005,8 @@ Nav.defaultProps = {
warnIfUnsavedChanges: undefined,
params: {
username: undefined
}
},
editorLink: '/'
};

function mapStateToProps(state) {
Expand All @@ -1013,7 +1016,8 @@ function mapStateToProps(state) {
unsavedChanges: state.ide.unsavedChanges,
rootFile: state.files.filter((file) => file.name === 'root')[0],
language: state.preferences.language,
isUserOwner: getIsUserOwner(state)
isUserOwner: getIsUserOwner(state),
editorLink: selectSketchPath(state)
};
}

Expand Down
10 changes: 10 additions & 0 deletions client/modules/IDE/selectors/project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createSelector } from 'reselect';

export const selectProjectOwner = (state) => state.project.owner;
export const selectProjectId = (state) => state.project.id;

export const selectSketchPath = createSelector(
selectProjectOwner,
selectProjectId,
(owner, id) => (owner && id ? `/${owner.username}/sketches/${id}` : '/')
);