Skip to content

Commit 1503b1b

Browse files
committed
🔀 merge from mobile-examples
2 parents bbb6adf + dd79bf7 commit 1503b1b

26 files changed

+459
-223
lines changed

client/components/Nav.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import i18next from 'i18next';
99
import * as IDEActions from '../modules/IDE/actions/ide';
1010
import * as toastActions from '../modules/IDE/actions/toast';
1111
import * as projectActions from '../modules/IDE/actions/project';
12-
import { setAllAccessibleOutput } from '../modules/IDE/actions/preferences';
12+
import { setAllAccessibleOutput, setLanguage } from '../modules/IDE/actions/preferences';
1313
import { logoutUser } from '../modules/User/actions';
1414

1515
import getConfig from '../utils/getConfig';
@@ -72,7 +72,6 @@ class Nav extends React.PureComponent {
7272
document.removeEventListener('mousedown', this.handleClick, false);
7373
document.removeEventListener('keydown', this.closeDropDown, false);
7474
}
75-
7675
setDropdown(dropdown) {
7776
this.setState({
7877
dropdownOpen: dropdown
@@ -170,7 +169,7 @@ class Nav extends React.PureComponent {
170169
}
171170

172171
handleLangSelection(event) {
173-
i18next.changeLanguage(event.target.value);
172+
this.props.setLanguage(event.target.value);
174173
this.props.showToast(1500);
175174
this.props.setToastText('Toast.LangChange');
176175
this.setDropdown('none');
@@ -808,8 +807,8 @@ Nav.propTypes = {
808807
params: PropTypes.shape({
809808
username: PropTypes.string
810809
}),
811-
t: PropTypes.func.isRequired
812-
810+
t: PropTypes.func.isRequired,
811+
setLanguage: PropTypes.func.isRequired,
813812
};
814813

815814
Nav.defaultProps = {
@@ -839,7 +838,8 @@ const mapDispatchToProps = {
839838
...projectActions,
840839
...toastActions,
841840
logoutUser,
842-
setAllAccessibleOutput
841+
setAllAccessibleOutput,
842+
setLanguage
843843
};
844844

845845
export default withTranslation()(withRouter(connect(mapStateToProps, mapDispatchToProps)(Nav)));

client/components/__test__/Nav.test.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ describe('Nav', () => {
4545
rootFile: {
4646
id: 'root-file'
4747
},
48-
t: jest.fn()
48+
t: jest.fn(),
49+
setLanguage: jest.fn()
4950
};
5051

5152
it('renders correctly', () => {

client/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export const SHOW_TOAST = 'SHOW_TOAST';
9393
export const HIDE_TOAST = 'HIDE_TOAST';
9494
export const SET_TOAST_TEXT = 'SET_TOAST_TEXT';
9595
export const SET_THEME = 'SET_THEME';
96+
export const SET_LANGUAGE = 'SET_LANGUAGE';
9697

9798
export const SET_UNSAVED_CHANGES = 'SET_UNSAVED_CHANGES';
9899
export const SET_AUTOREFRESH = 'SET_AUTOREFRESH';

client/modules/App/App.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { connect } from 'react-redux';
44
import getConfig from '../../utils/getConfig';
55
import DevTools from './components/DevTools';
66
import { setPreviousPath } from '../IDE/actions/ide';
7+
import { setLanguage } from '../IDE/actions/preferences';
78

89
class App extends React.Component {
910
constructor(props, context) {
@@ -23,6 +24,10 @@ class App extends React.Component {
2324
if (locationWillChange && !shouldSkipRemembering) {
2425
this.props.setPreviousPath(this.props.location.pathname);
2526
}
27+
28+
if (this.props.language !== nextProps.language) {
29+
this.props.setLanguage(nextProps.language, { persistPreference: false });
30+
}
2631
}
2732

2833
componentDidUpdate(prevProps) {
@@ -50,18 +55,22 @@ App.propTypes = {
5055
}),
5156
}).isRequired,
5257
setPreviousPath: PropTypes.func.isRequired,
58+
setLanguage: PropTypes.func.isRequired,
59+
language: PropTypes.string,
5360
theme: PropTypes.string,
5461
};
5562

5663
App.defaultProps = {
5764
children: null,
65+
language: null,
5866
theme: 'light'
5967
};
6068

6169
const mapStateToProps = state => ({
6270
theme: state.preferences.theme,
71+
language: state.preferences.language,
6372
});
6473

65-
const mapDispatchToProps = { setPreviousPath };
74+
const mapDispatchToProps = { setPreviousPath, setLanguage };
6675

6776
export default connect(mapStateToProps, mapDispatchToProps)(App);

client/modules/IDE/actions/preferences.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import i18next from 'i18next';
12
import apiClient from '../../../utils/apiClient';
23
import * as ActionTypes from '../../../constants';
34

@@ -210,3 +211,22 @@ export function setAllAccessibleOutput(value) {
210211
};
211212
}
212213

214+
export function setLanguage(value, { persistPreference = true } = {}) {
215+
return (dispatch, getState) => {
216+
i18next.changeLanguage(value);
217+
dispatch({
218+
type: ActionTypes.SET_LANGUAGE,
219+
language: value
220+
});
221+
const state = getState();
222+
if (persistPreference && state.user.authenticated) {
223+
const formParams = {
224+
preferences: {
225+
language: value
226+
}
227+
};
228+
updatePreferences(formParams, dispatch);
229+
}
230+
};
231+
}
232+

client/modules/IDE/components/CollectionList/CollectionList.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ class CollectionList extends React.Component {
143143
<thead>
144144
<tr>
145145
{this._renderFieldHeader('name', 'Name')}
146-
{(!mobile) && this._renderFieldHeader('createdAt', 'Date Created')}
147-
{this._renderFieldHeader('updatedAt', 'Date Updated')}
148-
{this._renderFieldHeader('numItems', '# sketches')}
146+
{this._renderFieldHeader('createdAt', `${mobile ? '' : 'Date '}Created`)}
147+
{this._renderFieldHeader('updatedAt', `${mobile ? '' : 'Date '}Updated`)}
148+
{this._renderFieldHeader('numItems', mobile ? 'Sketches' : '# sketches')}
149149
<th scope="col"></th>
150150
</tr>
151151
</thead>

client/modules/IDE/components/CollectionList/CollectionListRow.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class CollectionListRowBase extends React.Component {
213213
{this.renderCollectionName()}
214214
</span>
215215
</th>
216-
{(!mobile) && <td>{format(new Date(collection.createdAt), 'MMM D, YYYY')}</td>}
216+
<td>{mobile && 'Created: '}{format(new Date(collection.createdAt), 'MMM D, YYYY')}</td>
217217
<td>{mobile && 'Updated: '}{formatDateCell(collection.updatedAt)}</td>
218218
<td>{mobile && '# sketches: '}{(collection.items || []).length}</td>
219219
<td className="sketch-list__dropdown-column">

client/modules/IDE/components/SketchList.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@ class SketchList extends React.Component {
437437
<thead>
438438
<tr>
439439
{this._renderFieldHeader('name', 'Sketch')}
440-
{this._renderFieldHeader('createdAt', 'Date Created')}
441-
{this._renderFieldHeader('updatedAt', 'Date Updated')}
440+
{this._renderFieldHeader('createdAt', `${mobile ? '' : 'Date '}Created`)}
441+
{this._renderFieldHeader('updatedAt', `${mobile ? '' : 'Date '}Updated`)}
442442
<th scope="col"></th>
443443
</tr>
444444
</thead>

client/modules/IDE/pages/IDEView.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import AddToCollectionList from '../components/AddToCollectionList';
3535
import Feedback from '../components/Feedback';
3636
import { CollectionSearchbar } from '../components/Searchbar';
3737

38+
3839
function getTitle(props) {
3940
const { id } = props.project;
4041
return id ? `p5.js Web Editor | ${props.project.name}` : 'p5.js Web Editor';
@@ -167,13 +168,11 @@ class IDEView extends React.Component {
167168
warnIfUnsavedChanges(this.props));
168169
}
169170
}
170-
171171
componentWillUnmount() {
172172
document.removeEventListener('keydown', this.handleGlobalKeydown, false);
173173
clearTimeout(this.autosaveInterval);
174174
this.autosaveInterval = null;
175175
}
176-
177176
handleGlobalKeydown(e) {
178177
// 83 === s
179178
if (
@@ -389,6 +388,7 @@ class IDEView extends React.Component {
389388
expandConsole={this.props.expandConsole}
390389
clearConsole={this.props.clearConsole}
391390
cmController={this.cmController}
391+
language={this.props.preferences.language}
392392
/>
393393
</div>
394394
</section>
@@ -538,7 +538,7 @@ IDEView.propTypes = {
538538
soundOutput: PropTypes.bool.isRequired,
539539
theme: PropTypes.string.isRequired,
540540
autorefresh: PropTypes.bool.isRequired,
541-
541+
language: PropTypes.string.isRequired
542542
}).isRequired,
543543
closePreferences: PropTypes.func.isRequired,
544544
setFontSize: PropTypes.func.isRequired,

client/modules/IDE/reducers/preferences.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import i18next from 'i18next';
12
import * as ActionTypes from '../../../constants';
23

4+
35
const initialState = {
46
fontSize: 18,
57
autosave: true,
@@ -10,7 +12,8 @@ const initialState = {
1012
gridOutput: false,
1113
soundOutput: false,
1214
theme: 'light',
13-
autorefresh: false
15+
autorefresh: false,
16+
language: 'en-US'
1417
};
1518

1619
const preferences = (state = initialState, action) => {
@@ -37,6 +40,8 @@ const preferences = (state = initialState, action) => {
3740
return Object.assign({}, state, { autorefresh: action.value });
3841
case ActionTypes.SET_LINE_NUMBERS:
3942
return Object.assign({}, state, { lineNumbers: action.value });
43+
case ActionTypes.SET_LANGUAGE:
44+
return Object.assign({}, state, { language: action.language });
4045
default:
4146
return state;
4247
}

0 commit comments

Comments
 (0)