Merge branch 'fix-colors' into 'next'

Resolve missing CSS variables in the theme

See merge request soapbox-pub/soapbox-fe!1140
This commit is contained in:
Justin
2022-03-24 16:17:04 +00:00
5 changed files with 68 additions and 93 deletions

View File

@@ -1,87 +0,0 @@
import PropTypes from 'prop-types';
import React from 'react';
import { Helmet } from'react-helmet';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { getSettings } from 'soapbox/actions/settings';
// import sourceCode from 'soapbox/utils/code';
import FaviconService from 'soapbox/utils/favicon_service';
FaviconService.initFaviconService();
const getNotifTotals = state => {
const notifications = state.getIn(['notifications', 'unread'], 0);
const chats = state.getIn(['chats', 'items']).reduce((acc, curr) => acc + Math.min(curr.get('unread', 0), 1), 0);
const reports = state.getIn(['admin', 'openReports']).count();
const approvals = state.getIn(['admin', 'awaitingApproval']).count();
return notifications + chats + reports + approvals;
};
const mapStateToProps = state => {
const settings = getSettings(state);
return {
siteTitle: state.getIn(['instance', 'title']),
unreadCount: getNotifTotals(state),
demetricator: settings.get('demetricator'),
};
};
class SoapboxHelmet extends React.Component {
static propTypes = {
siteTitle: PropTypes.string,
children: PropTypes.node,
unreadCount: PropTypes.number,
demetricator: PropTypes.bool,
};
hasUnread = () => {
const { unreadCount, demetricator } = this.props;
return !(unreadCount < 1 || demetricator);
}
addCounter = title => {
const { unreadCount } = this.props;
const hasUnread = this.hasUnread();
return hasUnread ? `(${unreadCount}) ${title}` : title;
}
updateFaviconBadge = () => {
const hasUnread = this.hasUnread();
if (hasUnread) {
FaviconService.drawFaviconBadge();
} else {
FaviconService.clearFaviconBadge();
}
}
componentDidUpdate(prevProps) {
if (this.props.unreadCount !== prevProps.unreadCount || this.props.demetricator !== prevProps.demetricator) {
this.updateFaviconBadge();
}
}
componentDidMount() {
this.updateFaviconBadge();
}
render() {
const { siteTitle, children } = this.props;
return (
<Helmet
titleTemplate={this.addCounter(`%s | ${siteTitle}`)}
defaultTitle={this.addCounter(siteTitle)}
defer={false}
>
{children}
</Helmet>
);
}
}
export default withRouter(connect(mapStateToProps)(SoapboxHelmet));

View File

@@ -0,0 +1,53 @@
import * as React from 'react';
import { Helmet as ReactHelmet } from'react-helmet';
import { useAppSelector, useSettings } from 'soapbox/hooks';
import FaviconService from 'soapbox/utils/favicon_service';
FaviconService.initFaviconService();
const getNotifTotals = (state: any) => {
const notifications = state.getIn(['notifications', 'unread'], 0);
const chats = state.getIn(['chats', 'items']).reduce((acc: any, curr: any) => acc + Math.min(curr.get('unread', 0), 1), 0);
const reports = state.getIn(['admin', 'openReports']).count();
const approvals = state.getIn(['admin', 'awaitingApproval']).count();
return notifications + chats + reports + approvals;
};
const Helmet: React.FC = ({ children }) => {
const settings = useSettings();
const title = useAppSelector((state) => state.instance.get('title'));
const unreadCount = useAppSelector((state) => getNotifTotals(state));
const demetricator = useAppSelector((state) => settings.get('demetricator'));
const hasUnreadNotifications = React.useMemo(() => !(unreadCount < 1 || demetricator), [unreadCount, demetricator]);
const addCounter = (string: string) => {
return hasUnreadNotifications ? `(${unreadCount}) ${title}` : title;
};
const updateFaviconBadge = () => {
if (hasUnreadNotifications) {
FaviconService.drawFaviconBadge();
} else {
FaviconService.clearFaviconBadge();
}
};
React.useEffect(() => {
updateFaviconBadge();
}, [unreadCount, demetricator]);
return (
<ReactHelmet
titleTemplate={addCounter(`%s | ${title}`)}
defaultTitle={addCounter(title)}
defer={false}
>
{children}
</ReactHelmet>
);
};
export default Helmet;

View File

@@ -166,15 +166,16 @@ class SoapboxMount extends React.PureComponent {
return (
<IntlProvider locale={locale} messages={this.state.messages}>
<Helmet>
<html lang='en' className={classNames({ dark: this.props.themeMode === 'dark' })} />
<body className={bodyClass} />
{themeCss && <style id='theme' type='text/css'>{`:root{${themeCss}}`}</style>}
<meta name='theme-color' content={this.props.brandColor} />
</Helmet>
<ErrorBoundary>
<BrowserRouter basename={FE_SUBDIRECTORY}>
<>
<Helmet>
<html lang='en' className={classNames({ dark: this.props.themeMode === 'dark' })} />
<body className={bodyClass} />
{themeCss && <style id='theme' type='text/css'>{`:root{${themeCss}}`}</style>}
<meta name='theme-color' content={this.props.brandColor} />
</Helmet>
<ScrollContext shouldUpdateScroll={this.shouldUpdateScroll}>
<Switch>
<Redirect from='/v1/verify_email/:token' to='/auth/verify/email/:token' />