djordjemitrovic00 3 anni fa
parent
commit
26bd84b4f5

+ 1
- 0
src/components/Profile/ProfileOffers/NoProfileOffers.js/NoProfileOffers.styled.js Vedi File

display: flex; display: flex;
flex-direction: column; flex-direction: column;
border-radius: 4px; border-radius: 4px;
margin-top: 36px;
`; `;
export const NoProfileOffersIcon = styled(HalfLogo)` export const NoProfileOffersIcon = styled(HalfLogo)`
margin-top: 85px; margin-top: 85px;

+ 20
- 39
src/components/Profile/ProfileOffers/ProfileOffers.js Vedi File

import OfferCard from "../../Cards/OfferCard/OfferCard"; import OfferCard from "../../Cards/OfferCard/OfferCard";
import { selectProfileOffers } from "../../../store/selectors/offersSelectors"; import { selectProfileOffers } from "../../../store/selectors/offersSelectors";
import { selectLatestChats } from "../../../store/selectors/chatSelectors"; import { selectLatestChats } from "../../../store/selectors/chatSelectors";
import { useHistory } from "react-router-dom";
import { selectUserId } from "../../../store/selectors/loginSelectors"; import { selectUserId } from "../../../store/selectors/loginSelectors";
import NoProfileOffers from "./NoProfileOffers.js/NoProfileOffers"; import NoProfileOffers from "./NoProfileOffers.js/NoProfileOffers";
import { selectIsLoadingByActionType } from "../../../store/selectors/loadingSelectors"; import { selectIsLoadingByActionType } from "../../../store/selectors/loadingSelectors";
import SelectSortField from "./SelectSortField/SelectSortField"; import SelectSortField from "./SelectSortField/SelectSortField";
import HeaderTitle from "./HeaderTitle/HeaderTitle"; import HeaderTitle from "./HeaderTitle/HeaderTitle";
import SearchBar from "./SearchBar/SearchBar"; 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 ProfileOffers = (props) => {
const [offersToShow, setOffersToShow] = useState([]); const [offersToShow, setOffersToShow] = useState([]);
const chats = useSelector(selectLatestChats); const chats = useSelector(selectLatestChats);
const profileOffers = useSelector(selectProfileOffers); const profileOffers = useSelector(selectProfileOffers);
const { isMobile } = useIsMobile(); const { isMobile } = useIsMobile();
const history = useHistory();
const userId = useSelector(selectUserId); const userId = useSelector(selectUserId);
const arrayForMapping = Array.apply(null, Array(4)).map(() => {}); const arrayForMapping = Array.apply(null, Array(4)).map(() => {});


const messageUser = (offer) => { 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(() => { useEffect(() => {
return ( return (
<ProfileOffersContainer isAdmin={props.isAdmin}> <ProfileOffersContainer isAdmin={props.isAdmin}>
{isLoadingMineOffers || isLoadingMineOffers === undefined ? ( {isLoadingMineOffers || isLoadingMineOffers === undefined ? (
<ProfileOffersHeaderSkeleton />
) : (
<> <>
<ProfileOffersHeaderSkeleton />
{isMobile ? (
<SkeletonContainer>
<SkeletonOfferCard vertical />
<SkeletonOfferCard vertical />
<SkeletonOfferCard vertical />
</SkeletonContainer>
) : (
<>
{arrayForMapping.map((item, index) => (
<SkeletonOfferCard key={index} />
))}
</>
)}
</>
) : (
<OffersContainer>
<SelectSortField <SelectSortField
offersToShow={offersToShow} offersToShow={offersToShow}
setOffersToShow={setOffersToShow} setOffersToShow={setOffersToShow}
/> />
<HeaderTitle isMyProfile={props.isMyProfile && !props.isAdmin} /> <HeaderTitle isMyProfile={props.isMyProfile && !props.isAdmin} />
<SearchBar handleSearch={handleSearch} /> <SearchBar handleSearch={handleSearch} />
</>
)}

{isLoadingMineOffers || isLoadingMineOffers === undefined ? (
<SkeletonContainer>
<SkeletonOfferCard vertical />
<SkeletonOfferCard vertical />
<SkeletonOfferCard vertical />
</SkeletonContainer>
) : (
<OffersContainer>
{!isMobile ? ( {!isMobile ? (
isLoadingMineOffers || isLoadingMineOffers === undefined ? (
arrayForMapping.map((item, index) => (
<SkeletonOfferCard key={index} />
))
) : offersToShow.length !== 0 ? (
offersToShow.length !== 0 ? (
offersToShow.map((item) => ( offersToShow.map((item) => (
<OfferCard <OfferCard
isAdmin={props.isAdmin} isAdmin={props.isAdmin}

+ 19
- 0
src/components/Profile/ProfileOffers/ProfileOffersHeaderSkeleton/ProfileOffersHeaderSkeleton.styled.js Vedi File

display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 18px; gap: 18px;
@media (max-width: 600px) {
margin-bottom: 18px;
}
`; `;
export const ProfileOffersHeaderSkeletonGroupOne = styled(Box)` export const ProfileOffersHeaderSkeletonGroupOne = styled(Box)`
display: flex; display: flex;
)` )`
width: 148px; width: 148px;
height: 18px; height: 18px;
@media (max-width: 600px) {
width: 72px;
height: 18px;
position: relative;
top: 5px;
}
`; `;
export const ProfileOffersHeaderSkeletonLineSecond = styled( export const ProfileOffersHeaderSkeletonLineSecond = styled(
SkeletonBackgroundColor SkeletonBackgroundColor
)` )`
width: 209px; width: 209px;
height: 34px; height: 34px;
@media (max-width: 600px) {
width: 137px;
height: 29px;
}
`; `;
export const ProfileOffersHeaderSkeletonLineThird = styled( export const ProfileOffersHeaderSkeletonLineThird = styled(
SkeletonItemBackgroundColor SkeletonItemBackgroundColor
width: 120px; width: 120px;
margin-top: 2px; margin-top: 2px;
height: 14px; height: 14px;
@media (max-width: 600px) {
width: 108px;
}
`; `;
export const ProfileOffersHeaderSkeletonLineForth = styled( export const ProfileOffersHeaderSkeletonLineForth = styled(
SkeletonItemBackgroundColor SkeletonItemBackgroundColor
)` )`
width: 18px; width: 18px;
height: 18px; height: 18px;
@media (max-width: 600px) {
display: none;
}
`; `;

+ 23
- 0
src/util/helpers/messageHelper.js Vedi File

import { CHAT_MESSAGE_PAGE } from "../../constants/pages";
import history from "../../store/utils/history";
import { replaceInRoute } from "./routeHelpers";

export const messageUserHelper = (chats, userId, 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,
}
);
}
}
}

Loading…
Annulla
Salva