File size: 5,326 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { Flex, IconButton, useColorModeValue } from '@chakra-ui/react';
import React from 'react';
import useClickReactToPost from '../../hooks/useClickReactToPost';
import { useAuth } from '../../context/auth';
import MoreOptionMenu from './MoreOptionMenu';
import {
   Heart,
   AlreadyHearted,
   Unicorn,
   AlreadyUnicorned,
   Save,
   AlreadySaved,
} from '../../assets/icons';

const styles = {
   direction: { base: 'row', md: 'column' },
   align: 'center',
   fontSize: '15px',
   cursor: 'pointer',
};

const iconStyles = {
   bg: 'transparent',
   borderRadius: 'full',
   mb: { base: '0', md: '2' },
   mr: { base: '2', md: '0' },
};

const SideReactionBar = ({ postDetail }) => {
   const user = useAuth();

   const { clickReactHandler: clickHeart, updatingReact: updatingHeart } =
      useClickReactToPost(postDetail.heart, postDetail.id, 'heart');

   const { clickReactHandler: clickUnicorn, updatingReact: updatingUnicorn } =
      useClickReactToPost(postDetail.unicorn, postDetail.id, 'unicorn');

   const { clickReactHandler: clickSave, updatingReact: updatingSave } =
      useClickReactToPost(postDetail.saved, postDetail.id, 'saved');

   const alreadyHeart = postDetail.heart?.includes(user?.userId);
   const alreadyUnicorned = postDetail.unicorn?.includes(user?.userId);
   const alreadySaved = postDetail.saved?.includes(user?.userId);

   const totalHeart = postDetail.heart?.length || 0;
   const totalUnicorn = postDetail.unicorn?.length || 0;
   const totalSaved = postDetail.saved?.length || 0;

   const reactionIconColor = useColorModeValue('#3d3d3d', '#d6d6d7');
   const bg = useColorModeValue('rgb(255, 255, 255)', 'rgb(0, 0, 0)');

   return (
      <Flex
         bg={{ base: bg, md: 'transparent' }}
         boxShadow={{ base: '0 -1px 5px rgba(0,0,0,0.2)', md: 'none' }}
         height={{ base: '3.5rem', md: 'auto' }}
         width={{ base: '100vw', md: '50px' }}
         position={{ base: 'fixed', md: 'sticky' }}
         bottom={{ base: '0', md: 'unset' }}
         left='0'
         top={{ base: 'unset', md: '6rem' }}
         zIndex='2'
         direction={{ base: 'row', md: 'column' }}
         align='center'
         justify={{ base: 'space-around', md: 'flex-start' }}
         gap='1rem'
         me='1rem'
      >
         {!postDetail.draft && (
            <Flex
               {...styles}
               onClick={clickHeart}
               color={alreadyHeart && 'rgb(220 38 38)'}
            >
               <IconButton
                  disabled={updatingHeart}
                  icon={
                     alreadyHeart ? (
                        <AlreadyHearted />
                     ) : (
                        <Heart fill={reactionIconColor} />
                     )
                  }
                  {...iconStyles}
                  border={alreadyHeart && '2px solid rgb(220 38 38)'}
                  bg={alreadyHeart ? 'rgb(220 38 38 / 10%)' : 'transparent'}
                  _hover={{
                     bg: 'rgb(220 38 38 / 10%)',
                     svg: { fill: 'rgb(220 38 38)' },
                  }}
               />
               {totalHeart}
            </Flex>
         )}

         {!postDetail.draft && (
            <Flex
               {...styles}
               onClick={clickUnicorn}
               color={alreadyUnicorned && 'rgb(5 150 105)'}
            >
               <IconButton
                  disabled={updatingUnicorn}
                  icon={
                     alreadyUnicorned ? (
                        <AlreadyUnicorned />
                     ) : (
                        <Unicorn fill={reactionIconColor} />
                     )
                  }
                  {...iconStyles}
                  border={alreadyUnicorned && '2px solid rgb(5 150 105)'}
                  bg={alreadyUnicorned ? 'rgb(5 150 105 / 10%)' : 'transparent'}
                  _hover={{
                     bg: 'rgb(5 150 105 / 10%)',
                     svg: { fill: 'rgb(5 150 105)' },
                  }}
               />
               {totalUnicorn}
            </Flex>
         )}

         {!postDetail.draft && (
            <Flex
               {...styles}
               onClick={clickSave}
               color={alreadySaved && 'rgb(79 70 229)'}
            >
               <IconButton
                  disabled={updatingSave}
                  icon={
                     alreadySaved ? (
                        <AlreadySaved />
                     ) : (
                        <Save fill={reactionIconColor} />
                     )
                  }
                  {...iconStyles}
                  border={alreadySaved && '2px solid rgb(79 70 229)'}
                  bg={alreadySaved ? 'rgb(79 70 229 / 10%)' : 'transparent'}
                  _hover={{
                     bg: 'rgb(79 70 229 / 10%)',
                     svg: { fill: 'rgb(79 70 229)' },
                  }}
               />
               {totalSaved}
            </Flex>
         )}

         <Flex direction={{ base: 'row', md: 'column' }} align='center'>
            <MoreOptionMenu
               iconStyles={iconStyles}
               postTitle={postDetail.title}
               reactionIconColor={reactionIconColor}
            />
         </Flex>
      </Flex>
   );
};

export default SideReactionBar;