mirror of
https://github.com/mastodon/mastodon.git
synced 2026-10-20 12:43:14 -05:00
Composer redesign: Fix counter and publish check mismatch (#40872)
This commit is contained in:
@@ -64,7 +64,7 @@ export const selectComposeCharsCount = createAppSelector(
|
||||
: '',
|
||||
],
|
||||
(maxChars, text, spoilerText) => {
|
||||
const allText = (countableText(text) as string) + spoilerText;
|
||||
const allText = countableText(text) + spoilerText;
|
||||
return {
|
||||
text,
|
||||
allText,
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import { urlRegex } from './url_regex';
|
||||
|
||||
const urlPlaceholder = '$2xxxxxxxxxxxxxxxxxxxxxxx';
|
||||
|
||||
export function countableText(inputText) {
|
||||
return inputText
|
||||
.replace(urlRegex, urlPlaceholder)
|
||||
.replace(/(^|[^/\w])@(([a-z0-9_]+)@[a-z0-9.-]+[a-z0-9]+)/ig, '$1@$3');
|
||||
}
|
||||
9
app/javascript/mastodon/features/compose/util/counter.ts
Normal file
9
app/javascript/mastodon/features/compose/util/counter.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { urlRegex } from './url_regex';
|
||||
|
||||
const urlPlaceholder = '$2xxxxxxxxxxxxxxxxxxxxxxx';
|
||||
|
||||
export function countableText(inputText: string) {
|
||||
return inputText
|
||||
.replace(urlRegex as RegExp, urlPlaceholder)
|
||||
.replace(/(^|[^/\w])@(([a-z0-9_]+)@[a-z0-9.-]+[a-z0-9]+)/gi, '$1@$3');
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import type {
|
||||
ApiStatusJSON,
|
||||
StatusVisibility,
|
||||
} from '@/mastodon/api_types/statuses';
|
||||
import { countableText } from '@/mastodon/features/compose/util/counter';
|
||||
import {
|
||||
createAppSelector,
|
||||
createAppThunk,
|
||||
@@ -269,7 +270,12 @@ export const submitComposer = createAppThunk(
|
||||
|
||||
const maxChars =
|
||||
server.server.item?.configuration.statuses.max_characters ?? 500;
|
||||
const textLength = length(compose.get('text') as string);
|
||||
let text = compose.get('text') as string;
|
||||
const spoilerText = compose.get('spoiler_text');
|
||||
if (compose.get('spoiler') && typeof spoilerText === 'string') {
|
||||
text += spoilerText;
|
||||
}
|
||||
const textLength = length(countableText(text));
|
||||
if (textLength === 0) {
|
||||
dispatch(composerSlice.actions.addError('empty'));
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user