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

View file

@ -333,7 +333,9 @@ const ChatMessageList: React.FC<IChatMessageList> = ({ chat, autosize }) => {
// Stick scrollbar to bottom. // Stick scrollbar to bottom.
useEffect(() => { useEffect(() => {
if (isNearBottom()) { if (isNearBottom()) {
setTimeout(() => {
scrollToBottom(); scrollToBottom();
}, 25);
} }
// First load. // First load.
@ -348,10 +350,6 @@ const ChatMessageList: React.FC<IChatMessageList> = ({ chat, autosize }) => {
markChatAsRead(); markChatAsRead();
}, [formattedChatMessages.length]); }, [formattedChatMessages.length]);
// useEffect(() => {
// scrollToBottom();
// }, [messagesEnd.current]);
useEffect(() => { useEffect(() => {
// Restore scroll bar position when loading old messages. // Restore scroll bar position when loading old messages.
if (!initialLoad) { 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 { Avatar, Divider, HStack, Icon, Stack, Text, Toggle } from 'soapbox/components/ui';
import { useChatContext } from 'soapbox/contexts/chat-context'; import { useChatContext } from 'soapbox/contexts/chat-context';
import { useAppDispatch } from 'soapbox/hooks'; 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'; import ChatPaneHeader from './chat-pane-header';
const ChatSettings = () => { const ChatSettings = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { isSnoozed, handleSnooze } = useChatSnoozes(); const { isSilenced, handleSilence } = useChatSilences();
const { chat, setEditing, toggleChatPane } = useChatContext(); const { chat, setEditing, toggleChatPane } = useChatContext();
const { deleteChat } = useChat(chat?.id as string); const { deleteChat } = useChat(chat?.id as string);
@ -89,8 +89,8 @@ const ChatSettings = () => {
<Divider /> <Divider />
<List> <List>
<ListItem label='Snooze notifications'> <ListItem label='Silence notifications'>
<Toggle checked={isSnoozed} onChange={handleSnooze} /> <Toggle checked={isSilenced} onChange={handleSilence} />
</ListItem> </ListItem>
</List> </List>

View file

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

View file

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