2022-03-21 15:28:57 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { defineMessages, useIntl } from 'react-intl';
|
|
|
|
|
2022-09-10 14:52:06 -07:00
|
|
|
import { changeComposeContentType } from 'soapbox/actions/compose';
|
2022-09-14 11:01:00 -07:00
|
|
|
import { useAppDispatch, useCompose } from 'soapbox/hooks';
|
2022-09-10 14:52:06 -07:00
|
|
|
|
2022-11-15 09:23:36 -08:00
|
|
|
import ComposeFormButton from './compose-form-button';
|
2022-03-21 15:28:57 -07:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
marked: { id: 'compose_form.markdown.marked', defaultMessage: 'Post markdown enabled' },
|
|
|
|
unmarked: { id: 'compose_form.markdown.unmarked', defaultMessage: 'Post markdown disabled' },
|
|
|
|
});
|
|
|
|
|
|
|
|
interface IMarkdownButton {
|
2023-02-15 13:26:27 -08:00
|
|
|
composeId: string
|
2022-03-21 15:28:57 -07:00
|
|
|
}
|
|
|
|
|
2022-09-10 14:52:06 -07:00
|
|
|
const MarkdownButton: React.FC<IMarkdownButton> = ({ composeId }) => {
|
2022-03-21 15:28:57 -07:00
|
|
|
const intl = useIntl();
|
2022-09-10 14:52:06 -07:00
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
|
2022-09-14 11:01:00 -07:00
|
|
|
const active = useCompose(composeId).content_type === 'text/markdown';
|
2022-09-10 14:52:06 -07:00
|
|
|
|
|
|
|
const onClick = () => dispatch(changeComposeContentType(composeId, active ? 'text/plain' : 'text/markdown'));
|
2022-03-21 15:28:57 -07:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ComposeFormButton
|
2022-07-09 09:20:02 -07:00
|
|
|
icon={require('@tabler/icons/markdown.svg')}
|
2022-03-21 15:28:57 -07:00
|
|
|
title={intl.formatMessage(active ? messages.marked : messages.unmarked)}
|
|
|
|
active={active}
|
|
|
|
onClick={onClick}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
export default MarkdownButton;
|