Skip to content

Commit 9210a7e

Browse files
authored
Merge branch 'develop' into dependabot/npm_and_yarn/mongoose-5.13.20
2 parents e477b62 + 7c3ea21 commit 9210a7e

File tree

19 files changed

+395
-3191
lines changed

19 files changed

+395
-3191
lines changed

.storybook/preview.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React from 'react';
22
import { Provider } from 'react-redux';
3+
import { MemoryRouter } from 'react-router';
34

45
import ThemeProvider from '../client/modules/App/components/ThemeProvider';
56
import configureStore from '../client/store';
67
import '../client/i18n-test';
7-
import '../client/styles/build/css/main.css'
8+
import '../client/styles/storybook.css'
89

910
const initialState = window.__INITIAL_STATE__;
1011

@@ -13,9 +14,11 @@ const store = configureStore(initialState);
1314
export const decorators = [
1415
(Story) => (
1516
<Provider store={store}>
16-
<ThemeProvider>
17-
<Story />
18-
</ThemeProvider>
17+
<MemoryRouter>
18+
<ThemeProvider>
19+
<Story />
20+
</ThemeProvider>
21+
</MemoryRouter>
1922
</Provider>
2023
),
2124
]

client/common/icons.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Folder from '../images/folder-padded.svg';
2424
import CircleTerminal from '../images/circle-terminal.svg';
2525
import CircleFolder from '../images/circle-folder.svg';
2626
import CircleInfo from '../images/circle-info.svg';
27+
import Cross from '../images/cross.svg';
2728

2829
// HOC that adds the right web accessibility props
2930
// https://www.scottohara.me/blog/2019/05/22/contextual-images-svgs-and-a11y.html
@@ -94,9 +95,8 @@ export const MoreIcon = withLabel(More);
9495
export const TerminalIcon = withLabel(Terminal);
9596
export const CodeIcon = withLabel(Code);
9697
export const SaveIcon = withLabel(Save);
97-
9898
export const FolderIcon = withLabel(Folder);
99-
99+
export const CrossIcon = withLabel(Cross);
100100
export const CircleTerminalIcon = withLabel(CircleTerminal);
101101
export const CircleFolderIcon = withLabel(CircleFolder);
102102
export const CircleInfoIcon = withLabel(CircleInfo);

client/components/Nav/NavBar.jsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import React, {
66
useRef,
77
useState
88
} from 'react';
9+
import useKeyDownHandlers from '../../modules/IDE/hooks/useKeyDownHandlers';
910
import { MenuOpenContext, NavBarContext } from './contexts';
1011

1112
function NavBar({ children, className }) {
@@ -31,18 +32,9 @@ function NavBar({ children, className }) {
3132
};
3233
}, [nodeRef, setDropdownOpen]);
3334

34-
// TODO: replace with `useKeyDownHandlers` after #2052 is merged
35-
useEffect(() => {
36-
function handleKeyDown(e) {
37-
if (e.keyCode === 27) {
38-
setDropdownOpen('none');
39-
}
40-
}
41-
document.addEventListener('keydown', handleKeyDown, false);
42-
return () => {
43-
document.removeEventListener('keydown', handleKeyDown, false);
44-
};
45-
}, [setDropdownOpen]);
35+
useKeyDownHandlers({
36+
escape: () => setDropdownOpen('none')
37+
});
4638

