From d13cddc6368845771fa588f2864d71d397c2dfce Mon Sep 17 00:00:00 2001 From: Andrew Plummer Date: Thu, 13 Jun 2024 10:57:09 +0900 Subject: [PATCH] tweaks to theming --- services/api/src/models/definitions/user.json | 15 -- .../{logo-inverted.svg => logo-dark.svg} | 0 .../src/assets/{logo.svg => logo-light.svg} | 0 services/web/src/components/Footer.js | 11 +- services/web/src/components/Logo.js | 12 ++ services/web/src/components/LogoTitle.js | 12 +- services/web/src/components/ThemedImage.js | 6 - services/web/src/index.html | 2 +- services/web/src/layouts/Dashboard.js | 6 +- services/web/src/layouts/Portal.js | 7 +- .../web/src/screens/Settings/Appearance.js | 150 +++++------------- services/web/src/stores/session.js | 7 - services/web/src/stores/theme.js | 67 ++++---- 13 files changed, 90 insertions(+), 205 deletions(-) rename services/web/src/assets/{logo-inverted.svg => logo-dark.svg} (100%) rename services/web/src/assets/{logo.svg => logo-light.svg} (100%) create mode 100644 services/web/src/components/Logo.js delete mode 100644 services/web/src/components/ThemedImage.js diff --git a/services/api/src/models/definitions/user.json b/services/api/src/models/definitions/user.json index 1aead21ce..abbb02436 100644 --- a/services/api/src/models/definitions/user.json +++ b/services/api/src/models/definitions/user.json @@ -52,14 +52,6 @@ } } ], - "theme": { - "type": "String", - "enum": [ - "dark", - "light", - "system" - ] - }, "isTester": { "type": "Boolean", "default": false @@ -165,13 +157,6 @@ ] } }, - "onDelete": { - "errorOnReferenced": { - "except": [ - "AuditEntry" - ] - } - }, "search": { "fields": [ "firstName", diff --git a/services/web/src/assets/logo-inverted.svg b/services/web/src/assets/logo-dark.svg similarity index 100% rename from services/web/src/assets/logo-inverted.svg rename to services/web/src/assets/logo-dark.svg diff --git a/services/web/src/assets/logo.svg b/services/web/src/assets/logo-light.svg similarity index 100% rename from services/web/src/assets/logo.svg rename to services/web/src/assets/logo-light.svg diff --git a/services/web/src/components/Footer.js b/services/web/src/components/Footer.js index e02c0ba94..8ef285969 100644 --- a/services/web/src/components/Footer.js +++ b/services/web/src/components/Footer.js @@ -1,10 +1,8 @@ import React from 'react'; -import logo from 'assets/logo.svg'; -import darkLogo from 'assets/logo-inverted.svg'; +import Logo from 'components/Logo'; import Layout from './Layout'; -import ThemedImage from './ThemedImage'; export default class Footer extends React.Component { render() { @@ -12,12 +10,7 @@ export default class Footer extends React.Component { ); diff --git a/services/web/src/components/Logo.js b/services/web/src/components/Logo.js new file mode 100644 index 000000000..da5944bd5 --- /dev/null +++ b/services/web/src/components/Logo.js @@ -0,0 +1,12 @@ +import { useTheme } from 'stores/theme'; + +import logoLight from 'assets/logo-light.svg'; +import logoDark from 'assets/logo-dark.svg'; + +import { APP_NAME } from 'utils/env'; + +export default function Logo(props) { + const { currentTheme } = useTheme(); + const src = currentTheme === 'dark' ? logoDark : logoLight; + return {APP_NAME}; +} diff --git a/services/web/src/components/LogoTitle.js b/services/web/src/components/LogoTitle.js index 8a8df2530..fc0782f65 100644 --- a/services/web/src/components/LogoTitle.js +++ b/services/web/src/components/LogoTitle.js @@ -2,21 +2,13 @@ import React from 'react'; import { Header } from 'semantic'; import { Link } from 'react-router-dom'; -import Logo from 'assets/logo.svg'; -import DarkLogo from 'assets/logo-inverted.svg'; - -import ThemedImage from './ThemedImage'; +import Logo from 'components/Logo'; export default ({ title }) => { return ( - +
{title} diff --git a/services/web/src/components/ThemedImage.js b/services/web/src/components/ThemedImage.js deleted file mode 100644 index 789e1c859..000000000 --- a/services/web/src/components/ThemedImage.js +++ /dev/null @@ -1,6 +0,0 @@ -import { useTheme } from 'stores'; - -export default function ThemedImage({ darkSrc, ligthSrc, ...props }) { - const { renderedTheme } = useTheme(); - return ; -} diff --git a/services/web/src/index.html b/services/web/src/index.html index 1f7bc64df..5c5cb91e8 100644 --- a/services/web/src/index.html +++ b/services/web/src/index.html @@ -10,7 +10,7 @@ <%= require('utils/analytics/head.html') %> - +
<%= require('utils/analytics/body.html') %> diff --git a/services/web/src/layouts/Dashboard.js b/services/web/src/layouts/Dashboard.js index c8aaf3fda..8425a59ec 100644 --- a/services/web/src/layouts/Dashboard.js +++ b/services/web/src/layouts/Dashboard.js @@ -4,15 +4,13 @@ import { Icon, Container } from 'semantic'; import { withSession } from 'stores'; +import Logo from 'components/Logo'; import Footer from 'components/Footer'; import Layout from 'components/Layout'; import Protected from 'components/Protected'; -import ThemedImage from 'components/ThemedImage'; import Organization from 'modals/OrganizationSelector'; import ConnectionError from 'components/ConnectionError'; -import logo from 'assets/logo.svg'; -import darkLogo from 'assets/logo-inverted.svg'; import favicon from 'assets/favicon.svg'; import { userCanSwitchOrganizations } from 'utils/permissions'; @@ -29,7 +27,7 @@ export default class DashboardLayout extends React.Component { - + {userCanSwitchOrganizations(user) && ( diff --git a/services/web/src/layouts/Portal.js b/services/web/src/layouts/Portal.js index ac3b188d9..b6337ca78 100644 --- a/services/web/src/layouts/Portal.js +++ b/services/web/src/layouts/Portal.js @@ -4,13 +4,10 @@ import { Button, Icon, Menu } from 'semantic'; import bem from 'helpers/bem'; +import Logo from 'components/Logo'; import Layout from 'components/Layout'; -import ThemedImage from 'components/ThemedImage'; import ConnectionError from 'components/ConnectionError'; -import darkLogo from 'assets/logo-inverted.svg'; -import logo from 'assets/logo.svg'; - import './portal.less'; @bem @@ -26,7 +23,7 @@ export default class PortalLayout extends React.Component { spread> - + diff --git a/services/web/src/screens/Settings/Appearance.js b/services/web/src/screens/Settings/Appearance.js index 550b691b8..3bbe925bb 100644 --- a/services/web/src/screens/Settings/Appearance.js +++ b/services/web/src/screens/Settings/Appearance.js @@ -1,122 +1,50 @@ import React from 'react'; -import { Segment, Form, Button, Divider, Header } from 'semantic'; - -import { withTheme } from 'stores'; +import { Segment, Form, Divider, Header } from 'semantic'; import screen from 'helpers/screen'; +import { useTheme } from 'stores/theme'; -import ErrorMessage from 'components/ErrorMessage'; import Layout from 'components/Layout'; -import { request } from 'utils/api'; -import { APP_NAME } from 'utils/env'; - import Menu from './Menu'; -@screen -@withTheme -export default class Account extends React.Component { - state = { - theme: this.context.theme, - }; - - async save() { - try { - this.setState({ - loading: true, - error: null, - }); - await request({ - method: 'PATCH', - path: `/1/users/me`, - body: { - theme: this.state.theme, - }, - }); - this.context.setTheme(this.state.theme, true); - this.setState({ - error: false, - loading: false, - }); - } catch (error) { - this.setState({ - error, - loading: false, - }); - } - } - - setTheme(theme) { - this.setState({ theme }); - this.context.setTheme(theme); - } - - render() { - const { error, loading, theme } = this.state; - - return ( - - +function Appearance() { + const { theme, setTheme } = useTheme(); + return ( + + +