Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions client/modules/IDE/actions/ide.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as ActionTypes from '../../../constants';
import { clearConsole } from './console';
import { dispatchMessage, MessageTypes } from '../../../utils/dispatcher';
import { updatePreferences } from './preferences';

export function startVisualSketch() {
return {
Expand Down Expand Up @@ -293,3 +294,25 @@ export function createError(error) {
error
};
}

export function setTheme(value) {
// return {
// type: ActionTypes.SET_THEME,
// value
// };
return (dispatch, getState) => {
dispatch({
type: ActionTypes.SET_THEME,
value
});
const state = getState();
if (state.user.authenticated) {
const formParams = {
preferences: {
theme: value
}
};
updatePreferences(formParams, dispatch);
}
};
}
2 changes: 1 addition & 1 deletion client/modules/IDE/actions/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import i18next from 'i18next';
import apiClient from '../../../utils/apiClient';
import * as ActionTypes from '../../../constants';

function updatePreferences(formParams, dispatch) {
export function updatePreferences(formParams, dispatch) {
apiClient
.put('/preferences', formParams)
.then(() => {})
Expand Down
22 changes: 21 additions & 1 deletion client/modules/IDE/components/Header/Nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
newFolder,
showKeyboardShortcutModal,
startSketch,
stopSketch
stopSketch,
setTheme
} from '../../actions/ide';
import { logoutUser } from '../../../User/actions';
import { CmControllerContext } from '../../pages/IDEView';
Expand Down Expand Up @@ -260,11 +261,29 @@ const LanguageMenu = () => {
);
};

const ThemeMenu = () => {
const { t } = useTranslation();
const dispatch = useDispatch();
return (
<NavDropdownMenu id="theme" title={t('Preferences.Theme')}>
<NavMenuItem onClick={() => dispatch(setTheme('light'))}>
{t('Nav.Theme.LightTheme')}
</NavMenuItem>
<NavMenuItem onClick={() => dispatch(setTheme('dark'))}>
{t('Nav.Theme.DarkTheme')}
</NavMenuItem>
<NavMenuItem onClick={() => dispatch(setTheme('contrast'))}>
{t('Nav.Theme.HighContrastTheme')}
</NavMenuItem>
</NavDropdownMenu>
);
};
const UnauthenticatedUserMenu = () => {
const { t } = useTranslation();
return (
<ul className="nav__items-right" title="user-menu">
{getConfig('TRANSLATIONS_ENABLED') && <LanguageMenu />}
<ThemeMenu />
<li className="nav__item">
<Link to="/login" className="nav__auth-button">
<span className="nav__item-header" title="Login">
Expand Down Expand Up @@ -293,6 +312,7 @@ const AuthenticatedUserMenu = () => {
return (
<ul className="nav__items-right" title="user-menu">
{getConfig('TRANSLATIONS_ENABLED') && <LanguageMenu />}
<ThemeMenu />
<NavDropdownMenu
id="account"
title={
Expand Down
6 changes: 6 additions & 0 deletions translations/locales/en-US/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
"About": "About"
},
"Lang": "Language",
"Theme": {
"Title": "Theme",
"LightTheme": "Light",
"DarkTheme": "Dark",
"HighContrastTheme": "High Contrast"
},
"BackEditor": "Back to Editor",
"WarningUnsavedChanges": "Are you sure you want to leave this page? You have unsaved changes.",
"Login": "Log in",
Expand Down