4739
const clearHideTimeout = useCallback(() => {
4840
if (timerRef.current) {

client/images/cross.svg

Lines changed: 3 additions & 0 deletions
Loading

client/modules/App/components/Overlay.jsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ import { withTranslation } from 'react-i18next';
44

55
import browserHistory from '../../../browserHistory';
66
import ExitIcon from '../../../images/exit.svg';
7+
import { DocumentKeyDown } from '../../IDE/hooks/useKeyDownHandlers';
78

89
class Overlay extends React.Component {
910
constructor(props) {
1011
super(props);
1112
this.close = this.close.bind(this);
1213
this.handleClick = this.handleClick.bind(this);
1314
this.handleClickOutside = this.handleClickOutside.bind(this);
14-
this.keyPressHandle = this.keyPressHandle.bind(this);
1515
}
1616

1717
componentWillMount() {
1818
document.addEventListener('mousedown', this.handleClick, false);
19-
document.addEventListener('keydown', this.keyPressHandle);
2019
}
2120

2221
componentDidMount() {
@@ -25,7 +24,6 @@ class Overlay extends React.Component {
2524

2625
componentWillUnmount() {
2726
document.removeEventListener('mousedown', this.handleClick, false);
28-
document.removeEventListener('keydown', this.keyPressHandle);
2927
}
3028

3129
handleClick(e) {
@@ -40,14 +38,6 @@ class Overlay extends React.Component {
4038
this.close();
4139
}
4240

43-
keyPressHandle(e) {
44-
// escape key code = 27.
45-
// So here we are checking if the key pressed was Escape key.
46-
if (e.keyCode === 27) {
47-
this.close();
48-
}
49-
}
50-
5141
close() {
5242
// Only close if it is the last (and therefore the topmost overlay)
5343
const overlays = document.getElementsByClassName('overlay');
@@ -90,6 +80,7 @@ class Overlay extends React.Component {
9080
</div>
9181
</header>
9282
{children}
83+
<DocumentKeyDown handlers={{ escape: () => this.close() }} />
9384
</section>
9485
</div>
9586
</div>

client/modules/IDE/components/Header/MobileNav.jsx

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import NavMenuItem from '../../../../components/Nav/NavMenuItem';
1313
import { prop, remSize } from '../../../../theme';
1414
import AsteriskIcon from '../../../../images/p5-asterisk.svg';
1515
import IconButton from '../../../../components/mobile/IconButton';
16-
import { AccountIcon, EditorIcon, MoreIcon } from '../../../../common/icons';
16+
import {
17+
AccountIcon,
18+
EditorIcon,
19+
MoreIcon,
20+
CrossIcon
21+
} from '../../../../common/icons';
1722
import {
1823
newFile,
1924
newFolder,
@@ -237,26 +242,40 @@ const MobileNav = () => {
237242
<h5>by {project?.owner?.username}</h5>
238243
)}
239244
</Title>
240-
<Options>
241-
{user.authenticated ? (
242-
<AccountMenu />
243-
) : (
244-
<div>
245-
<Link to="/login">
246-
<IconButton icon={AccountIcon} />
247-
</Link>
248-
</div>
249-
)}
250-
{title === project.name ? (
251-
<MoreMenu />
252-
) : (
245+
246+
{/* check if the user is in login page */}
247+
{pathname === '/login' || pathname === '/signup' ? (
248+
// showing the login page
249+
<Options>
253250
<div>
254251
<Link to={editorLink}>
255-
<IconButton icon={EditorIcon} />
252+
<IconButton icon={CrossIcon} />
256253
</Link>
257254
</div>
258-
)}
259-
</Options>
255+
</Options>
256+
) : (
257+
<Options>
258+
{/* checking if user is logged in or not */}
259+
{user.authenticated ? (
260+
<AccountMenu />
261+
) : (
262+
<div>
263+
<Link to="/login">
264+
<IconButton icon={AccountIcon} />
265+
</Link>
266+
</div>
267+
)}
268+
{title === project.name ? (
269+
<MoreMenu />
270+
) : (
271+
<div>
272+
<Link to={editorLink}>
273+
<IconButton icon={EditorIcon} />
274+
</Link>
275+
</div>
276+
)}
277+
</Options>
278+
)}
260279
</Nav>
261280
);
262281
};

client/modules/IDE/components/Header/__snapshots__/Nav.unit.test.jsx.snap

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ exports[`Nav renders dashboard version for mobile 1`] = `
4848
<DocumentFragment>
4949
<header>
5050
<nav
51-
class="sc-giAqHp deBDHC"
51+
class="sc-ezzafa bZzfr"
5252
>
5353
<div
54-
class="sc-ezzafa bKgrFx"
54+
class="sc-bYwzuL bIGdtt"
5555
>
5656
<test-file-stub />
5757
</div>
5858
<div
59-
class="sc-bYwzuL lkVxhY"
59+
class="sc-kLojOw btKDXx"
6060
>
6161
<h1>
6262
<span
@@ -89,14 +89,14 @@ exports[`Nav renders dashboard version for mobile 1`] = `
8989
</h1>
9090
</div>
9191
<div
92-
class="sc-kLojOw casOUg"
92+
class="sc-iklJeh jupmlX"
9393
>
9494
<div>
9595
<a
9696
href="/login"
9797
>
9898
<button
99-
class="sc-jSFjdj fKQAQb sc-kEqXSa Ycwjo"
99+
class="sc-gKAaRy hWeMIn sc-kEqXSa Ycwjo"
100100
display="inline"
101101
focusable="false"
102102
kind="primary"
@@ -112,7 +112,7 @@ exports[`Nav renders dashboard version for mobile 1`] = `
112112
</div>
113113
<div>
114114
<button
115-
class="sc-jSFjdj fKQAQb sc-kEqXSa Ycwjo"
115+
class="sc-gKAaRy hWeMIn sc-kEqXSa Ycwjo"
116116
display="inline"
117117
focusable="false"
118118
kind="primary"
@@ -459,15 +459,15 @@ exports[`Nav renders editor version for mobile 1`] = `
459459
<DocumentFragment>
460460
<header>
461461
<nav
462-
class="sc-giAqHp deBDHC"
462+
class="sc-ezzafa bZzfr"
463463
>
464464
<div
465-
class="sc-ezzafa bKgrFx"
465+
class="sc-bYwzuL bIGdtt"
466466
>
467467
<test-file-stub />
468468
</div>
469469
<div
470-
class="sc-bYwzuL lkVxhY"
470+
class="sc-kLojOw btKDXx"
471471
>
472472
<h1>
473473
<span
@@ -500,14 +500,14 @@ exports[`Nav renders editor version for mobile 1`] = `
500500
</h1>
501501
</div>
502502
<div
503-
class="sc-kLojOw casOUg"
503+
class="sc-iklJeh jupmlX"
504504
>
505505
<div>
506506
<a
507507
href="/login"
508508
>
509509
<button
510-
class="sc-jSFjdj fKQAQb sc-kEqXSa Ycwjo"
510+
class="sc-gKAaRy hWeMIn sc-kEqXSa Ycwjo"
511511
display="inline"
512512
focusable="false"
513513
kind="primary"
@@ -523,7 +523,7 @@ exports[`Nav renders editor version for mobile 1`] = `
523523
</div>
524524
<div>
525525
<button
526-
class="sc-jSFjdj fKQAQb sc-kEqXSa Ycwjo"
526+
class="sc-gKAaRy hWeMIn sc-kEqXSa Ycwjo"
527527
display="inline"
528528
focusable="false"
529529
kind="primary"
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import PropTypes from 'prop-types';
2+
import { useDispatch, useSelector } from 'react-redux';
3+
import { updateFileContent } from '../actions/files';
4+
import {
5+
collapseConsole,
6+
collapseSidebar,
7+
expandConsole,
8+
expandSidebar,
9+
showErrorModal,
10+
startSketch,
11+
stopSketch
12+
} from '../actions/ide';
13+
import { setAllAccessibleOutput } from '../actions/preferences';
14+
import { cloneProject, saveProject } from '../actions/project';
15+
import useKeyDownHandlers from '../hooks/useKeyDownHandlers';
16+
import {
17+
getAuthenticated,
18+
getIsUserOwner,
19+
getSketchOwner
20+
} from '../selectors/users';
21+
22+
export const useIDEKeyHandlers = ({ getContent }) => {
23+
const dispatch = useDispatch();
24+
25+
const sidebarIsExpanded = useSelector((state) => state.ide.sidebarIsExpanded);
26+
const consoleIsExpanded = useSelector((state) => state.ide.consoleIsExpanded);
27+
28+
const isUserOwner = useSelector(getIsUserOwner);
29+
const isAuthenticated = useSelector(getAuthenticated);
30+
const sketchOwner = useSelector(getSketchOwner);
31+
32+
const syncFileContent = () => {
33+
const file = getContent();
34+
dispatch(updateFileContent(file.id, file.content));
35+
};
36+
37+
useKeyDownHandlers({
38+
'ctrl-s': (e) => {
39+
e.preventDefault();
40+
e.stopPropagation();
41+
if (isUserOwner || (isAuthenticated && !sketchOwner)) {
42+
dispatch(saveProject(getContent()));
43+
} else if (isAuthenticated) {
44+
dispatch(cloneProject());
45+
} else {
46+
dispatch(showErrorModal('forceAuthentication'));
47+
}
48+
},
49+
'ctrl-shift-enter': (e) => {
50+
e.preventDefault();
51+
e.stopPropagation();
52+
dispatch(stopSketch());
53+
},
54+
'ctrl-enter': (e) => {
55+
e.preventDefault();
56+
e.stopPropagation();
57+
syncFileContent();
58+
dispatch(startSketch());
59+
},
60+
'ctrl-shift-1': (e) => {
61+
e.preventDefault();
62+
dispatch(setAllAccessibleOutput(true));
63+
},
64+
'ctrl-shift-2': (e) => {
65+
e.preventDefault();
66+
dispatch(setAllAccessibleOutput(false));
67+
},
68+
'ctrl-b': (e) => {
69+
e.preventDefault();
70+
dispatch(
71+
// TODO: create actions 'toggleConsole', 'toggleSidebar', etc.
72+
sidebarIsExpanded ? collapseSidebar() : expandSidebar()
73+
);
74+
},
75+
'ctrl-`': (e) => {
76+
e.preventDefault();
77+
dispatch(consoleIsExpanded ? collapseConsole() : expandConsole());
78+
}
79+
});
80+
};
81+
82+
const IDEKeyHandlers = ({ getContent }) => {
83+
useIDEKeyHandlers({ getContent });
84+
return null;
85+
};
86+
87+
// Most actions can be accessed via redux, but those involving the cmController
88+
// must be provided via props.
89+
IDEKeyHandlers.propTypes = {
90+
getContent: PropTypes.func.isRequired
91+
};
92+
93+
export default IDEKeyHandlers;

0 commit comments

Comments
 (0)