pl-fe: optimize, maybe
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
6c0955f87c
commit
bff924891c
1 changed files with 11 additions and 7 deletions
|
@ -2,6 +2,7 @@ import { GroupRoles } from 'pl-api';
|
||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
||||||
import { useHistory, useRouteMatch } from 'react-router-dom';
|
import { useHistory, useRouteMatch } from 'react-router-dom';
|
||||||
|
import { createSelector } from 'reselect';
|
||||||
|
|
||||||
import { blockAccount } from 'pl-fe/actions/accounts';
|
import { blockAccount } from 'pl-fe/actions/accounts';
|
||||||
import { directCompose, mentionCompose, quoteCompose, replyCompose } from 'pl-fe/actions/compose';
|
import { directCompose, mentionCompose, quoteCompose, replyCompose } from 'pl-fe/actions/compose';
|
||||||
|
@ -31,6 +32,7 @@ import { useInstance } from 'pl-fe/hooks/use-instance';
|
||||||
import { useOwnAccount } from 'pl-fe/hooks/use-own-account';
|
import { useOwnAccount } from 'pl-fe/hooks/use-own-account';
|
||||||
import { useSettings } from 'pl-fe/hooks/use-settings';
|
import { useSettings } from 'pl-fe/hooks/use-settings';
|
||||||
import { useChats } from 'pl-fe/queries/chats';
|
import { useChats } from 'pl-fe/queries/chats';
|
||||||
|
import { RootState } from 'pl-fe/store';
|
||||||
import { useModalsStore } from 'pl-fe/stores/modals';
|
import { useModalsStore } from 'pl-fe/stores/modals';
|
||||||
import toast from 'pl-fe/toast';
|
import toast from 'pl-fe/toast';
|
||||||
import copy from 'pl-fe/utils/copy';
|
import copy from 'pl-fe/utils/copy';
|
||||||
|
@ -352,6 +354,11 @@ const DislikeButton: React.FC<IActionButton> = ({
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getLongerWrench = createSelector(
|
||||||
|
[(state: RootState) => state.custom_emojis],
|
||||||
|
(emojis) => emojis.find(({ shortcode }) => shortcode === 'longestest_wrench') || emojis.find(({ shortcode }) => shortcode === 'longest_wrench'),
|
||||||
|
);
|
||||||
|
|
||||||
const WrenchButton: React.FC<IActionButton> = ({
|
const WrenchButton: React.FC<IActionButton> = ({
|
||||||
status,
|
status,
|
||||||
statusActionButtonTheme,
|
statusActionButtonTheme,
|
||||||
|
@ -365,11 +372,7 @@ const WrenchButton: React.FC<IActionButton> = ({
|
||||||
const { openModal } = useModalsStore();
|
const { openModal } = useModalsStore();
|
||||||
const { showWrenchButton } = useSettings();
|
const { showWrenchButton } = useSettings();
|
||||||
|
|
||||||
const hasLongerWrench = useAppSelector(({ custom_emojis }) => {
|
const hasLongerWrench = useAppSelector(getLongerWrench);
|
||||||
if (!features.customEmojiReacts) return null;
|
|
||||||
|
|
||||||
return (custom_emojis.find(({ shortcode }) => shortcode === 'longestest_wrench') || custom_emojis.find(({ shortcode }) => shortcode === 'longest_wrench'));
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!me || withLabels || !features.emojiReacts || !showWrenchButton) return;
|
if (!me || withLabels || !features.emojiReacts || !showWrenchButton) return;
|
||||||
|
|
||||||
|
@ -384,8 +387,9 @@ const WrenchButton: React.FC<IActionButton> = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleWrenchLongPress = () => {
|
const handleWrenchLongPress = () => {
|
||||||
if (hasLongerWrench) dispatch(emojiReact(status, hasLongerWrench.shortcode, hasLongerWrench.url));
|
if (features.customEmojiReacts && hasLongerWrench) {
|
||||||
else if (wrenches?.count) {
|
dispatch(emojiReact(status, hasLongerWrench.shortcode, hasLongerWrench.url));
|
||||||
|
} else if (wrenches?.count) {
|
||||||
openModal('REACTIONS', { statusId: status.id, reaction: wrenches.name });
|
openModal('REACTIONS', { statusId: status.id, reaction: wrenches.name });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue