forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Content-Type back as a toggle button
- Loading branch information
1 parent
993b492
commit 74541aa
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
app/javascript/flavours/glitch/features/compose/components/content_type_button.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useCallback } from 'react'; | ||
|
||
import { useIntl, defineMessages } from 'react-intl'; | ||
|
||
import CodeIcon from '@/material-icons/400-24px/code.svg?react'; | ||
import MarkdownIcon from '@/material-icons/400-24px/markdown.svg?react'; | ||
import { changeComposeContentType } from 'flavours/glitch/actions/compose'; | ||
import { IconButton } from 'flavours/glitch/components/icon_button'; | ||
import { useAppSelector, useAppDispatch } from 'flavours/glitch/store'; | ||
|
||
const messages = defineMessages({ | ||
disable_html: { id: 'compose.advanced_formatting.disable_html', defaultMessage: 'Disable HTML advanced formatting' }, | ||
disable_markdown: { id: 'compose.advanced_formatting.disable_markdown', defaultMessage: 'Disable Markdown advanced formatting' }, | ||
enable_markdown: { id: 'compose.advanced_formatting.enable_markdown', defaultMessage: 'Enable Markdown advanced formatting' }, | ||
}); | ||
|
||
export const ContentTypeButton = () => { | ||
const intl = useIntl(); | ||
|
||
const showButton = useAppSelector((state) => state.getIn(['local_settings', 'show_content_type_choice'])); | ||
const contentType = useAppSelector((state) => state.getIn(['compose', 'content_type'])); | ||
const dispatch = useAppDispatch(); | ||
|
||
const handleClick = useCallback(() => { | ||
dispatch(changeComposeContentType(contentType === 'text/plain' ? 'text/markdown' : 'text/plain')); | ||
}, [contentType, dispatch]); | ||
|
||
if (!showButton) { | ||
return null; | ||
} | ||
|
||
const active = contentType !== 'text/plain'; | ||
const iconComponent = contentType === 'text/html' ? CodeIcon : MarkdownIcon; | ||
const icon = contentType === 'text/html' ? 'code' : 'arrow-circle-down'; | ||
|
||
const title = { | ||
'text/html': intl.formatMessage(messages.disable_html), | ||
'text/markdown': intl.formatMessage(messages.disable_markdown), | ||
'text/plain': intl.formatMessage(messages.enable_markdown), | ||
}[contentType]; | ||
|
||
return ( | ||
<IconButton | ||
onClick={handleClick} | ||
icon={icon} | ||
iconComponent={iconComponent} | ||
title={title} | ||
active={active} | ||
size={18} | ||
inverted | ||
/> | ||
); | ||
}; |