File size: 1,760 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
import { Box, Text, useColorModeValue, Wrap, WrapItem } from "@chakra-ui/react";
import { nanoid } from "@reduxjs/toolkit";
import React from "react";
import { useDispatch } from "react-redux";
import { useNavigate } from "react-router-dom";
import { titleRoute } from "../../helper/titleRoute";
import useClickTag from "../../hooks/useClickTag";
import { setClickComment } from "../../store/scrollDiscussion";
import LangTag from "../../utils/LangTag";

const OtherPostItem = ({ username, title, tags, postId, isLastElement }) => {
  const navigate = useNavigate();
  const dispatch = useDispatch();

  const handleNavigate = (e) => {
    e.stopPropagation();
    dispatch(setClickComment(false));

    navigate(`/${titleRoute(username, title, postId)}`);
  };

  const handleClickTag = useClickTag();

  const borderBottom = useColorModeValue(
    "1px solid rgb(23 23 23 / 13%)",
    "1px solid rgb(255 255 255 / 15%)"
  );

  return (
    <Box
      mb=".5rem"
      py=".5rem"
      px="1rem"
      onClick={handleNavigate}
      cursor="pointer"
      _hover={{
        bg: useColorModeValue("light.cardBg", "dark.cardBg"),
      }}
      borderBottom={!isLastElement && borderBottom}
    >
      <Text
        fontWeight={600}
        _hover={{
          color: useColorModeValue("light.headingHover", "dark.headingHover"),
        }}
        cursor="pointer"
        onClick={handleNavigate}
      >
        {title}
      </Text>

      <Wrap spacing=".2rem" pt=".3rem">
        {tags?.map((tag) => (
          <WrapItem
            key={nanoid()}
            onClick={(e) => handleClickTag(e, tag.tagName)}
          >
            <LangTag tag={tag} />
          </WrapItem>
        ))}
      </Wrap>
    </Box>
  );
};

export default OtherPostItem;