pl-fe: Prefer useRelationship hook

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-10-09 22:23:51 +02:00
parent 13454a38d6
commit 2e7a735c0c
2 changed files with 14 additions and 14 deletions

View file

@ -2,18 +2,18 @@ import React, { useState } from 'react';
import { defineMessages, IntlShape, useIntl } from 'react-intl';
import { unblockAccount } from 'pl-fe/actions/accounts';
import { useRelationship } from 'pl-fe/api/hooks/accounts/useRelationship';
import { Button, Combobox, ComboboxInput, ComboboxList, ComboboxOption, ComboboxPopover, HStack, IconButton, Stack, Text } from 'pl-fe/components/ui';
import { useChatContext } from 'pl-fe/contexts/chat-context';
import { Entities } from 'pl-fe/entity-store/entities';
import UploadButton from 'pl-fe/features/compose/components/upload-button';
import emojiSearch from 'pl-fe/features/emoji/search';
import { useAppDispatch, useAppSelector, useInstance } from 'pl-fe/hooks';
import { useAppDispatch, useInstance } from 'pl-fe/hooks';
import { useModalsStore } from 'pl-fe/stores';
import { textAtCursorMatchesToken } from 'pl-fe/utils/suggestions';
import ChatTextarea from './chat-textarea';
import type { MediaAttachment, Relationship } from 'pl-api';
import type { MediaAttachment } from 'pl-api';
import type { Emoji, NativeEmoji } from 'pl-fe/features/emoji';
const messages = defineMessages({
@ -74,11 +74,11 @@ const ChatComposer = React.forwardRef<HTMLTextAreaElement | null, IChatComposer>
const { openModal } = useModalsStore();
const { chat } = useChatContext();
const { relationship } = useRelationship(chat?.account.id, { enabled: !!chat });
const isBlocked = relationship?.blocked_by && false;
const isBlocking = relationship?.blocking && false;
const {
blocked_by: isBlocked,
blocking: isBlocking,
} = useAppSelector((state) => (chat?.account?.id && (state.entities[Entities.RELATIONSHIPS]?.store[chat.account.id]) || {}) as Relationship);
const maxCharacterCount = useInstance().configuration.chats.max_characters;
const [suggestions, setSuggestions] = useState<Suggestion>(initialSuggestionState);

View file

@ -2,17 +2,17 @@ import React, { useMemo } from 'react';
import { defineMessages, useIntl } from 'react-intl';
import { useHistory } from 'react-router-dom';
import { useRelationship } from 'pl-fe/api/hooks/accounts/useRelationship';
import DropdownMenu from 'pl-fe/components/dropdown-menu';
import RelativeTimestamp from 'pl-fe/components/relative-timestamp';
import { Avatar, HStack, IconButton, Stack, Text } from 'pl-fe/components/ui';
import VerificationBadge from 'pl-fe/components/verification-badge';
import { useChatContext } from 'pl-fe/contexts/chat-context';
import { Entities } from 'pl-fe/entity-store/entities';
import { useAppSelector, useFeatures } from 'pl-fe/hooks';
import { useFeatures } from 'pl-fe/hooks';
import { useChatActions } from 'pl-fe/queries/chats';
import { useModalsStore } from 'pl-fe/stores';
import type { Chat, Relationship } from 'pl-api';
import type { Chat } from 'pl-api';
import type { Menu } from 'pl-fe/components/dropdown-menu';
const messages = defineMessages({
@ -37,10 +37,10 @@ const ChatListItem: React.FC<IChatListItemInterface> = ({ chat, onClick }) => {
const { isUsingMainChatPage } = useChatContext();
const { deleteChat } = useChatActions(chat?.id as string);
const {
blocked_by: isBlocked,
blocking: isBlocking,
} = useAppSelector((state) => (state.entities[Entities.RELATIONSHIPS]?.store[chat.account.id] as Relationship) || {});
const { relationship } = useRelationship(chat?.account.id, { enabled: !!chat });
const isBlocked = relationship?.blocked_by && false;
const isBlocking = relationship?.blocking && false;
const menu = useMemo((): Menu => [{
text: intl.formatMessage(messages.leaveChat),