1
0
puyopuyotetr.is/app/javascript/flavours/glitch/components/column_back_button.tsx
Claire a1920425ca [Glitch] Switch from 48px weight 600 material symbol icons to 24px weight 400 icons
Port 6bbcd9348e to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
2024-01-15 20:53:08 +01:00

45 lines
1.2 KiB
TypeScript

import { useCallback } from 'react';
import { FormattedMessage } from 'react-intl';
import { Icon } from 'flavours/glitch/components/icon';
import { ButtonInTabsBar } from 'flavours/glitch/features/ui/util/columns_context';
import ArrowBackIcon from 'mastodon/../material-icons/400-24px/arrow_back.svg?react';
import { useAppHistory } from './router';
type OnClickCallback = () => void;
function useHandleClick(onClick?: OnClickCallback) {
const history = useAppHistory();
return useCallback(() => {
if (onClick) {
onClick();
} else if (history.location.state?.fromMastodon) {
history.goBack();
} else {
history.push('/');
}
}, [history, onClick]);
}
export const ColumnBackButton: React.FC<{ onClick: OnClickCallback }> = ({
onClick,
}) => {
const handleClick = useHandleClick(onClick);
const component = (
<button onClick={handleClick} className='column-back-button'>
<Icon
id='chevron-left'
icon={ArrowBackIcon}
className='column-back-button__icon'
/>
<FormattedMessage id='column_back_button.label' defaultMessage='Back' />
</button>
);
return <ButtonInTabsBar>{component}</ButtonInTabsBar>;
};