aboutsummaryrefslogtreecommitdiff
path: root/src/web/components/post/Post.jsx
blob: 3780a3890cf736c4c7ace07fd2eb8a4cc13aa4af (plain)
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
import React from "react";
import {useLocation, useNavigate} from "react-router-dom";
import dayjs from "dayjs";
import * as relativeTime from "dayjs/plugin/relativeTime";

import Card from "components/card/Card.jsx";
import styles from "./Post.css";
import {getInfoFromSubreact} from "helpers/Location.jsx";

import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";

dayjs.extend(relativeTime);

function TopRow({title, timeUpdated}) {
    return (
        <div className={styles.titleContainer}>
            <h3>
                {title}
            </h3>
            <h4>
                {dayjs.unix(timeUpdated).fromNow()}
            </h4>
        </div>
    );
}

function MiddleRow({contents}) {
    return (
        <h4>
            {contents}
        </h4>
    );
}

function BottomRow({subreact}) {
    const {icon, name} = getInfoFromSubreact(subreact);

    return (
        <div className={styles.postIconsContainer}>
            <FontAwesomeIcon icon={icon} className={styles.subreactIcon} />
            <div>
                {name}
            </div>
        </div>
    );
}

export default function Post({title, contents, timeUpdated, placeholder, subreact, uid}) {
    const location = useLocation();
    const navigate = useNavigate();

    return (
        <Card className={styles.postCard + (placeholder ? " " + styles.placeholder : "")}
            onClick={() => {navigate("/" + subreact + "/" + uid);}}>
            <img src={placeholder ? null : "/image/" + uid + ".png?thumbnail=1"} />
            <div className={styles.rowContainer}>
                <TopRow title={title} timeUpdated={timeUpdated} />
                <MiddleRow contents={contents} />
                <BottomRow subreact={subreact} />
            </div>
        </Card>
    );
}