Skip to content

Commit

Permalink
Merge branch 'develop' into piyush/refactor-collections-reducers-acti…
Browse files Browse the repository at this point in the history
…ons-redux-toolkit
  • Loading branch information
raclim authored Jun 13, 2024
2 parents 2c887c5 + 99b9463 commit 66186f1
Show file tree
Hide file tree
Showing 68 changed files with 649 additions and 644 deletions.
6 changes: 5 additions & 1 deletion client/common/useKeyDownHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export default function useKeyDownHandlers(keyHandlers) {
const isMac = navigator.userAgent.toLowerCase().indexOf('mac') !== -1;
const isCtrl = isMac ? e.metaKey : e.ctrlKey;
if (e.shiftKey && isCtrl) {
handlers.current[`ctrl-shift-${e.key.toLowerCase()}`]?.(e);
handlers.current[
`ctrl-shift-${
/^\d+$/.test(e.code.at(-1)) ? e.code.at(-1) : e.key.toLowerCase()
}`
]?.(e);
} else if (isCtrl) {
handlers.current[`ctrl-${e.key.toLowerCase()}`]?.(e);
}
Expand Down
32 changes: 0 additions & 32 deletions client/components/AddRemoveButton.jsx

This file was deleted.

52 changes: 0 additions & 52 deletions client/components/NavBasic.jsx

This file was deleted.

26 changes: 0 additions & 26 deletions client/components/OverlayManager.jsx

This file was deleted.

14 changes: 8 additions & 6 deletions client/components/PreviewNav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ const PreviewNav = ({ owner, project }) => {
<nav className="nav preview-nav">
<div className="nav__items-left">
<div className="nav__item-logo">
<LogoIcon
role="img"
aria-label={t('Common.p5logoARIA')}
focusable="false"
className="svg__logo"
/>
<Link to={`/${owner.username}/sketches`}>
<LogoIcon
role="img"
aria-label={t('Common.p5logoARIA')}
focusable="false"
className="svg__logo"
/>
</Link>
</div>
<Link
className="nav__item"
Expand Down
35 changes: 35 additions & 0 deletions client/components/SkipLink.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { useState } from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import { useTranslation } from 'react-i18next';

const SkipLink = ({ targetId, text }) => {
const [focus, setFocus] = useState(false);
const { t } = useTranslation();
const handleFocus = () => {
setFocus(true);
};

const handleBlur = () => {
setFocus(false);
};
const linkClasses = classNames('skip_link', { focus });

return (
<a
href={`#${targetId}`}
className={linkClasses}
onFocus={handleFocus}
onBlur={handleBlur}
>
{t(`SkipLink.${text}`)}
</a>
);
};

SkipLink.propTypes = {
targetId: PropTypes.string.isRequired,
text: PropTypes.string.isRequired
};

export default SkipLink;
39 changes: 17 additions & 22 deletions client/components/createRedirectWithUsername.jsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
import React from 'react';
import { connect } from 'react-redux';
import browserHistory from '../browserHistory';
import { useEffect } from 'react';
import { useSelector } from 'react-redux';
import { useHistory } from 'react-router-dom';
import PropTypes from 'prop-types';

const RedirectToUser = ({ username, url = '/:username/sketches' }) => {
React.useEffect(() => {
if (username == null) {
return;
const RedirectToUser = ({ url = '/:username/sketches' }) => {
const history = useHistory();
const username = useSelector((state) =>
state.user ? state.user.username : null
);
useEffect(() => {
if (username) {
history.replace(url.replace(':username', username));
}

browserHistory.replace(url.replace(':username', username));
}, [username]);
}, [history, url, username]);

return null;
};

function mapStateToProps(state) {
return {
username: state.user ? state.user.username : null
};
}

const ConnectedRedirectToUser = connect(mapStateToProps)(RedirectToUser);

const createRedirectWithUsername = (url) => (props) => (
<ConnectedRedirectToUser {...props} url={url} />
);
RedirectToUser.propTypes = {
url: PropTypes.string.isRequired
};

export default createRedirectWithUsername;
export default RedirectToUser;
6 changes: 3 additions & 3 deletions client/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// multiple files
export const UPDATE_FILE_CONTENT = 'UPDATE_FILE_CONTENT';
export const TOGGLE_SKETCH = 'TOGGLE_SKETCH';

export const START_SKETCH = 'START_SKETCH';
export const STOP_SKETCH = 'STOP_SKETCH';

Expand Down Expand Up @@ -47,8 +46,6 @@ export const SET_BLOB_URL = 'SET_BLOB_URL';
export const EXPAND_SIDEBAR = 'EXPAND_SIDEBAR';
export const COLLAPSE_SIDEBAR = 'COLLAPSE_SIDEBAR';

export const CONSOLE_EVENT = 'CONSOLE_EVENT';
export const CLEAR_CONSOLE = 'CLEAR_CONSOLE';
export const EXPAND_CONSOLE = 'EXPAND_CONSOLE';
export const COLLAPSE_CONSOLE = 'COLLAPSE_CONSOLE';

Expand Down Expand Up @@ -135,3 +132,6 @@ export const START_SAVING_PROJECT = 'START_SAVING_PROJECT';
export const END_SAVING_PROJECT = 'END_SAVING_PROJECT';

export const SET_COOKIE_CONSENT = 'SET_COOKIE_CONSENT';

export const CONSOLE_EVENT = 'CONSOLE_EVENT';
export const CLEAR_CONSOLE = 'CLEAR_CONSOLE';
1 change: 0 additions & 1 deletion client/i18n-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';

import translations from '../translations/locales/en-US/translations.json';

i18n.use(initReactI18next).init({
Expand Down
2 changes: 2 additions & 0 deletions client/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Routing from './routes';
import ThemeProvider from './modules/App/components/ThemeProvider';
import Loader from './modules/App/components/loader';
import './i18n';
import SkipLink from './components/SkipLink';

require('./styles/main.scss');

Expand All @@ -23,6 +24,7 @@ const App = () => (
<Provider store={store}>
<ThemeProvider>
<Router history={browserHistory}>
<SkipLink targetId="play-sketch" text="PlaySketch" />
<Routing />
</Router>
</ThemeProvider>
Expand Down
15 changes: 1 addition & 14 deletions client/modules/IDE/actions/console.js
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
import * as ActionTypes from '../../../constants';

export function clearConsole() {
return {
type: ActionTypes.CLEAR_CONSOLE
};
}

export function dispatchConsoleEvent(messages) {
return {
type: ActionTypes.CONSOLE_EVENT,
event: messages
};
}
export { dispatchConsoleEvent, clearConsole } from '../reducers/console';
22 changes: 7 additions & 15 deletions client/modules/IDE/components/AssetSize.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import { useSelector } from 'react-redux';
import prettyBytes from 'pretty-bytes';

import getConfig from '../../../utils/getConfig';
Expand All @@ -18,7 +17,11 @@ const formatPercent = (percent) => {
};

/* Eventually, this copy should be Total / 250 MB Used */
const AssetSize = ({ totalSize }) => {
const AssetSize = () => {
const totalSize = useSelector(
(state) => state.user.totalSize || state.assets.totalSize
);

if (totalSize === undefined) {
return null;
}
Expand All @@ -40,15 +43,4 @@ const AssetSize = ({ totalSize }) => {
);
};

AssetSize.propTypes = {
totalSize: PropTypes.number.isRequired
};

function mapStateToProps(state) {
return {
user: state.user,
totalSize: state.user.totalSize || state.assets.totalSize
};
}

export default connect(mapStateToProps)(AssetSize);
export default AssetSize;
Loading

0 comments on commit 66186f1

Please sign in to comment.