Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/ICONS.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,10 @@ export const ICONS = {
'user-x': () => import('@iconify-icons/mingcute/user-x-line'),
minimize: () => import('@iconify-icons/mingcute/arrows-down-line'),
celebrate: () => import('@iconify-icons/mingcute/celebrate-line'),
font: () => import('@iconify-icons/mingcute/font-line'),
'brackets-angle': () => import('@iconify-icons/mingcute/brackets-angle-line'),
asterisk: () => import('@iconify-icons/mingcute/asterisk-line'),
brackets: () => import('@iconify-icons/mingcute/brackets-line'),
'currency-dollar-2': () =>
import('@iconify-icons/mingcute/currency-dollar-2-line'),
};
65 changes: 60 additions & 5 deletions src/components/compose.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import './compose.css';
import '@github/text-expander-element';

import { msg, plural } from '@lingui/core/macro';
import { msg, plural, t } from '@lingui/core/macro';
import { Trans, useLingui } from '@lingui/react/macro';
import { MenuItem } from '@szhsin/react-menu';
import { deepEqual } from 'fast-equals';
Expand Down Expand Up @@ -46,7 +46,6 @@ import store from '../utils/store';
import {
getCurrentAccount,
getCurrentAccountNS,
getCurrentInstance,
getCurrentInstanceConfiguration,
} from '../utils/store-utils';
import supports from '../utils/supports';
Expand Down Expand Up @@ -75,6 +74,14 @@ const supportedLanguagesMap = supportedLanguages.reduce((acc, l) => {
return acc;
}, {});

const contentTypesMap = {
'text/plain': { icon: 'font', text: t`Plain text` },
'text/html': { icon: 'brackets-angle', text: t`HTML` },
'text/markdown': { icon: 'asterisk', text: t`Markdown` },
'text/bbcode': { icon: 'brackets', text: t`BBCode` },
'text/x.misskeymarkdown': { icon: 'currency-dollar-2', text: t`MFM` },
};

/* NOTES:
- Max character limit includes BOTH status text and Content Warning text
*/
Expand Down Expand Up @@ -235,12 +242,13 @@ function Compose({

const {
statuses: {
supportedMimeTypes: supportedStatusMimeTypes = ['text/plain'],
maxCharacters,
maxMediaAttachments, // Beware: it can be undefined!
charactersReservedPerUrl,
} = {},
mediaAttachments: {
supportedMimeTypes,
supportedMimeTypes: supportedMediaMimeTypes = undefined,
imageSizeLimit,
imageMatrixLimit,
videoSizeLimit,
Expand All @@ -255,9 +263,12 @@ function Compose({
} = {},
} = configuration || {};

const defaultContentType = supportedStatusMimeTypes[0];

const textareaRef = useRef();
const spoilerTextRef = useRef();
const [visibility, setVisibility] = useState('public');
const [contentType, setContentType] = useState(defaultContentType);
const [sensitive, setSensitive] = useState(false);
const [language, setLanguage] = useState(
store.session.get('currentLanguage') || DEFAULT_LANG,
Expand Down Expand Up @@ -1123,9 +1134,16 @@ function Compose({
);
} else if (!editStatus) {
params.visibility = visibility;
if (params.visibility === 'list') {
const list_id = prompt('Target list ID?');
params.visibility = `list:${list_id}`;
}
// params.inReplyToId = replyToStatus?.id || undefined;
params.in_reply_to_id = replyToStatus?.id || undefined;
}
if (supportedStatusMimeTypes.length > 1) {
params.content_type = contentType;
}
params = removeNullUndefined(params);
console.log('POST', params);

Expand Down Expand Up @@ -1212,6 +1230,37 @@ function Compose({
/>
<Icon icon={`eye-${sensitive ? 'close' : 'open'}`} />
</label>{' '}
{supportedStatusMimeTypes.length > 1 && (
<>
<label
class={`toolbar-button ${
contentType !== defaultContentType && !sensitive
? 'show-field'
: ''
} ${contentType !== defaultContentType ? 'highlight' : ''}`}
>
<Icon
icon={contentTypesMap[contentType].icon ?? 'asterisk'}
alt={visibility}
/>
<select
name={'contentType'}
value={contentType}
onChange={(e) => {
setContentType(e.target.value);
}}
disabled={uiState === 'loading'}
dir={'auto'}
>
{supportedStatusMimeTypes.map((mime) => (
<option value={mime}>
{contentTypesMap[mime].text ?? mime}
</option>
))}
</select>
</label>{' '}
</>
)}
<label
class={`toolbar-button ${
visibility !== 'public' && !sensitive ? 'show-field' : ''
Expand Down Expand Up @@ -1243,6 +1292,12 @@ function Compose({
<option value="private">
<Trans>Followers only</Trans>
</option>
{(supports('@pleroma/list-visibility-post') ||
supports('@akkoma/list-visibility-post')) && (
<option value="list">
<Trans>List only</Trans>
</option>
)}
<option value="direct">
<Trans>Private mention</Trans>
</option>
Expand Down Expand Up @@ -1386,7 +1441,7 @@ function Compose({
<label class="compose-menu-add-media-field">
<FilePickerInput
hidden
supportedMimeTypes={supportedMimeTypes}
supportedMimeTypes={supportedMediaMimeTypes}
maxMediaAttachments={maxMediaAttachments}
mediaAttachments={mediaAttachments}
disabled={
Expand Down Expand Up @@ -1429,7 +1484,7 @@ function Compose({
<span class="add-sub-toolbar-button-group" ref={addSubToolbarRef}>
<label class="toolbar-button">
<FilePickerInput
supportedMimeTypes={supportedMimeTypes}
supportedMimeTypes={supportedMediaMimeTypes}
maxMediaAttachments={maxMediaAttachments}
mediaAttachments={mediaAttachments}
disabled={
Expand Down
4 changes: 3 additions & 1 deletion src/utils/supports.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ function supports(feature) {
}

const key = `${domain}-${feature}`;
if (supportsCache[key]) return supportsCache[key];
if (supportsCache[key]) {
return supportsCache[key];
}

if (platformFeatures[feature]) {
return (supportsCache[key] = platformFeatures[feature].test(version));
Expand Down