File size: 3,613 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
import { Box, Button, Text } from '@chakra-ui/react';
import React from 'react';
import { useAuth } from '../../context/auth';
import {
   calcTotalDiscussion,
   calculateReaction,
} from '../../helper/calculateTotal';
import PostItem from '../post/PostItem';
import { BsFillPinAngleFill } from 'react-icons/bs';

const ProfileRightPart = ({ pinnedPosts, otherPosts }) => {
   const user = useAuth();
   const userId = user?.userId;

   return (
      <Box flex={{ base: 'unset', md: '2' }} borderRadius='5px' w='100%'>
         {pinnedPosts && pinnedPosts.length !== 0 && (
            <Box
               border='2px solid rgb(59 73 223)'
               borderRadius='5px'
               mb='.5rem'
               p={{ base: '.7rem .7rem .3rem', md: '1rem 1rem .5rem' }}
            >
               <Box as='header'>
                  <Button
                     bg='light.primary'
                     _hover={{ bg: 'light.primary' }}
                     m={{ base: '-2rem 0 0 0', md: '-2.5rem 0 0' }}
                     _active={{ bg: 'light.primary' }}
                     cursor='default'
                     color='dark.color'
                  >
                     <BsFillPinAngleFill size={19} />
                     <Text fontWeight={700} ms='.5rem'>
                        Pinned
                     </Text>
                  </Button>
               </Box>

               {pinnedPosts.map((postData) => (
                  <PostItem
                     key={postData.id}
                     name={postData.name}
                     username={postData.username}
                     profile={postData.profile}
                     id={postData.id}
                     createdAt={postData.createdAt}
                     title={postData.title}
                     tags={postData.tags}
                     readTime={postData.readTime}
                     isUpdated={postData?.updated}
                     userId={postData.userId}
                     currentUserId={userId} // authenticated userId
                     totalDiscussion={calcTotalDiscussion(postData.comments)}
                     totalReaction={calculateReaction(
                        postData.heart,
                        postData.unicorn,
                        postData.saved
                     )}
                     saved={postData.saved}
                     alreadySaved={postData.saved?.includes(userId)}
                     baseRadius='5px'
                  />
               ))}
            </Box>
         )}

         {otherPosts &&
            otherPosts.map((postData) => (
               <PostItem
                  key={postData.id}
                  name={postData.name}
                  username={postData.username}
                  profile={postData.profile}
                  id={postData.id}
                  createdAt={postData.createdAt}
                  title={postData.title}
                  tags={postData.tags}
                  readTime={postData.readTime}
                  isUpdated={postData?.updated}
                  userId={postData.userId}
                  currentUserId={userId} // authenticated userId
                  totalDiscussion={calcTotalDiscussion(postData.comments)}
                  totalReaction={calculateReaction(
                     postData.heart,
                     postData.unicorn,
                     postData.saved
                  )}
                  saved={postData.saved}
                  alreadySaved={postData.saved?.includes(userId)}
               />
            ))}
      </Box>
   );
};

export default ProfileRightPart;