2022-03-21 23:30:45 -04:00
|
|
|
import Text from "@geist-ui/core/dist/text"
|
2022-03-10 02:46:59 -05:00
|
|
|
import NextLink from "next/link"
|
2022-03-06 20:20:01 -05:00
|
|
|
import Link from '../Link'
|
2022-03-06 19:46:59 -05:00
|
|
|
|
|
|
|
import styles from './post-list.module.css'
|
2022-03-09 20:11:37 -05:00
|
|
|
import ListItemSkeleton from "./list-item-skeleton"
|
|
|
|
import ListItem from "./list-item"
|
2022-03-06 19:46:59 -05:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
posts: any
|
|
|
|
error: any
|
|
|
|
}
|
|
|
|
|
|
|
|
const PostList = ({ posts, error }: Props) => {
|
|
|
|
return (
|
|
|
|
<div className={styles.container}>
|
|
|
|
{error && <Text type='error'>Failed to load.</Text>}
|
2022-03-09 20:11:37 -05:00
|
|
|
{!posts && <ul>
|
|
|
|
<li>
|
|
|
|
<ListItemSkeleton />
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<ListItemSkeleton />
|
|
|
|
</li>
|
|
|
|
</ul>}
|
2022-03-10 02:46:59 -05:00
|
|
|
{posts?.length === 0 && <Text>You have no posts. Create one <NextLink passHref={true} href="/new"><Link color>here</Link></NextLink>.</Text>}
|
2022-03-06 19:46:59 -05:00
|
|
|
{
|
|
|
|
posts?.length > 0 && <div>
|
|
|
|
<ul>
|
|
|
|
{posts.map((post: any) => {
|
2022-03-09 20:11:37 -05:00
|
|
|
return <ListItem post={post} key={post.id} />
|
2022-03-06 19:46:59 -05:00
|
|
|
})}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
}
|
2022-03-09 04:33:22 -05:00
|
|
|
</div >
|
2022-03-06 19:46:59 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-09 20:11:37 -05:00
|
|
|
export default PostList
|