Arrow functions and so

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2024-05-13 01:18:04 +02:00
parent 615ec68931
commit a58c52631e
352 changed files with 2894 additions and 3693 deletions

View File

@ -17,23 +17,21 @@ const ComposeFormButton: React.FC<IComposeFormButton> = ({
active,
disabled,
onClick,
}) => {
return (
<div>
<IconButton
className={
clsx({
'text-gray-600 hover:text-gray-700 dark:hover:text-gray-500': !active,
'text-primary-500 hover:text-primary-600 dark:text-primary-500 dark:hover:text-primary-400': active,
})
}
src={icon}
title={title}
disabled={disabled}
onClick={onClick}
/>
</div>
);
};
}) => (
<div>
<IconButton
className={
clsx({
'text-gray-600 hover:text-gray-700 dark:hover:text-gray-500': !active,
'text-primary-500 hover:text-primary-600 dark:text-primary-500 dark:hover:text-primary-400': active,
})
}
src={icon}
title={title}
disabled={disabled}
onClick={onClick}
/>
</div>
);
export default ComposeFormButton;

View File

@ -110,20 +110,16 @@ const ComposeForm = <ID extends string>({ id, shouldCondense, autoFocus, clickab
const shouldAutoFocus = autoFocus && !showSearch;
const canSubmit = !!editorRef.current && !isSubmitting && !isUploading && !isChangingUpload && !isEmpty && length(fulltext) <= maxTootChars;
const getClickableArea = () => {
return clickableAreaRef ? clickableAreaRef.current : formRef.current;
};
const getClickableArea = () => clickableAreaRef ? clickableAreaRef.current : formRef.current;
const isClickOutside = (e: MouseEvent | React.MouseEvent) => {
return ![
// List of elements that shouldn't collapse the composer when clicked
// FIXME: Make this less brittle
getClickableArea(),
document.getElementById('privacy-dropdown'),
document.querySelector('em-emoji-picker'),
document.getElementById('modal-overlay'),
].some(element => element?.contains(e.target as any));
};
const isClickOutside = (e: MouseEvent | React.MouseEvent) => ![
// List of elements that shouldn't collapse the composer when clicked
// FIXME: Make this less brittle
getClickableArea(),
document.getElementById('privacy-dropdown'),
document.querySelector('em-emoji-picker'),
document.getElementById('modal-overlay'),
].some(element => element?.contains(e.target as any));
const handleClick = useCallback((e: MouseEvent | React.MouseEvent) => {
if (isEmpty && isClickOutside(e)) {

View File

@ -8,9 +8,8 @@ import { HStack, Input, Stack, Text } from 'soapbox/components/ui';
import { DatePicker } from 'soapbox/features/ui/util/async-components';
import { useAppDispatch, useCompose } from 'soapbox/hooks';
export const isCurrentOrFutureDate = (date: Date) => {
return date && new Date().setHours(0, 0, 0, 0) <= new Date(date).setHours(0, 0, 0, 0);
};
export const isCurrentOrFutureDate = (date: Date) =>
date && new Date().setHours(0, 0, 0, 0) <= new Date(date).setHours(0, 0, 0, 0);
const isFiveMinutesFromNow = (time: Date) => {
const fiveMinutesFromNow = new Date(new Date().getTime() + 300000); // now, plus five minutes (Pleroma won't schedule posts )

View File

@ -74,9 +74,7 @@ const SearchResults = () => {
return <Tabs items={items} activeItem={selectedFilter} />;
};
const getCurrentIndex = (id: string): number => {
return resultsIds?.keySeq().findIndex(key => key === id);
};
const getCurrentIndex = (id: string): number => resultsIds?.keySeq().findIndex(key => key === id);
const handleMoveUp = (id: string) => {
if (!resultsIds) return;

View File

@ -24,15 +24,14 @@ const messages = defineMessages({
action: { id: 'search.action', defaultMessage: 'Search for “{query}”' },
});
function redirectToAccount(accountId: string, routerHistory: any) {
return (_dispatch: AppDispatch, getState: () => RootState) => {
const redirectToAccount = (accountId: string, routerHistory: any) =>
(_dispatch: AppDispatch, getState: () => RootState) => {
const acct = selectAccount(getState(), accountId)!.acct;
if (acct && routerHistory) {
routerHistory.push(`/@${acct}`);
}
};
}
interface ISearch {
autoFocus?: boolean;
@ -136,16 +135,14 @@ const Search = (props: ISearch) => {
componentProps.autoSelect = false;
}
useEffect(() => {
return () => {
const newPath = history.location.pathname;
const shouldPersistSearch = !!newPath.match(/@.+\/posts\/[a-zA-Z0-9]+/g)
useEffect(() => () => {
const newPath = history.location.pathname;
const shouldPersistSearch = !!newPath.match(/@.+\/posts\/[a-zA-Z0-9]+/g)
|| !!newPath.match(/\/tags\/.+/g);
if (!shouldPersistSearch) {
dispatch(changeSearch(''));
}
};
if (!shouldPersistSearch) {
dispatch(changeSearch(''));
}
}, []);
return (

View File

@ -8,18 +8,16 @@ interface ITextCharacterCounter {
}
const TextCharacterCounter: React.FC<ITextCharacterCounter> = ({ text, max }) => {
const checkRemainingText = (diff: number) => {
return (
<span
className={clsx('text-sm font-medium', {
'text-gray-700': diff >= 0,
'text-secondary-600': diff < 0,
})}
>
{diff}
</span>
);
};
const checkRemainingText = (diff: number) => (
<span
className={clsx('text-sm font-medium', {
'text-gray-700': diff >= 0,
'text-secondary-600': diff < 0,
})}
>
{diff}
</span>
);
const diff = max - length(text);
return checkRemainingText(diff);

View File

@ -8,9 +8,8 @@ const messages = defineMessages({
upload: { id: 'upload_button.label', defaultMessage: 'Add media attachment' },
});
export const onlyImages = (types: string[] | undefined): boolean => {
return types?.every((type) => type.startsWith('image/')) ?? false;
};
export const onlyImages = (types: string[] | undefined): boolean =>
types?.every((type) => type.startsWith('image/')) ?? false;
export interface IUploadButton {
disabled?: boolean;

View File

@ -311,13 +311,13 @@ const AutosuggestPlugin = ({
const offset = leadOffset - 1;
/** Replace the matched text with the given node. */
function replaceMatch(replaceWith: LexicalNode) {
const replaceMatch = (replaceWith: LexicalNode) => {
const result = (node as TextNode).splitText(offset, offset + matchingString.length);
const textNode = result[1] ?? result[0];
const replacedNode = textNode.replace(replaceWith);
replacedNode.insertAfter(new TextNode(' '));
replacedNode.selectNext();
}
};
if (typeof suggestion === 'object') {
if (!suggestion.id) return;

View File

@ -18,8 +18,6 @@ export const validateUrl = (url: string): boolean => {
return url === 'https://' || urlRegExp.test(url);
};
const LinkPlugin = (): JSX.Element => {
return <LexicalLinkPlugin validateUrl={validateUrl} />;
};
const LinkPlugin = (): JSX.Element => <LexicalLinkPlugin validateUrl={validateUrl} />;
export default LinkPlugin;

View File

@ -2,8 +2,7 @@ import { urlRegex } from './url-regex';
const urlPlaceholder = 'xxxxxxxxxxxxxxxxxxxxxxx';
export function countableText(inputText: string) {
return inputText
export const countableText = (inputText: string) =>
inputText
.replace(urlRegex, urlPlaceholder)
.replace(/(^|[^/\w])@(([a-z0-9_]+)@[a-z0-9.-]+[a-z0-9]+)/ig, '$1@$3');
}