File size: 2,936 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import React from "react";
import { Box, Text, useColorModeValue } from "@chakra-ui/react";
import UserProfilePopup from "../profile/UserProfilePopup";
import { nanoid } from "@reduxjs/toolkit";
import { useNavigate } from "react-router-dom";
import OtherPostItem from "../post/OtherPostItem";
import { useAuth } from "../../context/auth";

const DetailRightContent = ({
  currentUserProfile,
  otherPosts,
  userId,
  display,
  m,
  trandingOnDevCommunity,
}) => {
  const navigate = useNavigate();
  const user = useAuth();

  const cardColor = useColorModeValue(
    "light.cardSecondaryBg",
    "dark.cardSecondaryBg"
  );

  const nameColor = useColorModeValue(
    "light.headingHover",
    "dark.headingHover"
  );

  const postsToShow =
    otherPosts.length !== 0 ? otherPosts : trandingOnDevCommunity;

  return (
    <Box
      m={m}
      flex="1"
      ms={{ xl: "1rem" }}
      pos="sticky"
      top="4rem"
      display={display}
    >
      <UserProfilePopup
        w="100%"
        p="1rem"
        m={{ base: "0", md: "1px" }}
        borderRadius={{ base: "0", md: "5px" }}
        boxShadow={useColorModeValue(
          "0 0 0 1px rgb(23 23 23 / 10%)",
          "0 0 0 1px rgb(255 255 255 / 15%)"
        )}
        backgroundHeight="50px"
        background={currentUserProfile.background}
        profile={currentUserProfile.profile}
        name={currentUserProfile.name}
        username={currentUserProfile.username}
        bio={currentUserProfile.bio}
        work={currentUserProfile.work}
        location={currentUserProfile.location}
        education={currentUserProfile.education}
        joined={currentUserProfile.createdAt}
        id={userId}
        currentUserId={user?.userId}
        followers={currentUserProfile.followers || []}
      />

      <Box
        borderRadius={{ base: "0", md: "5px" }}
        className="shadow"
        mt="1rem"
        overflow="hidden"
        bg={cardColor}
        py=".5rem"
      >
        <Text fontSize="1.3rem" mb="1rem" fontWeight={600} ms="1rem">
          {otherPosts.length ? "More from" : "Trending on"}{" "}
          <Text
            as="span"
            color={nameColor}
            cursor="pointer"
            onClick={() =>
              otherPosts.length
                ? navigate(`/${currentUserProfile.username}`)
                : navigate("/")
            }
          >
            {otherPosts.length
              ? currentUserProfile.name
              : "DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»πŸ”₯"}
          </Text>
        </Text>

        {postsToShow.map((postData, idx) => (
          <OtherPostItem
            key={nanoid()}
            username={postData.username}
            title={postData.title}
            tags={postData.tags}
            postId={postData.id}
            isLastElement={idx === postsToShow.length - 1}
          />
        ))}
      </Box>
    </Box>
  );
};

export default DetailRightContent;