Replace logos throughout the UI with SiteLogo component

This commit is contained in:
Alex Gleason 2022-05-11 19:54:23 -05:00
parent 56f339a619
commit 01ec7bc279
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
7 changed files with 47 additions and 54 deletions

View file

@ -9,9 +9,10 @@ import { fetchOwnAccounts } from 'soapbox/actions/auth';
import { getSettings } from 'soapbox/actions/settings'; import { getSettings } from 'soapbox/actions/settings';
import { closeSidebar } from 'soapbox/actions/sidebar'; import { closeSidebar } from 'soapbox/actions/sidebar';
import Account from 'soapbox/components/account'; import Account from 'soapbox/components/account';
import SiteLogo from 'soapbox/components/site-logo';
import { Stack } from 'soapbox/components/ui'; import { Stack } from 'soapbox/components/ui';
import ProfileStats from 'soapbox/features/ui/components/profile_stats'; import ProfileStats from 'soapbox/features/ui/components/profile_stats';
import { useAppSelector, useSoapboxConfig, useFeatures } from 'soapbox/hooks'; import { useAppSelector, useFeatures } from 'soapbox/hooks';
import { makeGetAccount, makeGetOtherAccounts } from 'soapbox/selectors'; import { makeGetAccount, makeGetOtherAccounts } from 'soapbox/selectors';
import { getBaseURL } from 'soapbox/utils/accounts'; import { getBaseURL } from 'soapbox/utils/accounts';
@ -66,7 +67,6 @@ const SidebarMenu: React.FC = (): JSX.Element | null => {
const intl = useIntl(); const intl = useIntl();
const dispatch = useDispatch(); const dispatch = useDispatch();
const { logo } = useSoapboxConfig();
const features = useFeatures(); const features = useFeatures();
const getAccount = makeGetAccount(); const getAccount = makeGetAccount();
const instance = useAppSelector((state) => state.instance); const instance = useAppSelector((state) => state.instance);
@ -141,15 +141,7 @@ const SidebarMenu: React.FC = (): JSX.Element | null => {
<Stack space={4}> <Stack space={4}>
<HStack alignItems='center' justifyContent='between'> <HStack alignItems='center' justifyContent='between'>
<Link to='/' onClick={onClose}> <Link to='/' onClick={onClose}>
{logo ? ( <SiteLogo alt='Logo' className='h-5 w-auto cursor-pointer' />
<img alt='Logo' src={logo} className='h-5 w-auto cursor-pointer' />
) : (
<Icon
alt='Logo'
src={require('@tabler/icons/icons/home.svg')}
className='h-6 w-6 text-gray-400 hover:text-gray-600 dark:text-gray-200 cursor-pointer'
/>
)}
</Link> </Link>
<IconButton <IconButton

View file

@ -0,0 +1,30 @@
import React from 'react';
import { useSoapboxConfig, useSettings, useSystemTheme } from 'soapbox/hooks';
/** Display the most appropriate site logo based on the theme and configuration. */
const SiteLogo: React.FC<React.ComponentProps<'img'>> = (props) => {
const { logo, logoDarkMode } = useSoapboxConfig();
const settings = useSettings();
const systemTheme = useSystemTheme();
const userTheme = settings.get('themeMode');
const darkMode = userTheme === 'dark' || (userTheme === 'system' && systemTheme === 'dark');
// Use the right logo if provided, then use fallbacks.
const getSrc = () => {
// In demo mode, use the Soapbox logo.
if (settings.get('demo')) return require('images/soapbox-logo.svg');
return (darkMode && logoDarkMode)
? logoDarkMode
: logo || logoDarkMode || require('@tabler/icons/icons/home.svg');
};
return (
// eslint-disable-next-line jsx-a11y/alt-text
<img src={getSrc()} {...props} />
);
};
export default SiteLogo;

View file

@ -2,10 +2,10 @@ import React from 'react';
import { Link, Redirect, Route, Switch } from 'react-router-dom'; import { Link, Redirect, Route, Switch } from 'react-router-dom';
import LandingGradient from 'soapbox/components/landing-gradient'; import LandingGradient from 'soapbox/components/landing-gradient';
import SvgIcon from 'soapbox/components/ui/icon/svg-icon'; import SiteLogo from 'soapbox/components/site-logo';
import BundleContainer from 'soapbox/features/ui/containers/bundle_container'; import BundleContainer from 'soapbox/features/ui/containers/bundle_container';
import { NotificationsContainer } from 'soapbox/features/ui/util/async-components'; import { NotificationsContainer } from 'soapbox/features/ui/util/async-components';
import { useAppSelector, useSoapboxConfig } from 'soapbox/hooks'; import { useAppSelector } from 'soapbox/hooks';
import { Card, CardBody } from '../../components/ui'; import { Card, CardBody } from '../../components/ui';
import LoginPage from '../auth_login/components/login_page'; import LoginPage from '../auth_login/components/login_page';
@ -18,7 +18,6 @@ import Verification from '../verification';
import EmailPassthru from '../verification/email_passthru'; import EmailPassthru from '../verification/email_passthru';
const AuthLayout = () => { const AuthLayout = () => {
const { logo } = useSoapboxConfig();
const siteTitle = useAppSelector(state => state.instance.title); const siteTitle = useAppSelector(state => state.instance.title);
return ( return (
@ -29,15 +28,7 @@ const AuthLayout = () => {
<div className='w-full sm:max-w-lg md:max-w-2xl space-y-8'> <div className='w-full sm:max-w-lg md:max-w-2xl space-y-8'>
<header className='flex justify-center relative'> <header className='flex justify-center relative'>
<Link to='/' className='cursor-pointer'> <Link to='/' className='cursor-pointer'>
{logo ? ( <SiteLogo alt={siteTitle} className='h-7' />
<img src={logo} alt={siteTitle} className='h-7' />
) : (
<SvgIcon
className='w-7 h-7 dark:text-white'
alt={siteTitle}
src={require('@tabler/icons/icons/home.svg')}
/>
)}
</Link> </Link>
</header> </header>

View file

@ -1,4 +1,3 @@
import classNames from 'classnames';
import React from 'react'; import React from 'react';
import { defineMessages, useIntl } from 'react-intl'; import { defineMessages, useIntl } from 'react-intl';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
@ -6,6 +5,7 @@ import { Link, Redirect } from 'react-router-dom';
import { logIn, verifyCredentials } from 'soapbox/actions/auth'; import { logIn, verifyCredentials } from 'soapbox/actions/auth';
import { fetchInstance } from 'soapbox/actions/instance'; import { fetchInstance } from 'soapbox/actions/instance';
import SiteLogo from 'soapbox/components/site-logo';
import { useAppSelector, useFeatures, useSoapboxConfig } from 'soapbox/hooks'; import { useAppSelector, useFeatures, useSoapboxConfig } from 'soapbox/hooks';
import { openModal } from '../../../actions/modals'; import { openModal } from '../../../actions/modals';
@ -31,7 +31,6 @@ const Header = () => {
const soapboxConfig = useSoapboxConfig(); const soapboxConfig = useSoapboxConfig();
const pepeEnabled = soapboxConfig.getIn(['extensions', 'pepe', 'enabled']) === true; const pepeEnabled = soapboxConfig.getIn(['extensions', 'pepe', 'enabled']) === true;
const { logo, logoDarkMode } = soapboxConfig;
const features = useFeatures(); const features = useFeatures();
const instance = useAppSelector((state) => state.instance); const instance = useAppSelector((state) => state.instance);
const isOpen = features.accountCreation && instance.registrations; const isOpen = features.accountCreation && instance.registrations;
@ -80,11 +79,7 @@ const Header = () => {
<Sonar /> <Sonar />
</div> </div>
<Link to='/' className='z-10'> <Link to='/' className='z-10'>
<img alt='Logo' src={logo} className={classNames('h-6 w-auto cursor-pointer', { 'dark:hidden': logoDarkMode })} /> <SiteLogo alt='Logo' className='h-6 w-auto cursor-pointer' />
{logoDarkMode && (
<img alt='Logo' src={logoDarkMode} className='h-6 w-auto cursor-pointer hidden dark:block' />
)}
<span className='hidden'>{intl.formatMessage(messages.home)}</span> <span className='hidden'>{intl.formatMessage(messages.home)}</span>
</Link> </Link>
</div> </div>

View file

@ -2,6 +2,7 @@ import classNames from 'classnames';
import React from 'react'; import React from 'react';
import { defineMessages, useIntl } from 'react-intl'; import { defineMessages, useIntl } from 'react-intl';
import SiteLogo from 'soapbox/components/site-logo';
import { Button } from 'soapbox/components/ui'; import { Button } from 'soapbox/components/ui';
import { Modal } from 'soapbox/components/ui'; import { Modal } from 'soapbox/components/ui';
import { useAppSelector, useFeatures, useSoapboxConfig } from 'soapbox/hooks'; import { useAppSelector, useFeatures, useSoapboxConfig } from 'soapbox/hooks';
@ -23,7 +24,6 @@ const LandingPageModal: React.FC<ILandingPageModal> = ({ onClose }) => {
const soapboxConfig = useSoapboxConfig(); const soapboxConfig = useSoapboxConfig();
const pepeEnabled = soapboxConfig.getIn(['extensions', 'pepe', 'enabled']) === true; const pepeEnabled = soapboxConfig.getIn(['extensions', 'pepe', 'enabled']) === true;
const { logo } = soapboxConfig;
const instance = useAppSelector((state) => state.instance); const instance = useAppSelector((state) => state.instance);
const features = useFeatures(); const features = useFeatures();
@ -32,7 +32,7 @@ const LandingPageModal: React.FC<ILandingPageModal> = ({ onClose }) => {
return ( return (
<Modal <Modal
title={<img alt='Logo' src={logo} className='h-4 w-auto' />} title={<SiteLogo alt='Logo' className='h-4 w-auto' />}
onClose={() => onClose('LANDING_PAGE')} onClose={() => onClose('LANDING_PAGE')}
> >
<div className='mt-4 divide-y divide-solid divide-gray-200 dark:divide-slate-700'> <div className='mt-4 divide-y divide-solid divide-gray-200 dark:divide-slate-700'>

View file

@ -4,9 +4,10 @@ import { FormattedMessage } from 'react-intl';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { Avatar, Button, Icon } from 'soapbox/components/ui'; import SiteLogo from 'soapbox/components/site-logo';
import { Avatar, Button } from 'soapbox/components/ui';
import Search from 'soapbox/features/compose/components/search'; import Search from 'soapbox/features/compose/components/search';
import { useOwnAccount, useSoapboxConfig, useSettings } from 'soapbox/hooks'; import { useOwnAccount, useSoapboxConfig } from 'soapbox/hooks';
import { openSidebar } from '../../../actions/sidebar'; import { openSidebar } from '../../../actions/sidebar';
@ -17,14 +18,9 @@ const Navbar = () => {
const node = React.useRef(null); const node = React.useRef(null);
const account = useOwnAccount(); const account = useOwnAccount();
const settings = useSettings();
const soapboxConfig = useSoapboxConfig(); const soapboxConfig = useSoapboxConfig();
const singleUserMode = soapboxConfig.get('singleUserMode'); const singleUserMode = soapboxConfig.get('singleUserMode');
// In demo mode, use the Soapbox logo
const logo = settings.get('demo') ? require('images/soapbox-logo.svg') : soapboxConfig.logo;
const logoDarkMode = soapboxConfig.logoDarkMode;
const onOpenSidebar = () => dispatch(openSidebar()); const onOpenSidebar = () => dispatch(openSidebar());
return ( return (
@ -46,21 +42,10 @@ const Navbar = () => {
'justify-start': !account, 'justify-start': !account,
})} })}
> >
{logo ? ( <Link key='logo' to='/' data-preview-title-id='column.home' className='flex-shrink-0 flex items-center'>
<Link key='logo' to='/' data-preview-title-id='column.home' className='flex-shrink-0 flex items-center'> <SiteLogo alt='Logo' className='h-5 lg:h-6 w-auto cursor-pointer' />
<img alt='Logo' src={logo} className={classNames('h-5 lg:h-6 w-auto cursor-pointer', { 'dark:hidden': logoDarkMode })} /> <span className='hidden'><FormattedMessage id='tabs_bar.home' defaultMessage='Home' /></span>
{logoDarkMode && ( </Link>
<img alt='Logo' src={logoDarkMode} className='h-5 lg:h-6 w-auto cursor-pointer hidden dark:block' />
)}
<span className='hidden'><FormattedMessage id='tabs_bar.home' defaultMessage='Home' /></span>
</Link>
) : (
<Link key='logo' to='/' data-preview-title-id='column.home' className='flex-shrink-0 flex items-center'>
<Icon alt='Logo' src={require('@tabler/icons/icons/home.svg')} className='h-5 lg:h-6 w-auto text-primary-700' />
<span className='hidden'><FormattedMessage id='tabs_bar.home' defaultMessage='Home' /></span>
</Link>
)}
{account && ( {account && (
<div className='flex-1 hidden lg:flex justify-center px-2 lg:ml-6 lg:justify-start items-center'> <div className='flex-1 hidden lg:flex justify-center px-2 lg:ml-6 lg:justify-start items-center'>