Skip to content

Commit 776fe2a

Browse files
committed
Move to separate files.
1 parent 285b407 commit 776fe2a

File tree

10 files changed

+229
-208
lines changed

10 files changed

+229
-208
lines changed

client/modules/IDE/components/Toolbar.jsx

Lines changed: 0 additions & 206 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
import { useTranslation } from 'react-i18next';
3+
import { useDispatch, useSelector } from 'react-redux';
4+
import { setAutorefresh } from '../../actions/preferences';
5+
6+
export default function AutoRefreshCheckbox() {
7+
const { t } = useTranslation();
8+
const dispatch = useDispatch();
9+
10+
const autorefresh = useSelector((state) => state.preferences.autorefresh);
11+
12+
return (
13+
<div className="toolbar__autorefresh">
14+
<input
15+
id="autorefresh"
16+
className="checkbox__autorefresh"
17+
type="checkbox"
18+
checked={autorefresh}
19+
onChange={(event) => {
20+
dispatch(setAutorefresh(event.target.checked));
21+
}}
22+
/>
23+
<label htmlFor="autorefresh" className="toolbar__autorefresh-label">
24+
{t('Toolbar.Auto-refresh')}
25+
</label>
26+
</div>
27+
);
28+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
import { useTranslation } from 'react-i18next';
3+
import { useDispatch, useSelector } from 'react-redux';
4+
import { saveProject, setProjectName } from '../../actions/project';
5+
import { selectProjectId, selectProjectName } from '../../selectors/project';
6+
import { selectCanEditSketch } from '../../selectors/users';
7+
import EditableInput from '../EditableInput';
8+
9+
export default function EditableProjectName() {
10+
const { t } = useTranslation();
11+
const dispatch = useDispatch();
12+
13+
const projectId = useSelector(selectProjectId);
14+
const projectName = useSelector(selectProjectName);
15+
const canEditProjectName = useSelector(selectCanEditSketch);
16+
17+
const handleProjectNameSave = (value) => {
18+
const newProjectName = value.trim();
19+
dispatch(setProjectName(newProjectName));
20+
if (projectId) {
21+
dispatch(saveProject());
22+
}
23+
};
24+
25+
return (
26+
<EditableInput
27+
value={projectName}
28+
disabled={!canEditProjectName}
29+
aria-label={t('Toolbar.EditSketchARIA')}
30+
inputProps={{
31+
maxLength: 128,
32+
'aria-label': t('Toolbar.NewSketchNameARIA')
33+
}}
34+
validate={(text) => text.trim().length > 0}
35+
onChange={handleProjectNameSave}
36+
/>
37+
);
38+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import classNames from 'classnames';
2+
import PropTypes from 'prop-types';
3+
import React from 'react';
4+
import { useTranslation } from 'react-i18next';
5+
import { useDispatch, useSelector } from 'react-redux';
6+
import PlayIcon from '../../../../images/play.svg';
7+
import { startAccessibleSketch, startSketch } from '../../actions/ide';
8+
import { setGridOutput, setTextOutput } from '../../actions/preferences';
9+
10+
export default function PlayButton({ syncFileContent }) {
11+
const { t } = useTranslation();
12+
const dispatch = useDispatch();
13+
14+
const isPlaying = useSelector((state) => state.ide.isPlaying);
15+
const infiniteLoop = useSelector((state) => state.ide.infiniteLoop);
16+
17+
return (
18+
<>
19+
<button
20+
className="toolbar__play-sketch-button"
21+
onClick={() => {
22+
syncFileContent();
23+
dispatch(startAccessibleSketch());
24+
dispatch(setTextOutput(true));
25+
dispatch(setGridOutput(true));
26+
}}
27+
aria-label={t('Toolbar.PlaySketchARIA')}
28+
disabled={infiniteLoop}
29+
>
30+
<PlayIcon focusable="false" aria-hidden="true" />
31+
</button>
32+
<button
33+
className={classNames(
34+
'toolbar__play-button',
35+
isPlaying && 'toolbar__play-button--selected'
36+
)}
37+
onClick={() => {
38+
syncFileContent();
39+
dispatch(startSketch());
40+
}}
41+
aria-label={t('Toolbar.PlayOnlyVisualSketchARIA')}
42+
disabled={infiniteLoop}
43+
>
44+
<PlayIcon focusable="false" aria-hidden="true" />
45+
</button>
46+
</>
47+
);
48+
}
49+
50+
PlayButton.propTypes = {
51+
syncFileContent: PropTypes.func.isRequired
52+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import classNames from 'classnames';
2+
import React from 'react';
3+
import { useTranslation } from 'react-i18next';
4+
import { useDispatch, useSelector } from 'react-redux';
5+
import PreferencesIcon from '../../../../images/preferences.svg';
6+
import { openPreferences } from '../../actions/ide';
7+
8+
export default function PreferencesButton() {
9+
const { t } = useTranslation();
10+
const dispatch = useDispatch();
11+
12+
const preferencesIsVisible = useSelector(
13+
(state) => state.ide.preferencesIsVisible
14+
);
15+
16+
return (
17+
<button
18+
className={classNames(
19+
'toolbar__preferences-button',
20+
preferencesIsVisible && 'toolbar__preferences-button--selected'
21+
)}
22+
onClick={() => dispatch(openPreferences())}
23+
aria-label={t('Toolbar.OpenPreferencesARIA')}
24+
>
25+
<PreferencesIcon focusable="false" aria-hidden="true" />
26+
</button>
27+
);
28+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import { useTranslation } from 'react-i18next';
3+
import { useSelector } from 'react-redux';
4+
import { Link } from 'react-router';
5+
import { selectProjectOwner } from '../../selectors/project';
6+
7+
export default function ProjectOwner() {
8+
const { t } = useTranslation();
9+
10+
const owner = useSelector(selectProjectOwner);
11+
12+
if (!owner) return null;
13+
14+
return (
15+
<p className="toolbar__project-owner">
16+
{t('Toolbar.By')}{' '}
17+
<Link to={`/${owner.username}/sketches`}>{owner.username}</Link>
18+
</p>
19+
);
20+
}

0 commit comments

Comments
 (0)