From 2e7a735c0ca2253b6340a2ef5f0d27846ef67f99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Wed, 9 Oct 2024 22:23:51 +0200 Subject: [PATCH] pl-fe: Prefer useRelationship hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- .../features/chats/components/chat-composer.tsx | 14 +++++++------- .../features/chats/components/chat-list-item.tsx | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/pl-fe/src/features/chats/components/chat-composer.tsx b/packages/pl-fe/src/features/chats/components/chat-composer.tsx index 354dedcbf..06b8b7b88 100644 --- a/packages/pl-fe/src/features/chats/components/chat-composer.tsx +++ b/packages/pl-fe/src/features/chats/components/chat-composer.tsx @@ -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 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(initialSuggestionState); diff --git a/packages/pl-fe/src/features/chats/components/chat-list-item.tsx b/packages/pl-fe/src/features/chats/components/chat-list-item.tsx index 276bf7ad7..84d41c0e8 100644 --- a/packages/pl-fe/src/features/chats/components/chat-list-item.tsx +++ b/packages/pl-fe/src/features/chats/components/chat-list-item.tsx @@ -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 = ({ 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),