|
|
|
@@ -12,7 +12,6 @@ import { useSelector } from "react-redux"; |
|
|
|
import OfferCard from "../../Cards/OfferCard/OfferCard"; |
|
|
|
import { selectProfileOffers } from "../../../store/selectors/offersSelectors"; |
|
|
|
import { selectLatestChats } from "../../../store/selectors/chatSelectors"; |
|
|
|
import { useHistory } from "react-router-dom"; |
|
|
|
import { selectUserId } from "../../../store/selectors/loginSelectors"; |
|
|
|
import NoProfileOffers from "./NoProfileOffers.js/NoProfileOffers"; |
|
|
|
import { selectIsLoadingByActionType } from "../../../store/selectors/loadingSelectors"; |
|
|
|
@@ -23,8 +22,7 @@ import ProfileOffersHeaderSkeleton from "./ProfileOffersHeaderSkeleton/ProfileOf |
|
|
|
import SelectSortField from "./SelectSortField/SelectSortField"; |
|
|
|
import HeaderTitle from "./HeaderTitle/HeaderTitle"; |
|
|
|
import SearchBar from "./SearchBar/SearchBar"; |
|
|
|
import { replaceInRoute } from "../../../util/helpers/routeHelpers"; |
|
|
|
import { CHAT_MESSAGE_PAGE } from "../../../constants/pages"; |
|
|
|
import { messageUserHelper } from "../../../util/helpers/messageHelper"; |
|
|
|
|
|
|
|
const ProfileOffers = (props) => { |
|
|
|
const [offersToShow, setOffersToShow] = useState([]); |
|
|
|
@@ -34,28 +32,11 @@ const ProfileOffers = (props) => { |
|
|
|
const chats = useSelector(selectLatestChats); |
|
|
|
const profileOffers = useSelector(selectProfileOffers); |
|
|
|
const { isMobile } = useIsMobile(); |
|
|
|
const history = useHistory(); |
|
|
|
const userId = useSelector(selectUserId); |
|
|
|
const arrayForMapping = Array.apply(null, Array(4)).map(() => {}); |
|
|
|
|
|
|
|
const messageUser = (offer) => { |
|
|
|
const chatItem = chats.find( |
|
|
|
(item) => item.chat.offerId === offer?.offer?._id |
|
|
|
); |
|
|
|
if (chatItem !== undefined) { |
|
|
|
history.push( |
|
|
|
replaceInRoute(CHAT_MESSAGE_PAGE, { idChat: chatItem.chat._id }) |
|
|
|
); |
|
|
|
} else { |
|
|
|
if (offer?.offer?.userId !== userId) { |
|
|
|
history.push( |
|
|
|
replaceInRoute(CHAT_MESSAGE_PAGE, { idChat: "newMessage" }), |
|
|
|
{ |
|
|
|
offerId: offer?.offer?._id, |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
messageUserHelper(chats, offer, userId); |
|
|
|
}; |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
@@ -72,32 +53,32 @@ const ProfileOffers = (props) => { |
|
|
|
return ( |
|
|
|
<ProfileOffersContainer isAdmin={props.isAdmin}> |
|
|
|
{isLoadingMineOffers || isLoadingMineOffers === undefined ? ( |
|
|
|
<ProfileOffersHeaderSkeleton /> |
|
|
|
) : ( |
|
|
|
<> |
|
|
|
<ProfileOffersHeaderSkeleton /> |
|
|
|
{isMobile ? ( |
|
|
|
<SkeletonContainer> |
|
|
|
<SkeletonOfferCard vertical /> |
|
|
|
<SkeletonOfferCard vertical /> |
|
|
|
<SkeletonOfferCard vertical /> |
|
|
|
</SkeletonContainer> |
|
|
|
) : ( |
|
|
|
<> |
|
|
|
{arrayForMapping.map((item, index) => ( |
|
|
|
<SkeletonOfferCard key={index} /> |
|
|
|
))} |
|
|
|
</> |
|
|
|
)} |
|
|
|
</> |
|
|
|
) : ( |
|
|
|
<OffersContainer> |
|
|
|
<SelectSortField |
|
|
|
offersToShow={offersToShow} |
|
|
|
setOffersToShow={setOffersToShow} |
|
|
|
/> |
|
|
|
<HeaderTitle isMyProfile={props.isMyProfile && !props.isAdmin} /> |
|
|
|
<SearchBar handleSearch={handleSearch} /> |
|
|
|
</> |
|
|
|
)} |
|
|
|
|
|
|
|
{isLoadingMineOffers || isLoadingMineOffers === undefined ? ( |
|
|
|
<SkeletonContainer> |
|
|
|
<SkeletonOfferCard vertical /> |
|
|
|
<SkeletonOfferCard vertical /> |
|
|
|
<SkeletonOfferCard vertical /> |
|
|
|
</SkeletonContainer> |
|
|
|
) : ( |
|
|
|
<OffersContainer> |
|
|
|
{!isMobile ? ( |
|
|
|
isLoadingMineOffers || isLoadingMineOffers === undefined ? ( |
|
|
|
arrayForMapping.map((item, index) => ( |
|
|
|
<SkeletonOfferCard key={index} /> |
|
|
|
)) |
|
|
|
) : offersToShow.length !== 0 ? ( |
|
|
|
offersToShow.length !== 0 ? ( |
|
|
|
offersToShow.map((item) => ( |
|
|
|
<OfferCard |
|
|
|
isAdmin={props.isAdmin} |