2022-03-10 02:46:59 -05:00
|
|
|
import NextLink from "next/link"
|
2022-03-30 23:01:24 -04:00
|
|
|
import VisibilityBadge from "../badges/visibility-badge"
|
2022-11-10 02:11:36 -05:00
|
|
|
import {
|
|
|
|
Text,
|
|
|
|
Card,
|
|
|
|
Tooltip,
|
|
|
|
Divider,
|
|
|
|
Badge,
|
|
|
|
Button
|
|
|
|
} from "@geist-ui/core/dist"
|
2022-03-26 03:05:05 -04:00
|
|
|
import FadeIn from "@components/fade-in"
|
2022-03-26 03:24:18 -04:00
|
|
|
import Trash from "@geist-ui/icons/trash"
|
2022-03-30 23:01:24 -04:00
|
|
|
import ExpirationBadge from "@components/badges/expiration-badge"
|
|
|
|
import CreatedAgoBadge from "@components/badges/created-ago-badge"
|
2022-04-02 01:55:27 -04:00
|
|
|
import Edit from "@geist-ui/icons/edit"
|
|
|
|
import { useRouter } from "next/router"
|
2022-04-09 20:48:19 -04:00
|
|
|
import Parent from "@geist-ui/icons/arrowUpCircle"
|
2022-04-02 01:55:27 -04:00
|
|
|
import styles from "./list-item.module.css"
|
2022-11-08 03:23:28 -05:00
|
|
|
import Link from "@components/link"
|
2022-11-10 02:11:36 -05:00
|
|
|
import { PostWithFiles, File } from "app/prisma"
|
|
|
|
import { PostVisibility } from "@lib/types"
|
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-04-09 20:48:19 -04:00
|
|
|
const ListItem = ({
|
|
|
|
post,
|
|
|
|
isOwner = true,
|
|
|
|
deletePost
|
|
|
|
}: {
|
2022-11-10 02:11:36 -05:00
|
|
|
post: PostWithFiles
|
2022-04-09 20:48:19 -04:00
|
|
|
isOwner?: boolean
|
|
|
|
deletePost: () => void
|
|
|
|
}) => {
|
|
|
|
const router = useRouter()
|
2022-03-31 02:03:21 -04:00
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
const editACopy = () => {
|
|
|
|
router.push(`/new/from/${post.id}`)
|
|
|
|
}
|
2022-03-09 20:11:37 -05:00
|
|
|
|
2022-04-14 20:18:47 -04:00
|
|
|
const viewParentClick = () => {
|
2022-11-10 02:11:36 -05:00
|
|
|
router.push(`/post/${post.parentId}`)
|
2022-04-14 20:18:47 -04:00
|
|
|
}
|
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
return (
|
|
|
|
<FadeIn>
|
|
|
|
<li key={post.id}>
|
|
|
|
<Card style={{ overflowY: "scroll" }}>
|
|
|
|
<Card.Body>
|
|
|
|
<Text h3 className={styles.title}>
|
2022-11-08 03:23:28 -05:00
|
|
|
<Link
|
|
|
|
colored
|
|
|
|
style={{ marginRight: "var(--gap)" }}
|
2022-04-14 20:18:47 -04:00
|
|
|
href={`/post/[id]`}
|
|
|
|
as={`/post/${post.id}`}
|
2022-04-09 20:48:19 -04:00
|
|
|
>
|
2022-11-08 03:23:28 -05:00
|
|
|
{post.title}
|
|
|
|
</Link>
|
2022-04-09 20:48:19 -04:00
|
|
|
{isOwner && (
|
|
|
|
<span className={styles.buttons}>
|
2022-11-10 02:11:36 -05:00
|
|
|
{post.parentId && (
|
2022-04-09 20:48:19 -04:00
|
|
|
<Tooltip text={"View parent"} hideArrow>
|
|
|
|
<Button
|
|
|
|
auto
|
|
|
|
icon={<Parent />}
|
2022-04-14 20:18:47 -04:00
|
|
|
onClick={viewParentClick}
|
2022-04-09 20:48:19 -04:00
|
|
|
/>
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
|
|
|
<Tooltip text={"Make a copy"} hideArrow>
|
|
|
|
<Button auto iconRight={<Edit />} onClick={editACopy} />
|
|
|
|
</Tooltip>
|
|
|
|
<Tooltip text={"Delete"} hideArrow>
|
|
|
|
<Button iconRight={<Trash />} onClick={deletePost} auto />
|
|
|
|
</Tooltip>
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</Text>
|
2022-03-26 03:05:05 -04:00
|
|
|
|
2022-04-14 17:25:31 -04:00
|
|
|
{post.description && (
|
|
|
|
<Text p className={styles.oneline}>
|
|
|
|
{post.description}
|
|
|
|
</Text>
|
|
|
|
)}
|
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
<div className={styles.badges}>
|
2022-11-10 02:11:36 -05:00
|
|
|
<VisibilityBadge visibility={post.visibility as PostVisibility} />
|
2022-04-09 20:48:19 -04:00
|
|
|
<CreatedAgoBadge createdAt={post.createdAt} />
|
|
|
|
<Badge type="secondary">
|
|
|
|
{post.files?.length === 1
|
|
|
|
? "1 file"
|
|
|
|
: `${post.files?.length || 0} files`}
|
|
|
|
</Badge>
|
|
|
|
<ExpirationBadge postExpirationDate={post.expiresAt} />
|
|
|
|
</div>
|
|
|
|
</Card.Body>
|
|
|
|
<Divider h="1px" my={0} />
|
|
|
|
<Card.Content>
|
|
|
|
{post.files?.map((file: File) => {
|
|
|
|
return (
|
|
|
|
<div key={file.id}>
|
2022-11-08 03:23:28 -05:00
|
|
|
<Link colored href={`/post/${post.id}#${file.title}`}>
|
2022-04-09 20:48:19 -04:00
|
|
|
{file.title || "Untitled file"}
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</Card.Content>
|
|
|
|
</Card>
|
|
|
|
</li>{" "}
|
|
|
|
</FadeIn>
|
|
|
|
)
|
2022-03-09 20:11:37 -05:00
|
|
|
}
|
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
export default ListItem
|