Move FloatingActionButton to its own component

This commit is contained in:
Alex Gleason 2022-12-23 14:51:57 -06:00
parent 472af420c0
commit 7a6126b978
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
3 changed files with 43 additions and 38 deletions

View file

@ -0,0 +1,38 @@
import React from 'react';
import { defineMessages, useIntl } from 'react-intl';
import { openModal } from 'soapbox/actions/modals';
import { Icon } from 'soapbox/components/ui';
import { useAppDispatch } from 'soapbox/hooks';
const messages = defineMessages({
publish: { id: 'compose_form.publish', defaultMessage: 'Publish' },
});
interface IFloatingActionButton {
}
/** FloatingActionButton (aka FAB), a composer button that floats in the corner on mobile. */
const FloatingActionButton: React.FC<IFloatingActionButton> = () => {
const intl = useIntl();
const dispatch = useAppDispatch();
const handleOpenComposeModal = () => {
dispatch(openModal('COMPOSE'));
};
return (
<button
onClick={handleOpenComposeModal}
className='z-40 lg:hidden transition-all fixed bottom-24 right-4 p-4 text-white bg-accent-300 hover:bg-accent-500 rounded-full'
aria-label={intl.formatMessage(messages.publish)}
>
<Icon
src={require('@tabler/icons/pencil-plus.svg')}
className='w-6 h-6 stroke-[1.5px]'
/>
</button>
);
};
export default FloatingActionButton;

View file

@ -2,7 +2,7 @@
import React, { useState, useEffect, useRef } from 'react';
import { HotKeys } from 'react-hotkeys';
import { defineMessages, useIntl } from 'react-intl';
import { useIntl } from 'react-intl';
import { Switch, useHistory, useLocation, Redirect } from 'react-router-dom';
import { fetchFollowRequests } from 'soapbox/actions/accounts';
@ -20,7 +20,6 @@ import { fetchScheduledStatuses } from 'soapbox/actions/scheduled-statuses';
import { connectUserStream } from 'soapbox/actions/streaming';
import { fetchSuggestionsForTimeline } from 'soapbox/actions/suggestions';
import { expandHomeTimeline } from 'soapbox/actions/timelines';
import Icon from 'soapbox/components/icon';
import SidebarNavigation from 'soapbox/components/sidebar-navigation';
import ThumbNavigation from 'soapbox/components/thumb-navigation';
import { Layout } from 'soapbox/components/ui';
@ -39,6 +38,7 @@ import { getAccessToken, getVapidKey } from 'soapbox/utils/auth';
import { isStandalone } from 'soapbox/utils/state';
import BackgroundShapes from './components/background-shapes';
import FloatingActionButton from './components/floating-action-button';
import { supportedPolicyIds } from './components/modals/policy-modal';
import Navbar from './components/navbar';
import BundleContainer from './containers/bundle-container';
@ -121,11 +121,6 @@ import 'soapbox/components/status';
const EmptyPage = HomePage;
const messages = defineMessages({
beforeUnload: { id: 'ui.beforeunload', defaultMessage: 'Your draft will be lost if you leave.' },
publish: { id: 'compose_form.publish', defaultMessage: 'Publish' },
});
const keyMap = {
help: '?',
new: 'n',
@ -597,10 +592,6 @@ const UI: React.FC = ({ children }) => {
history.push('/follow_requests');
};
const handleOpenComposeModal = () => {
dispatch(openModal('COMPOSE'));
};
const shouldHideFAB = (): boolean => {
const path = location.pathname;
return Boolean(path.match(/^\/posts\/|^\/search|^\/getting-started|^\/chats/));
@ -627,19 +618,6 @@ const UI: React.FC = ({ children }) => {
goToRequests: handleHotkeyGoToRequests,
};
const fabElem = (
<button
key='floating-action-button'
onClick={handleOpenComposeModal}
className='floating-action-button'
aria-label={intl.formatMessage(messages.publish)}
>
<Icon src={require('@tabler/icons/pencil-plus.svg')} />
</button>
);
const floatingActionButton = shouldHideFAB() ? null : fabElem;
const style: React.CSSProperties = {
pointerEvents: dropdownMenuIsOpen ? 'none' : undefined,
};
@ -662,7 +640,9 @@ const UI: React.FC = ({ children }) => {
</SwitchingColumnsArea>
</Layout>
{me && floatingActionButton}
{(me && !shouldHideFAB()) && (
<FloatingActionButton />
)}
<BundleContainer fetchComponent={UploadArea}>
{Component => <Component active={draggingOver} onClose={closeUploadModal} />}

View file

@ -241,19 +241,6 @@
}
}
.floating-action-button {
@apply z-40 lg:hidden transition-all fixed bottom-24 right-4 p-4 text-white bg-accent-300 hover:bg-accent-500 rounded-full;
.svg-icon {
@apply w-6 h-6;
svg {
@apply w-6; // iOS fix
stroke-width: 1.5px;
}
}
}
.slist {
&--flex {
display: flex;