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-12 23:40:28 -05:00
|
|
|
import timeAgo from "@lib/time-ago"
|
2022-03-09 20:11:37 -05:00
|
|
|
import VisibilityBadge from "../visibility-badge"
|
2022-03-21 20:20:41 -04:00
|
|
|
import getPostPath from "@lib/get-post-path"
|
2022-03-24 22:25:02 -04:00
|
|
|
import { Input, Link, Text, Card, Spacer, Grid, Tooltip, Divider, Badge } from "@geist-ui/core"
|
2022-03-09 20:11:37 -05:00
|
|
|
|
|
|
|
const FilenameInput = ({ title }: { title: string }) => <Input
|
2022-03-24 18:35:59 -04:00
|
|
|
value={title || 'No title'}
|
2022-03-23 00:18:26 -04:00
|
|
|
marginTop="var(--gap)"
|
2022-03-09 20:11:37 -05:00
|
|
|
size={1.2}
|
|
|
|
font={1.2}
|
|
|
|
label="Filename"
|
|
|
|
readOnly
|
|
|
|
width={"100%"}
|
2022-03-24 18:35:59 -04:00
|
|
|
style={{ color: !!title ? 'var(--fg)' : 'var(--gray)' }}
|
2022-03-09 20:11:37 -05:00
|
|
|
/>
|
|
|
|
|
|
|
|
const ListItem = ({ post }: { post: any }) => {
|
2022-03-10 02:46:59 -05:00
|
|
|
const createdDate = useMemo(() => new Date(post.createdAt), [post.createdAt])
|
|
|
|
const [time, setTimeAgo] = useState(timeAgo(createdDate))
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const interval = setInterval(() => {
|
|
|
|
setTimeAgo(timeAgo(createdDate))
|
|
|
|
}, 10000)
|
|
|
|
return () => clearInterval(interval)
|
|
|
|
}, [createdDate])
|
|
|
|
|
|
|
|
const formattedTime = `${createdDate.toLocaleDateString()} ${createdDate.toLocaleTimeString()}`
|
2022-03-09 20:11:37 -05:00
|
|
|
return (<li key={post.id}>
|
|
|
|
<Card style={{ overflowY: 'scroll' }}>
|
2022-03-24 22:25:02 -04:00
|
|
|
<Card.Body>
|
|
|
|
<Text h3>
|
|
|
|
<NextLink passHref={true} href={getPostPath(post.visibility, post.id)}>
|
|
|
|
<Link color marginRight={'var(--gap)'}>
|
|
|
|
{post.title}
|
|
|
|
</Link>
|
|
|
|
</NextLink>
|
|
|
|
<div style={{ display: 'inline-flex' }}>
|
|
|
|
<span>
|
|
|
|
<VisibilityBadge visibility={post.visibility} />
|
|
|
|
</span>
|
|
|
|
<span style={{ marginLeft: 'var(--gap)' }}>
|
|
|
|
<Badge type="secondary"><Tooltip text={formattedTime}>{time}</Tooltip></Badge>
|
|
|
|
</span>
|
|
|
|
<span style={{ marginLeft: 'var(--gap)' }}>
|
|
|
|
<Badge type="secondary">{post.files.length === 1 ? "1 file" : `${post.files.length} files`}</Badge>
|
|
|
|
</span>
|
2022-03-09 20:11:37 -05:00
|
|
|
|
2022-03-24 22:25:02 -04:00
|
|
|
</div>
|
|
|
|
</Text>
|
2022-03-09 20:11:37 -05:00
|
|
|
|
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-03-09 20:11:37 -05:00
|
|
|
{post.files.map((file: any) => {
|
|
|
|
return <FilenameInput key={file.id} title={file.title} />
|
|
|
|
})}
|
|
|
|
</Card.Content>
|
|
|
|
|
|
|
|
</Card>
|
|
|
|
</li>)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ListItem
|