Rename snooze endpoint

This commit is contained in:
Justin 2022-08-29 15:05:16 -04:00
parent cfa183531e
commit 2a02f6dcc7
5 changed files with 35 additions and 44 deletions

View file

@ -27,7 +27,7 @@ const ChatList: React.FC<IChatList> = ({ onClickChat, useWindowScroll = false })
const [isNearBottom, setNearBottom] = useState<boolean>(false);
const [isNearTop, setNearTop] = useState<boolean>(true);
const isEmpty = chats?.length === 0;
const isEmpty = (!chats || chats.length === 0);
const handleLoadMore = () => {
if (hasNextPage && !isFetching) {
@ -64,9 +64,7 @@ const ChatList: React.FC<IChatList> = ({ onClickChat, useWindowScroll = false })
useWindowScroll={useWindowScroll}
data={chats}
endReached={handleLoadMore}
itemContent={(_index, chat) => (
<Chat chat={chat} onClick={onClickChat} />
)}
itemContent={(_index, chat) => <Chat chat={chat} onClick={onClickChat} />}
components={{
ScrollSeekPlaceholder: () => <PlaceholderChat />,
// Footer: () => hasNextPage ? <Spinner withText={false} /> : null,

View file

@ -333,7 +333,9 @@ const ChatMessageList: React.FC<IChatMessageList> = ({ chat, autosize }) => {
// Stick scrollbar to bottom.
useEffect(() => {
if (isNearBottom()) {
setTimeout(() => {
scrollToBottom();
}, 25);
}
// First load.
@ -348,10 +350,6 @@ const ChatMessageList: React.FC<IChatMessageList> = ({ chat, autosize }) => {
markChatAsRead();
}, [formattedChatMessages.length]);
// useEffect(() => {
// scrollToBottom();
// }, [messagesEnd.current]);
useEffect(() => {
// Restore scroll bar position when loading old messages.
if (!initialLoad) {

View file

@ -7,13 +7,13 @@ import List, { ListItem } from 'soapbox/components/list';
import { Avatar, Divider, HStack, Icon, Stack, Text, Toggle } from 'soapbox/components/ui';
import { useChatContext } from 'soapbox/contexts/chat-context';
import { useAppDispatch } from 'soapbox/hooks';
import { useChat, useChatSnoozes } from 'soapbox/queries/chats';
import { useChat, useChatSilences } from 'soapbox/queries/chats';
import ChatPaneHeader from './chat-pane-header';
const ChatSettings = () => {
const dispatch = useAppDispatch();
const { isSnoozed, handleSnooze } = useChatSnoozes();
const { isSilenced, handleSilence } = useChatSilences();
const { chat, setEditing, toggleChatPane } = useChatContext();
const { deleteChat } = useChat(chat?.id as string);
@ -89,8 +89,8 @@ const ChatSettings = () => {
<Divider />
<List>
<ListItem label='Snooze notifications'>
<Toggle checked={isSnoozed} onChange={handleSnooze} />
<ListItem label='Silence notifications'>
<Toggle checked={isSilenced} onChange={handleSilence} />
</ListItem>
</List>

View file

@ -12,11 +12,6 @@ interface IChatInterface {
}
const Chat: React.FC<IChatInterface> = ({ chat, onClick }) => {
// Temporary: remove once bad Staging data is removed.
if (!chat.account) {
return null;
}
return (
<button
key={chat.id}

View file

@ -163,64 +163,64 @@ const useChat = (chatId: string) => {
return { createChatMessage, markChatAsRead, deleteChatMessage, acceptChat, deleteChat };
};
const useChatSnoozes = () => {
const useChatSilences = () => {
const api = useApi();
const dispatch = useAppDispatch();
const { chat } = useChatContext();
const [isSnoozed, setSnoozed] = useState<boolean>(false);
const [isSilenced, setSilenced] = useState<boolean>(false);
const getChatSnoozes = async() => {
const { data } = await api.get(`api/v1/pleroma/chats/snooze?account_id=${chat?.account.id}`);
const getChatSilences = async() => {
const { data } = await api.get(`api/v1/pleroma/chats/silence?account_id=${chat?.account.id}`);
return data;
};
const fetchChatSnooze = async() => {
const data = await getChatSnoozes();
const fetchChatSilence = async() => {
const data = await getChatSilences();
if (data) {
setSnoozed(true);
setSilenced(true);
}
};
const handleSnooze = () => {
if (isSnoozed) {
deleteSnooze();
const handleSilence = () => {
if (isSilenced) {
deleteSilence();
} else {
createSnooze();
createSilence();
}
};
const createSnooze = () => {
setSnoozed(true);
const createSilence = () => {
setSilenced(true);
api.post(`api/v1/pleroma/chats/snooze?account_id=${chat?.account.id}`)
api.post(`api/v1/pleroma/chats/silence?account_id=${chat?.account.id}`)
.then(() => {
dispatch(snackbar.success('Successfully snoozed this chat.'));
dispatch(snackbar.success('Successfully silenced this chat.'));
})
.catch(() => {
dispatch(snackbar.error('Something went wrong trying to snooze this chat. Please try again.'));
setSnoozed(false);
dispatch(snackbar.error('Something went wrong trying to silence this chat. Please try again.'));
setSilenced(false);
});
};
const deleteSnooze = () => {
setSnoozed(false);
const deleteSilence = () => {
setSilenced(false);
api.delete(`api/v1/pleroma/chats/snooze?account_id=${chat?.account.id}`)
api.delete(`api/v1/pleroma/chats/silence?account_id=${chat?.account.id}`)
.then(() => {
dispatch(snackbar.success('Successfully unsnoozed this chat.'));
dispatch(snackbar.success('Successfully unsilenced this chat.'));
})
.catch(() => {
dispatch(snackbar.error('Something went wrong trying to unsnooze this chat. Please try again.'));
setSnoozed(true);
dispatch(snackbar.error('Something went wrong trying to unsilence this chat. Please try again.'));
setSilenced(true);
});
};
useEffect(() => {
fetchChatSnooze();
fetchChatSilence();
}, []);
return { isSnoozed, handleSnooze };
return { isSilenced, handleSilence };
};
export { useChat, useChats, useChatMessages, useChatSnoozes };
export { useChat, useChats, useChatMessages, useChatSilences };