From 0003b7323a095bde918b2b7d6a6d2aded52e3b85 Mon Sep 17 00:00:00 2001 From: Justin Date: Fri, 23 Sep 2022 09:48:52 -0400 Subject: [PATCH] Fix errant fetches to the silence endpoint --- .../components/chat-page/components/chat-page-main.tsx | 10 ++++++++-- .../features/chats/components/chat-settings.tsx | 10 ++++++++-- app/soapbox/queries/chats.ts | 10 ++-------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/soapbox/features/chats/components/chat-page/components/chat-page-main.tsx b/app/soapbox/features/chats/components/chat-page/components/chat-page-main.tsx index c743baa262..6b6ba786d7 100644 --- a/app/soapbox/features/chats/components/chat-page/components/chat-page-main.tsx +++ b/app/soapbox/features/chats/components/chat-page/components/chat-page-main.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { blockAccount } from 'soapbox/actions/accounts'; @@ -33,7 +33,7 @@ const ChatPageMain = () => { const account = useOwnAccount(); const { chat, setChat } = useChatContext(); - const { isSilenced, handleSilence } = useChatSilence(chat); + const { isSilenced, handleSilence, fetchChatSilence } = useChatSilence(chat); const { deleteChat } = useChat(chat?.id as string); const handleBlockUser = () => { @@ -58,6 +58,12 @@ const ChatPageMain = () => { const handleReportChat = () => dispatch(initReport(chat?.account as any)); + useEffect(() => { + if (chat?.id) { + fetchChatSilence(); + } + }, [chat?.id]); + if (!chat && !account?.chats_onboarded) { return ( diff --git a/app/soapbox/features/chats/components/chat-settings.tsx b/app/soapbox/features/chats/components/chat-settings.tsx index 870b08ba2c..fe10f2ab64 100644 --- a/app/soapbox/features/chats/components/chat-settings.tsx +++ b/app/soapbox/features/chats/components/chat-settings.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { blockAccount } from 'soapbox/actions/accounts'; @@ -30,7 +30,7 @@ const ChatSettings = () => { const intl = useIntl(); const { chat, setEditing, toggleChatPane } = useChatContext(); - const { isSilenced, handleSilence } = useChatSilence(chat); + const { isSilenced, handleSilence, fetchChatSilence } = useChatSilence(chat); const { deleteChat } = useChat(chat?.id as string); @@ -63,6 +63,12 @@ const ChatSettings = () => { const handleReportChat = () => dispatch(initReport(chat?.account as any)); + useEffect(() => { + if (chat?.id) { + fetchChatSilence(); + } + }, [chat?.id]); + if (!chat) { return null; } diff --git a/app/soapbox/queries/chats.ts b/app/soapbox/queries/chats.ts index 495628ed16..eccb1c896d 100644 --- a/app/soapbox/queries/chats.ts +++ b/app/soapbox/queries/chats.ts @@ -1,5 +1,5 @@ import { useInfiniteQuery, useMutation, useQuery } from '@tanstack/react-query'; -import { useEffect, useState } from 'react'; +import { useState } from 'react'; import { fetchRelationships } from 'soapbox/actions/accounts'; import snackbar from 'soapbox/actions/snackbar'; @@ -255,13 +255,7 @@ const useChatSilence = (chat: IChat | null) => { }); }; - useEffect(() => { - if (chat?.id) { - fetchChatSilence(); - } - }, [chat?.id]); - - return { isSilenced, handleSilence }; + return { isSilenced, handleSilence, fetchChatSilence }; }; export { useChat, useChats, useChatMessages, useChatSilences, useChatSilence };