Skip to content

Commit

Permalink
tweaks to theming
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewplummer committed Jun 13, 2024
1 parent fa2d95e commit d13cddc
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 205 deletions.
15 changes: 0 additions & 15 deletions services/api/src/models/definitions/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@
}
}
],
"theme": {
"type": "String",
"enum": [
"dark",
"light",
"system"
]
},
"isTester": {
"type": "Boolean",
"default": false
Expand Down Expand Up @@ -165,13 +157,6 @@
]
}
},
"onDelete": {
"errorOnReferenced": {
"except": [
"AuditEntry"
]
}
},
"search": {
"fields": [
"firstName",
Expand Down
File renamed without changes
File renamed without changes
11 changes: 2 additions & 9 deletions services/web/src/components/Footer.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
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() {
return (
<footer>
<Layout horizontal center right>
<span style={{ marginRight: '10px' }}>Built with</span>
<ThemedImage
width="112"
height="24"
darkSrc={darkLogo}
ligthSrc={logo}
/>
<Logo width="112" height="24" />
</Layout>
</footer>
);
Expand Down
12 changes: 12 additions & 0 deletions services/web/src/components/Logo.js
Original file line number Diff line number Diff line change
@@ -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 <img src={src} alt={APP_NAME} {...props} />;
}
12 changes: 2 additions & 10 deletions services/web/src/components/LogoTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<React.Fragment>
<Link to="/">
<ThemedImage
ligthSrc={Logo}
darkSrc={DarkLogo}
alt="Logo"
style={{ height: '75px', margin: 'auto', display: 'block' }}
/>
<Logo style={{ height: '75px', margin: 'auto', display: 'block' }} />
</Link>
<Header as="h3" textAlign="center" style={{ textTransform: 'uppercase' }}>
{title}
Expand Down
6 changes: 0 additions & 6 deletions services/web/src/components/ThemedImage.js

This file was deleted.

2 changes: 1 addition & 1 deletion services/web/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<%= require('utils/analytics/head.html') %>
<!-- env:conf -->
</head>
<body class="nocturnal-theme">
<body>
<div id="root"></div>
<%= require('utils/analytics/body.html') %>
</body>
Expand Down
6 changes: 2 additions & 4 deletions services/web/src/layouts/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -29,7 +27,7 @@ export default class DashboardLayout extends React.Component {
<Sidebar.Menu>
<Layout style={{ height: '100%' }}>
<NavLink style={{ margin: '5px 25px 20px 25px' }} to="/">
<ThemedImage width="100%" ligthSrc={logo} darkSrc={darkLogo} />
<Logo width="100%" />
</NavLink>
<Layout vertical spread>
{userCanSwitchOrganizations(user) && (
Expand Down
7 changes: 2 additions & 5 deletions services/web/src/layouts/Portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,7 +23,7 @@ export default class PortalLayout extends React.Component {
spread>
<Layout.Group>
<NavLink className="logo" to="/">
<ThemedImage height="40" ligthSrc={logo} darkSrc={darkLogo} />
<Logo height="40" />
</NavLink>
<Menu className={this.getElementClass('menu-bottom')} secondary>
<Menu.Item as={NavLink} to="/docs/getting-started">
Expand Down
150 changes: 39 additions & 111 deletions services/web/src/screens/Settings/Appearance.js
Original file line number Diff line number Diff line change
@@ -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 (
<React.Fragment>
<Menu />
function Appearance() {
const { theme, setTheme } = useTheme();
return (
<React.Fragment>
<Menu />
<Divider hidden />
<Segment>
<Header as="h5">Choose the theme for this device</Header>
<Divider hidden />
<ErrorMessage error={error} />
<Form onSubmit={() => this.save()}>
<Segment>
<p>
Choose how {APP_NAME} looks to you. Select a light or dark mode,
or sync with your system and automatically switch between light
and dark mode.
</p>
<Header as="h5">
<Form.Checkbox
checked={theme === 'system'}
onChange={(e, { checked }) =>
this.setTheme(checked ? 'system' : undefined)
}
label="Sync With System"
/>
</Header>
<Layout vertical>
<Form.Radio
checked={theme === 'light'}
label="Light Mode"
onClick={() => {
setTheme('light');
}}
/>
<Form.Radio
checked={theme === 'dark'}
label="Dark Mode"
onClick={() => {
setTheme('dark');
}}
/>
<Form.Radio
checked={theme === 'system'}
label="Sync with System"
onClick={() => {
setTheme('system');
}}
/>
</Layout>

<p style={{ marginLeft: '1.92em', marginTop: '-0.8em' }}>
Sync with OS setting Automatically switch between light and dark
themes when your system does.
</p>

<Divider hidden />

<div className="diurnal-theme" style={{ paddingBottom: '1em' }}>
<Layout horizontal baseline>
<Form.Radio
disabled={theme === 'system'}
checked={theme === 'light'}
label="Light Mode"
onClick={() => this.setTheme('light')}
/>
</Layout>
</div>

<div className="nocturnal-theme">
<Layout horizontal baseline>
<Form.Radio
disabled={theme === 'system'}
checked={theme === 'dark'}
label="Dark Mode"
onClick={() => this.setTheme('dark')}
/>
</Layout>
</div>

<Divider hidden />
</Segment>
<div>
<Button
primary
content="Save"
loading={loading}
disabled={loading}
/>
</div>
</Form>
</React.Fragment>
);
}
<Divider hidden />
</Segment>
</React.Fragment>
);
}

export default screen(Appearance);
7 changes: 0 additions & 7 deletions services/web/src/stores/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import { captureError } from 'utils/sentry';
import { wrapContext } from 'utils/hoc';
import { localStorage } from 'utils/storage';

import { withTheme } from './theme';

const SessionContext = React.createContext();

@withTheme
@withRouter
export class SessionProvider extends React.PureComponent {
constructor(props) {
Expand Down Expand Up @@ -68,10 +65,6 @@ export class SessionProvider extends React.PureComponent {
});
const organization = await this.loadOrganization();

if (user.theme) {
this.context.setTheme(user.theme, true);
}

// Uncomment this line if you want to set up
// User-Id tracking. https://bit.ly/2DKQYEN.
// setUserId(user.id);
Expand Down
Loading

0 comments on commit d13cddc

Please sign in to comment.