📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
added chose theme
Maksim Mrugb6218911e373
diff --git a/src/App.js b/src/App.jsindex 484ae9333..2e2f11528 100644--- a/src/App.js+++ b/src/App.js@@ -83,6 +83,7 @@ const App = () => {const { theme } = useSelector(state => state.ui.theme)const { error } = useSelector(state => state.errors)const { message, type } = useSelector(state => state.alerts)+ const themeType = useSelector(state => state.ui.theme.type)const accessToken = getAccessToken()useEffect(() => {@@ -121,7 +122,7 @@ const App = () => {if (accessToken && !authenticated) {try {const me = await authMe()-+ dispatch(UIActions.setThemeType(me.theme))dispatch(authActions.loginSuccess(me))dispatch(authActions.finishLoading())} catch (e) {@@ -158,7 +159,7 @@ const App = () => {(!accessToken || !loading) && (// eslint-disable-next-line react/jsx-no-useless-fragment<Suspense fallback={<></>}>- <Header authenticated={authenticated} theme={theme} />+ <Header authenticated={authenticated} theme={theme} themeType={themeType} /><ScrollToTop><Selfhosted><Suspense fallback={<Fallback theme={theme} isMinimalFooter={isMinimalFooter} />}>diff --git a/src/api/index.js b/src/api/index.jsindex 67f20aebb..d07e78b03 100644--- a/src/api/index.js+++ b/src/api/index.js@@ -424,3 +424,14 @@ export const getInstalledExtensions = (limit = 100, offset = 0) =>? error.response.data: error.response.data.message})++export const setTheme = (theme) =>+ api+ .put('user/theme', { theme })+ .then((response) => response.data)+ .catch((error) => {+ debug('%s', error)+ throw _isEmpty(error.response.data?.message)+ ? error.response.data+ : error.response.data.message+ })diff --git a/src/components/Header/index.jsx b/src/components/Header/index.jsxindex 261e6cccd..38e49dd67 100644--- a/src/components/Header/index.jsx+++ b/src/components/Header/index.jsx@@ -16,11 +16,11 @@ import routes from 'routes'import { authActions } from 'redux/actions/auth'import UIActions from 'redux/actions/ui'import {- whitelist, languages, languageFlag, isSelfhosted, BLOG_URL,+ whitelist, languages, languageFlag, isSelfhosted, BLOG_URL, THEME_TYPE,} from 'redux/constants'import Dropdown from 'ui/Dropdown'-const Header = ({ authenticated, theme }) => {+const Header = ({ authenticated, theme, themeType }) => {const { t, i18n: { language } } = useTranslation('common')const dispatch = useDispatch()const buttonRef = useRef()@@ -40,29 +40,35 @@ const Header = ({ authenticated, theme }) => {return (<Popover className='relative bg-white'><header className='bg-indigo-600 dark:bg-gray-750 relative overflow-hidden'>- <div className='santa-claus group'>- <div className='group-hover:cursor-pointer group-hover:translate-y-[-130px] transition-all ease-linear delay-300 duration-500'>- <div className='sc-head'>- <div className='sc-hat'>- <div className='hat-tip' />- </div>- <div className='eyes' />- <div className='nose' />- <div className='beard' />- <div className='ears'>- <div className='ear left' />- <div className='ear right' />+ {themeType === THEME_TYPE.christmas && (+ <div className='santa-claus group'>+ <div className='group-hover:cursor-pointer group-hover:translate-y-[-130px] transition-all ease-linear delay-300 duration-500'>+ <div className='sc-head'>+ <div className='sc-hat'>+ <div className='hat-tip' />+ </div>+ <div className='eyes' />+ <div className='nose' />+ <div className='beard' />+ <div className='ears'>+ <div className='ear left' />+ <div className='ear right' />+ </div></div></div>+ <div className='sc-body' /></div>- <div className='sc-body' />- </div>+ )}<nav className='mx-auto px-4 sm:px-6 lg:px-8' aria-label='Top'><div className='w-full py-4 flex items-center justify-between border-b border-indigo-500 dark:border-gray-300 lg:border-none'><div className='flex items-center'><Link to={routes.main}><span className='sr-only'>Swetrix</span>- <img className='h-10' src='/assets/logo_white_christmas.png' alt='' />+ {themeType === THEME_TYPE.christmas ? (+ <img className='h-10' src='/assets/logo_white_christmas.png' alt='' />+ ) : (+ <img className='h-10' src='/assets/logo_white.svg' alt='' />+ )}</Link><div className='hidden ml-10 space-x-1 lg:flex'><a href={BLOG_URL} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' target='_blank' rel='noreferrer noopener'>@@ -213,7 +219,11 @@ const Header = ({ authenticated, theme }) => {<Link to={routes.main}><span className='sr-only'>Swetrix</span>{theme === 'dark' ? (- <img className='h-10' src='/assets/logo_white_christmas.png' alt='' />+ themeType === THEME_TYPE.christmas ? (+ <img className='h-10' src='/assets/logo_white_christmas.png' alt='' />+ ) : (+ <img className='h-10' src='/assets/logo_white.svg' alt='' />+ )) : (<img className='h-10' src='/assets/logo_blue.svg' alt='' />)}diff --git a/src/pages/UserSettings/UserSettings.container.jsx b/src/pages/UserSettings/UserSettings.container.jsxindex 0bfe1063d..12a89ac43 100644--- a/src/pages/UserSettings/UserSettings.container.jsx+++ b/src/pages/UserSettings/UserSettings.container.jsx@@ -13,6 +13,7 @@ const mapStateToProps = (state) => {user: state.auth.user,dontRemember: state.auth.dontRemember,isPaidTierUsed: state.auth.isPaidTierUsed,+ themeType: state.ui.theme.type,}}@@ -83,6 +84,9 @@ const mapDispatchToProps = (dispatch) => ({setAPIKey: (apiKey) => {dispatch(authActions.setApiKey(apiKey))},+ setThemeType: (theme) => {+ dispatch(UIActions.setThemeType(theme))+ },})export default connect(mapStateToProps, mapDispatchToProps)(UserSettings)diff --git a/src/pages/UserSettings/UserSettings.jsx b/src/pages/UserSettings/UserSettings.jsxindex a289c22f2..69282ab3b 100644--- a/src/pages/UserSettings/UserSettings.jsx+++ b/src/pages/UserSettings/UserSettings.jsx@@ -19,7 +19,7 @@ import utc from 'dayjs/plugin/utc'import {reportFrequencies, DEFAULT_TIMEZONE, WEEKLY_REPORT_FREQUENCY, CONFIRMATION_TIMEOUT,- GDPR_REQUEST, GDPR_EXPORT_TIMEFRAME,+ GDPR_REQUEST, GDPR_EXPORT_TIMEFRAME, THEME_TYPE,} from 'redux/constants'import Title from 'components/Title'import { withAuthentication, auth } from 'hoc/protected'@@ -28,6 +28,8 @@ import Button from 'ui/Button'import Modal from 'ui/Modal'import Beta from 'ui/Beta'import Select from 'ui/Select'+import Tooltip from 'ui/Tooltip'+import { ActivePin } from 'ui/Pin'import PaidFeature from 'modals/PaidFeature'import TimezonePicker from 'ui/TimezonePicker'import { isValidEmail, isValidPassword, MIN_PASSWORD_CHARS } from 'utils/validator'@@ -35,7 +37,7 @@ import routes from 'routes'import { trackCustom } from 'utils/analytics'import { getCookie, setCookie } from 'utils/cookie'import {- confirmEmail, exportUserData, generateApiKey, deleteApiKey,+ confirmEmail, exportUserData, generateApiKey, deleteApiKey, setTheme,} from 'api'import ProjectList from './components/ProjectList'import TwoFA from './components/TwoFA'@@ -47,7 +49,7 @@ const UserSettings = ({onDelete, onDeleteProjectCache, removeProject, removeShareProject, setUserShareData,setProjectsShareData, userSharedUpdate, sharedProjectError, updateUserData, login,genericError, onGDPRExportFailed, updateProfileFailed, updateUserProfileAsync,- accountUpdated, setAPIKey, user, dontRemember, isPaidTierUsed,+ accountUpdated, setAPIKey, user, dontRemember, isPaidTierUsed, setThemeType, themeType,}) => {const history = useHistory()const { t, i18n: { language } } = useTranslation('common')@@ -257,6 +259,15 @@ const UserSettings = ({}}+ const setAsyncThemeType = async (theme) => {+ try {+ await setTheme(theme)+ setThemeType(theme)+ } catch (e) {+ updateProfileFailed(e)+ }+ }+return (<Title title={t('titles.profileSettings')}><div className='min-h-min-footer bg-gray-50 dark:bg-gray-800 flex flex-col py-6 px-4 sm:px-6 lg:px-8'>@@ -307,6 +318,24 @@ const UserSettings = ({{t('profileSettings.update')}</Button><hr className='mt-5 border-gray-200 dark:border-gray-600' />+ <h3 className='flex items-center mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>+ Theme+ <div className='ml-3'>+ <ActivePin label='New' />+ </div>+ </h3>+ <div className='grid grid-cols-1 gap-y-6 gap-x-4 lg:grid-cols-2 mt-2 mb-4'>+ <div>+ <Select+ title={themeType}+ label='Select theme'+ className='w-full'+ items={[THEME_TYPE.classic, THEME_TYPE.christmas]}+ onSelect={(f) => setAsyncThemeType(f)}+ />+ </div>+ </div>+ <hr className='mt-5 border-gray-200 dark:border-gray-600' /><h3 className='mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>{t('profileSettings.timezone')}</h3>diff --git a/src/redux/actions/ui/index.js b/src/redux/actions/ui/index.jsindex b3d81c254..b71ddbe67 100644--- a/src/redux/actions/ui/index.js+++ b/src/redux/actions/ui/index.js@@ -177,6 +177,11 @@ const setLastBlogPost = (lastBlogPost) => ({payload: { lastBlogPost },})+const setThemeType = (theme) => ({+ type: types.SET_THEME_TYPE,+ payload: { theme },+})+const UIActions = {loadProjects,loadSharedProjects,@@ -204,6 +209,7 @@ const UIActions = {setExtensions,loadExtensions,setLastBlogPost,+ setThemeType,}export default UIActionsdiff --git a/src/redux/actions/ui/types.js b/src/redux/actions/ui/types.jsindex 71911958e..c2611042d 100644--- a/src/redux/actions/ui/types.js+++ b/src/redux/actions/ui/types.js@@ -25,4 +25,5 @@ export const types = {SHARE_VERIFY_ASYNC: 'UI_SHARE_VERIFY_ASYNC',LOAD_SHARED_PROJECTS: 'UI_LOAD_SHARED_PROJECTS',SET_DASHBOARD_TABS: 'UI_SET_DASHBOARD_TABS',+ SET_THEME_TYPE: 'UI_SET_THEME_TYPE',}diff --git a/src/redux/constants/index.js b/src/redux/constants/index.jsindex 17b8a2031..6a5afa72b 100644--- a/src/redux/constants/index.js+++ b/src/redux/constants/index.js@@ -196,3 +196,8 @@ export const tabsForDashboard = [export const INVITATION_EXPIRES_IN = 48 // hoursexport const ENTRIES_PER_PAGE_DASHBOARD = 10++export const THEME_TYPE = {+ classic: 'classic',+ christmas: 'christmas',+}diff --git a/src/redux/reducers/ui/theme.js b/src/redux/reducers/ui/theme.jsindex 78b7c8b8f..92f43990d 100644--- a/src/redux/reducers/ui/theme.js+++ b/src/redux/reducers/ui/theme.js@@ -1,6 +1,6 @@import _includes from 'lodash/includes'import { types } from 'redux/actions/ui/types'-import { LS_THEME_SETTING, SUPPORTED_THEMES } from 'redux/constants'+import { LS_THEME_SETTING, SUPPORTED_THEMES, THEME_TYPE } from 'redux/constants'const setThemeToDOM = (theme) => {const root = window.document.documentElement@@ -38,6 +38,7 @@ const getInitialTheme = () => {const getInitialState = () => {return {theme: getInitialTheme(),+ type: THEME_TYPE.christmas,}}@@ -54,6 +55,15 @@ const themeReducer = (state = getInitialState(), { type, payload }) => {}}+ case types.SET_THEME_TYPE: {+ const { theme } = payload++ return {+ ...state,+ type: theme,+ }+ }+default:return state}diff --git a/src/ui/Button.jsx b/src/ui/Button.jsxindex 7b54022ac..b7296fe3b 100644--- a/src/ui/Button.jsx+++ b/src/ui/Button.jsx@@ -2,43 +2,57 @@import React, { memo } from 'react'import cx from 'clsx'import PropTypes from 'prop-types'-+import { useSelector } from 'react-redux'+import { THEME_TYPE } from 'redux/constants'import Spin from './icons/Spin'import './ButtonChristmas.css'const Button = ({text, children, primary, secondary, danger, onClick, white, small, regular, large, giant, type, className, loading, semiSmall, semiDanger, noBorder,-}) => (- <button- type={type}- onClick={onClick}- className={cx('relative inline-flex select-none items-center border leading-4 font-medium rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500', {- 'shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 border-transparent': primary,- 'text-indigo-700 bg-indigo-100 hover:bg-indigo-200 border-transparent': secondary,- 'text-gray-700 bg-white hover:bg-gray-50 border-transparent': white,- 'text-white bg-red-500 hover:bg-red-600 border-transparent': danger,- 'text-red-500 hover:text-red-600 border-red-600 dark:text-red-300 dark:hover:text-red-400 dark:border-red-500 border-1': semiDanger,- 'focus:border-none border-none text-gray-700 dark:text-white focus:ring-0 focus:ring-offset-0': noBorder,- 'px-2.5 py-1.5 text-xs': small,- 'px-2.5 py-1.5 text-sm': semiSmall,- 'px-4 py-2 text-sm': large,- 'px-6 py-3 text-base': giant,- 'px-3 py-2 text-sm': regular,- 'cursor-not-allowed': loading,- }, className)}- >- <span className={cx('inline-flex items-center', {- button3: text,- button2: semiSmall || regular || large || giant,- })}+}) => {+ const themeType = useSelector((state) => state.ui.theme.type)++ return (+ <button+ type={type}+ onClick={onClick}+ className={cx('relative inline-flex select-none items-center border leading-4 font-medium rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500', {+ 'shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 border-transparent': primary,+ 'text-indigo-700 bg-indigo-100 hover:bg-indigo-200 border-transparent': secondary,+ 'text-gray-700 bg-white hover:bg-gray-50 border-transparent': white,+ 'text-white bg-red-500 hover:bg-red-600 border-transparent': danger,+ 'text-red-500 hover:text-red-600 border-red-600 dark:text-red-300 dark:hover:text-red-400 dark:border-red-500 border-1': semiDanger,+ 'focus:border-none border-none text-gray-700 dark:text-white focus:ring-0 focus:ring-offset-0': noBorder,+ 'px-2.5 py-1.5 text-xs': small,+ 'px-2.5 py-1.5 text-sm': semiSmall,+ 'px-4 py-2 text-sm': large,+ 'px-6 py-3 text-base': giant,+ 'px-3 py-2 text-sm': regular,+ 'cursor-not-allowed': loading,+ }, className)}>- {loading && (- <Spin />+ {themeType === THEME_TYPE.christmas ? (+ <span className={cx('inline-flex items-center', {+ button3: text,+ button2: semiSmall || regular || large || giant,+ })}+ >+ {loading && (+ <Spin />+ )}+ {text || children}+ </span>+ ) : (+ <>+ {loading && (+ <Spin />+ )}+ {text || children}+ </>)}- {text || children}- </span>- </button>-)+ </button>+ )+}Button.propTypes = {text: PropTypes.string,