| import React, { useEffect, useMemo } from "react"; | |||||
| import React, { useEffect, useMemo, useState } from "react"; | |||||
| import PropTypes from "prop-types"; | import PropTypes from "prop-types"; | ||||
| import { | import { | ||||
| ChatPagingText, | ChatPagingText, | ||||
| selectLatestChats, | selectLatestChats, | ||||
| selectSelectedChat, | selectSelectedChat, | ||||
| } from "../../../store/selectors/chatSelectors"; | } from "../../../store/selectors/chatSelectors"; | ||||
| import { fetchChats } from "../../../store/actions/chat/chatActions"; | |||||
| import { fetchChats, setOneChat } from "../../../store/actions/chat/chatActions"; | |||||
| import MiniChatColumnHeader from "./MiniChatColumnHeader/MiniChatColumnHeaderTitle"; | import MiniChatColumnHeader from "./MiniChatColumnHeader/MiniChatColumnHeaderTitle"; | ||||
| import { useLocation } from "react-router-dom"; | import { useLocation } from "react-router-dom"; | ||||
| import { selectOffer } from "../../../store/selectors/offersSelectors"; | import { selectOffer } from "../../../store/selectors/offersSelectors"; | ||||
| const offer = useSelector(selectOffer); | const offer = useSelector(selectOffer); | ||||
| const location = useLocation(); | const location = useLocation(); | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const [changedPage, setChangedPage] = useState(false); | |||||
| const paging = usePaging(); | const paging = usePaging(); | ||||
| const isLoadingMiniChat = useSelector( | const isLoadingMiniChat = useSelector( | ||||
| selectIsLoadingByActionType(CHAT_SCOPE) | selectIsLoadingByActionType(CHAT_SCOPE) | ||||
| return {}; | return {}; | ||||
| }, [offer, location.state]); | }, [offer, location.state]); | ||||
| useEffect(() => { | |||||
| if (changedPage && !isLoadingMiniChat) { | |||||
| dispatch(setOneChat(chats[0])) | |||||
| } | |||||
| }, [changedPage, isLoadingMiniChat]) | |||||
| useEffect(() => { | useEffect(() => { | ||||
| dispatch( | dispatch( | ||||
| fetchChats({ | fetchChats({ | ||||
| }) | }) | ||||
| ); | ); | ||||
| }, [paging.currentPage]); | }, [paging.currentPage]); | ||||
| const handleChangePage = (newPage) => paging.changePage(newPage); | |||||
| const handleChangePage = (newPage) => { | |||||
| setChangedPage(true); | |||||
| paging.changePage(newPage); | |||||
| }; | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| {isLoadingMiniChat || isLoadingMiniChat === undefined ? ( | {isLoadingMiniChat || isLoadingMiniChat === undefined ? ( |