2022-03-21 23:30:45 -04:00
|
|
|
|
2022-03-10 02:46:59 -05:00
|
|
|
import NextLink from "next/link"
|
|
|
|
import { useEffect, useMemo, useState } from "react"
|
2022-03-30 23:01:24 -04:00
|
|
|
import { timeAgo } from "@lib/time-ago"
|
|
|
|
import VisibilityBadge from "../badges/visibility-badge"
|
2022-03-21 20:20:41 -04:00
|
|
|
import getPostPath from "@lib/get-post-path"
|
2022-03-26 03:24:18 -04:00
|
|
|
import { Link, Text, Card, Tooltip, Divider, Badge, Button } from "@geist-ui/core"
|
2022-03-26 03:05:05 -04:00
|
|
|
import { File, Post } from "@lib/types"
|
|
|
|
import FadeIn from "@components/fade-in"
|
2022-03-26 03:24:18 -04:00
|
|
|
import Trash from "@geist-ui/icons/trash"
|
|
|
|
import Cookies from "js-cookie"
|
2022-03-30 23:01:24 -04:00
|
|
|
import ExpirationBadge from "@components/badges/expiration-badge"
|
|
|
|
import CreatedAgoBadge from "@components/badges/created-ago-badge"
|
2022-03-09 20:11:37 -05:00
|
|
|
|
2022-03-26 03:05:05 -04:00
|
|
|
// TODO: isOwner should default to false so this can be used generically
|
2022-03-26 03:24:18 -04:00
|
|
|
const ListItem = ({ post, isOwner = true, deletePost }: { post: Post, isOwner?: boolean, deletePost: () => void }) => {
|
2022-03-10 02:46:59 -05:00
|
|
|
|
2022-03-26 03:05:05 -04:00
|
|
|
return (<FadeIn><li key={post.id}>
|
2022-03-09 20:11:37 -05:00
|
|
|
<Card style={{ overflowY: 'scroll' }}>
|
2022-03-24 22:25:02 -04:00
|
|
|
<Card.Body>
|
2022-03-31 02:03:21 -04:00
|
|
|
<Text h3 style={{
|
|
|
|
}}>
|
2022-03-24 22:25:02 -04:00
|
|
|
<NextLink passHref={true} href={getPostPath(post.visibility, post.id)}>
|
|
|
|
<Link color marginRight={'var(--gap)'}>
|
|
|
|
{post.title}
|
|
|
|
</Link>
|
|
|
|
</NextLink>
|
2022-03-26 03:05:05 -04:00
|
|
|
{isOwner && <span style={{ float: 'right' }}>
|
2022-03-26 03:24:18 -04:00
|
|
|
<Button iconRight={<Trash />} onClick={deletePost} auto />
|
2022-03-26 03:05:05 -04:00
|
|
|
</span>}
|
2022-03-24 22:25:02 -04:00
|
|
|
</Text>
|
2022-03-09 20:11:37 -05:00
|
|
|
|
2022-03-31 02:03:21 -04:00
|
|
|
|
|
|
|
<div style={{ display: 'inline-flex' }}>
|
|
|
|
<span>
|
|
|
|
<VisibilityBadge visibility={post.visibility} />
|
|
|
|
</span>
|
|
|
|
<span style={{ marginLeft: 'var(--gap)' }}>
|
|
|
|
<CreatedAgoBadge createdAt={post.createdAt} />
|
|
|
|
</span>
|
|
|
|
<span style={{ marginLeft: 'var(--gap)' }}>
|
2022-04-01 19:26:42 -04:00
|
|
|
<Badge type="secondary">{post.files?.length === 1 ? "1 file" : `${post.files?.length || 0} files`}</Badge>
|
2022-03-31 02:03:21 -04:00
|
|
|
</span>
|
|
|
|
<span style={{ marginLeft: 'var(--gap)' }}>
|
|
|
|
<ExpirationBadge postExpirationDate={post.expiresAt} />
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
|
2022-03-24 22:25:02 -04:00
|
|
|
</Card.Body>
|
|
|
|
<Divider h="1px" my={0} />
|
2022-03-23 19:28:39 -04:00
|
|
|
<Card.Content>
|
2022-04-01 19:26:42 -04:00
|
|
|
{post.files?.map((file: File) => {
|
2022-03-26 03:05:05 -04:00
|
|
|
return <div key={file.id}>
|
|
|
|
<Link color href={`${getPostPath(post.visibility, post.id)}#${file.title}`}>
|
|
|
|
{file.title || 'Untitled file'}
|
|
|
|
</Link></div>
|
2022-03-09 20:11:37 -05:00
|
|
|
})}
|
|
|
|
</Card.Content>
|
|
|
|
|
|
|
|
</Card>
|
2022-03-26 03:05:05 -04:00
|
|
|
|
|
|
|
</li> </FadeIn>)
|
2022-03-09 20:11:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export default ListItem
|