Fix errant fetches to the silence endpoint

This commit is contained in:
Justin 2022-09-23 09:48:52 -04:00
parent 641bf1268d
commit 0003b7323a
3 changed files with 18 additions and 12 deletions

View file

@ -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 (
<Welcome />

View file

@ -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;
}

View file

@ -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 };