From 8298e961722e5a3015e26be35e47649dc79ef191 Mon Sep 17 00:00:00 2001 From: gauravsingh94 Date: Mon, 4 Dec 2023 01:26:06 +0530 Subject: [PATCH] Fixed issue-#2655 cant find setting button on examples page --- client/modules/IDE/actions/ide.js | 23 ++++++++++++++++++++ client/modules/IDE/actions/preferences.js | 2 +- client/modules/IDE/components/Header/Nav.jsx | 22 ++++++++++++++++++- translations/locales/en-US/translations.json | 6 +++++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/client/modules/IDE/actions/ide.js b/client/modules/IDE/actions/ide.js index 80a43443bc..fb03aa3d57 100644 --- a/client/modules/IDE/actions/ide.js +++ b/client/modules/IDE/actions/ide.js @@ -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 { @@ -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); + } + }; +} diff --git a/client/modules/IDE/actions/preferences.js b/client/modules/IDE/actions/preferences.js index e0473bd995..eaf4b6c27d 100644 --- a/client/modules/IDE/actions/preferences.js +++ b/client/modules/IDE/actions/preferences.js @@ -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(() => {}) diff --git a/client/modules/IDE/components/Header/Nav.jsx b/client/modules/IDE/components/Header/Nav.jsx index b4f7cb151f..9738cca455 100644 --- a/client/modules/IDE/components/Header/Nav.jsx +++ b/client/modules/IDE/components/Header/Nav.jsx @@ -25,7 +25,8 @@ import { newFolder, showKeyboardShortcutModal, startSketch, - stopSketch + stopSketch, + setTheme } from '../../actions/ide'; import { logoutUser } from '../../../User/actions'; import { CmControllerContext } from '../../pages/IDEView'; @@ -260,11 +261,29 @@ const LanguageMenu = () => { ); }; +const ThemeMenu = () => { + const { t } = useTranslation(); + const dispatch = useDispatch(); + return ( + + dispatch(setTheme('light'))}> + {t('Nav.Theme.LightTheme')} + + dispatch(setTheme('dark'))}> + {t('Nav.Theme.DarkTheme')} + + dispatch(setTheme('contrast'))}> + {t('Nav.Theme.HighContrastTheme')} + + + ); +}; const UnauthenticatedUserMenu = () => { const { t } = useTranslation(); return (