Skip to content

Commit 02bce98

Browse files
committed
Add content_type selector to the compose box
1 parent 492528e commit 02bce98

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

src/components/ICONS.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,9 @@ export const ICONS = {
174174
'heart-break': () => import('@iconify-icons/mingcute/heart-crack-line'),
175175
'user-x': () => import('@iconify-icons/mingcute/user-x-line'),
176176
minimize: () => import('@iconify-icons/mingcute/arrows-down-line'),
177+
'font': () => import('@iconify-icons/mingcute/font-line'),
178+
'brackets-angle': () => import('@iconify-icons/mingcute/brackets-angle-line'),
179+
'asterisk': () => import('@iconify-icons/mingcute/asterisk-line'),
180+
'brackets': () => import('@iconify-icons/mingcute/brackets-line'),
181+
'currency-dollar-2': () => import('@iconify-icons/mingcute/currency-dollar-2-line'),
177182
};

src/components/compose.jsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
import supports from '../utils/supports';
5252
import useCloseWatcher from '../utils/useCloseWatcher';
5353
import useInterval from '../utils/useInterval';
54+
import contentTypesIconMap from '../utils/content-types-icon-map.js';
5455
import visibilityIconsMap from '../utils/visibility-icons-map';
5556

5657
import AccountBlock from './account-block';
@@ -248,6 +249,7 @@ function Compose({
248249
const textareaRef = useRef();
249250
const spoilerTextRef = useRef();
250251
const [visibility, setVisibility] = useState('public');
252+
const [contentType, setContentType] = useState('text/plain');
251253
const [sensitive, setSensitive] = useState(false);
252254
const [language, setLanguage] = useState(
253255
store.session.get('currentLanguage') || DEFAULT_LANG,
@@ -1064,6 +1066,9 @@ function Compose({
10641066
// params.inReplyToId = replyToStatus?.id || undefined;
10651067
params.in_reply_to_id = replyToStatus?.id || undefined;
10661068
}
1069+
if (supports('@akkoma/post-content-type')) {
1070+
params.content_type = contentType;
1071+
}
10671072
params = removeNullUndefined(params);
10681073
console.log('POST', params);
10691074

@@ -1150,6 +1155,38 @@ function Compose({
11501155
/>
11511156
<Icon icon={`eye-${sensitive ? 'close' : 'open'}`} />
11521157
</label>{' '}
1158+
{supports('@akkoma/post-content-type') && (
1159+
<>
1160+
<label class={`toolbar-button ${contentType !== 'text/plain' && !sensitive ? 'show-field' : ''} ${contentType !== 'text/plain' ? 'highlight' : ''}`}>
1161+
<Icon icon={contentTypesIconMap[contentType]} alt={visibility} />
1162+
<select
1163+
name={'contentType'}
1164+
value={contentType}
1165+
onChange={(e) => {
1166+
setContentType(e.target.value);
1167+
}}
1168+
disabled={uiState === 'loading'}
1169+
dir={'auto'}
1170+
>
1171+
<option value="text/plain">
1172+
<Trans>Plain text</Trans>
1173+
</option>
1174+
<option value="text/html">
1175+
<Trans>HTML</Trans>
1176+
</option>
1177+
<option value="text/markdown">
1178+
<Trans>Markdown</Trans>
1179+
</option>
1180+
<option value="text/bbcode">
1181+
<Trans>BBCode</Trans>
1182+
</option>
1183+
<option value="text/x.misskeymarkdown">
1184+
<Trans>MFM</Trans>
1185+
</option>
1186+
</select>
1187+
</label>{' '}
1188+
</>
1189+
)}
11531190
<label
11541191
class={`toolbar-button ${
11551192
visibility !== 'public' && !sensitive ? 'show-field' : ''
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default {
2+
"text/plain": 'font',
3+
"text/html": 'brackets-angle',
4+
"text/markdown": 'asterisk',
5+
"text/bbcode": 'brackets',
6+
"text/x.misskeymarkdown": 'currency-dollar-2',
7+
};

src/utils/supports.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const platformFeatures = {
2424
'@pixelfed/global-feed': containPixelfed,
2525
'@pleroma/local-visibility-post': containPleroma,
2626
'@akkoma/local-visibility-post': containAkkoma,
27+
'@akkoma/post-content-type': containAkkoma,
2728
};
2829
const supportsCache = {};
2930

0 commit comments

Comments
 (0)