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 ShiftBy from "../shift-by"
|
|
|
|
import VisibilityBadge from "../visibility-badge"
|
2022-03-21 20:20:41 -04:00
|
|
|
import getPostPath from "@lib/get-post-path"
|
2022-03-22 23:06:15 -04:00
|
|
|
import { Input, Link, Text, Card, Spacer, Grid, Tooltip, Divider } from "@geist-ui/core"
|
2022-03-09 20:11:37 -05:00
|
|
|
|
|
|
|
const FilenameInput = ({ title }: { title: string }) => <Input
|
|
|
|
value={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%"}
|
|
|
|
/>
|
|
|
|
|
|
|
|
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' }}>
|
|
|
|
<Spacer height={1 / 2} />
|
2022-03-20 23:45:37 -04:00
|
|
|
<Grid.Container>
|
|
|
|
<Grid md={14} xs={14}>
|
|
|
|
<Text h3 paddingLeft={1 / 2} >
|
2022-03-21 20:20:41 -04:00
|
|
|
<NextLink passHref={true} href={getPostPath(post.visibility, post.id)}>
|
2022-03-10 02:46:59 -05:00
|
|
|
<Link color>{post.title}
|
|
|
|
<ShiftBy y={-1}><VisibilityBadge visibility={post.visibility} /></ShiftBy>
|
|
|
|
</Link>
|
|
|
|
</NextLink>
|
2022-03-09 20:11:37 -05:00
|
|
|
</Text></Grid>
|
2022-03-20 23:45:37 -04:00
|
|
|
<Grid paddingLeft={1 / 2} md={5} xs={9}><Text type="secondary" h5><Tooltip text={formattedTime}>{time}</Tooltip></Text></Grid>
|
|
|
|
<Grid paddingLeft={1 / 2} md={5} xs={4}><Text type="secondary" h5>{post.files.length === 1 ? "1 file" : `${post.files.length} files`}</Text></Grid>
|
2022-03-09 20:11:37 -05:00
|
|
|
</Grid.Container>
|
|
|
|
|
|
|
|
<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
|