Skip to content

Commit cf963b7

Browse files
committed
Switch to controlled preferences tabs; create version button
1 parent e0342fb commit cf963b7

File tree

9 files changed

+80
-5
lines changed

9 files changed

+80
-5
lines changed

client/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const STOP_ACCESSIBLE_OUTPUT = 'STOP_ACCESSIBLE_OUTPUT';
1010

1111
export const OPEN_PREFERENCES = 'OPEN_PREFERENCES';
1212
export const CLOSE_PREFERENCES = 'CLOSE_PREFERENCES';
13+
export const SET_PREFERENCES_TAB = 'SET_PREFERENCES_TAB';
1314
export const SET_FONT_SIZE = 'SET_FONT_SIZE';
1415
export const SET_LINE_NUMBERS = 'SET_LINE_NUMBERS';
1516

client/modules/IDE/actions/preferences.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ function updatePreferences(formParams, dispatch) {
1414
});
1515
}
1616

17+
export function setPreferencesTab(value) {
18+
return {
19+
type: ActionTypes.SET_PREFERENCES_TAB,
20+
value
21+
};
22+
}
23+
1724
export function setFontSize(value) {
1825
return (dispatch, getState) => {
1926
// eslint-disable-line

client/modules/IDE/components/Editor/index.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import UnsavedChangesIndicator from '../UnsavedChangesIndicator';
7272
import { EditorContainer, EditorHolder } from './MobileEditor';
7373
import { FolderIcon } from '../../../../common/icons';
7474
import IconButton from '../../../../common/IconButton';
75+
import VersionIndicator from '../VersionIndicator';
7576

7677
emmet(CodeMirror);
7778

@@ -565,6 +566,9 @@ class Editor extends React.Component {
565566
</span>
566567
<Timer />
567568
</div>
569+
<div className="editor__library-version">
570+
<VersionIndicator />
571+
</div>
568572
</div>
569573
<article
570574
ref={(element) => {

client/modules/IDE/components/Preferences/index.jsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
setLintWarning,
1717
setAutocloseBracketsQuotes,
1818
setAutocompleteHinter,
19-
setLinewrap
19+
setLinewrap,
20+
setPreferencesTab
2021
} from '../../actions/preferences';
2122

2223
export default function Preferences() {
@@ -25,6 +26,7 @@ export default function Preferences() {
2526
const dispatch = useDispatch();
2627

2728
const {
29+
tabIndex,
2830
fontSize,
2931
autosave,
3032
linewrap,
@@ -78,14 +80,18 @@ export default function Preferences() {
7880
handleFontSize(newValue);
7981
}
8082

83+
function changeTab(index) {
84+
dispatch(setPreferencesTab(index));
85+
}
86+
8187
const fontSizeInputRef = useRef(null);
8288

8389
return (
8490
<section className="preferences">
8591
<Helmet>
8692
<title>p5.js Web Editor | Preferences</title>
8793
</Helmet>
88-
<Tabs>
94+
<Tabs selectedIndex={tabIndex} onSelect={changeTab}>
8995
<TabList>
9096
<div className="tabs__titles">
9197
<Tab>
@@ -96,6 +102,11 @@ export default function Preferences() {
96102
<Tab>
97103
<h4 className="tabs__title">{t('Preferences.Accessibility')}</h4>
98104
</Tab>
105+
<Tab>
106+
<h4 className="tabs__title">
107+
{t('Preferences.LibraryManagement')}
108+
</h4>
109+
</Tab>
99110
</div>
100111
</TabList>
101112
<TabPanel>
@@ -455,6 +466,7 @@ export default function Preferences() {
455466
</div>
456467
</div>
457468
</TabPanel>
469+
<TabPanel>TODO</TabPanel>
458470
</Tabs>
459471
</section>
460472
);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React, { useCallback } from 'react';
2+
import { useTranslation } from 'react-i18next';
3+
import { useDispatch } from 'react-redux';
4+
import { openPreferences } from '../actions/ide';
5+
import { setPreferencesTab } from '../actions/preferences';
6+
7+
import { useP5Version } from '../hooks/useP5Version';
8+
9+
const VersionIndicator = () => {
10+
const { versionInfo } = useP5Version();
11+
const { t } = useTranslation();
12+
const dispatch = useDispatch();
13+
14+
const openVersionSettings = useCallback(() => {
15+
dispatch(openPreferences());
16+
dispatch(setPreferencesTab(2));
17+
}, []);
18+
19+
return (
20+
<button onClick={openVersionSettings}>
21+
{t('Toolbar.LibraryVersion')}
22+
&nbsp;
23+
{versionInfo?.version || t('Toolbar.CustomLibraryVersion')}
24+
</button>
25+
);
26+
};
27+
28+
VersionIndicator.propTypes = {};
29+
30+
export default VersionIndicator;

client/modules/IDE/components/VersionPicker.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { updateFileContent } from '../actions/files';
88

99
const VersionPicker = () => {
1010
const { indexID, versionInfo } = useP5Version();
11-
console.log(versionInfo);
1211
const dispatch = useDispatch();
1312
const dispatchReplaceVersion = useCallback(
1413
(version) => {
@@ -33,6 +32,6 @@ const VersionPicker = () => {
3332
);
3433
};
3534

36-
VersionPicker.popTypes = {};
35+
VersionPicker.propTypes = {};
3736

3837
export default VersionPicker;

client/modules/IDE/reducers/preferences.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as ActionTypes from '../../../constants';
22

33
export const initialState = {
4+
tabIndex: 0,
45
fontSize: 18,
56
autosave: true,
67
linewrap: true,
@@ -17,6 +18,10 @@ export const initialState = {
1718

1819
const preferences = (state = initialState, action) => {
1920
switch (action.type) {
21+
case ActionTypes.OPEN_PREFERENCES:
22+
return Object.assign({}, state, { tabIndex: 0 });
23+
case ActionTypes.SET_PREFERENCES_TAB:
24+
return Object.assign({}, state, { tabIndex: action.value });
2025
case ActionTypes.SET_FONT_SIZE:
2126
return Object.assign({}, state, { fontSize: action.value });
2227
case ActionTypes.SET_AUTOSAVE:

client/styles/components/_editor.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,25 @@ pre.CodeMirror-line {
398398
height: #{math.div(29, $base-font-size)}rem;
399399
padding-top: #{math.div(7, $base-font-size)}rem;
400400
padding-left: #{math.div(56, $base-font-size)}rem;
401+
padding-right: #{math.div(168, $base-font-size)}rem;
401402
font-size: #{math.div(12, $base-font-size)}rem;
402403
display: flex;
403404
justify-content: space-between;
404405
}
405406

407+
.editor__library-version {
408+
@include themify() {
409+
color: getThemifyVariable("primary-text-color");
410+
}
411+
position: absolute;
412+
top: 0;
413+
right: 0;
414+
display: flex;
415+
justify-content: flex-end;
416+
height: #{math.div(29, $base-font-size)}rem;
417+
width: #{math.div(168, $base-font-size)}rem;
418+
}
419+
406420
.editor__unsaved-changes {
407421
margin-left: #{math.div(2, $base-font-size)}rem;
408422
}

translations/locales/en-US/translations.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@
153153
"StopSketchARIA": "Stop sketch",
154154
"EditSketchARIA": "Edit sketch name",
155155
"NewSketchNameARIA": "New sketch name",
156-
"By": " by "
156+
"By": " by ",
157+
"LibraryVersion": "p5.js Version:",
158+
"CustomLibraryVersion": "Custom"
157159
},
158160
"Console": {
159161
"Title": "Console",
@@ -168,6 +170,7 @@
168170
"Settings": "Settings",
169171
"GeneralSettings": "General settings",
170172
"Accessibility": "Accessibility",
173+
"LibraryManagement": "Library Management",
171174
"Theme": "Theme",
172175
"LightTheme": "Light",
173176
"LightThemeARIA": "light theme on",

0 commit comments

Comments
 (0)