import NextLink from "next/link" import { useEffect, useMemo, useState } from "react" import timeAgo from "@lib/time-ago" import VisibilityBadge from "../visibility-badge" import getPostPath from "@lib/get-post-path" import { Link, Text, Card, Tooltip, Divider, Badge } from "@geist-ui/core" import { File, Post } from "@lib/types" import FadeIn from "@components/fade-in" // TODO: isOwner should default to false so this can be used generically const ListItem = ({ post, isOwner = true }: { post: Post, isOwner?: boolean }) => { 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()}` return (
  • {post.title}
    {time} {post.files.length === 1 ? "1 file" : `${post.files.length} files`}
    {isOwner && }
    {post.files.map((file: File) => { return
    {file.title || 'Untitled file'}
    })}
  • ) } export default ListItem