add component
This commit is contained in:
16
web/src/components/BlogPost/BlogPost.js
Normal file
16
web/src/components/BlogPost/BlogPost.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { Link, routes } from '@redwoodjs/router'
|
||||||
|
|
||||||
|
const BlogPost = ({ post }) => {
|
||||||
|
return (
|
||||||
|
<article>
|
||||||
|
<header>
|
||||||
|
<h2>
|
||||||
|
<Link to={routes.blogPost({ id: post.id })}>{post.title}</Link>
|
||||||
|
</h2>
|
||||||
|
</header>
|
||||||
|
<div>{post.body}</div>
|
||||||
|
</article>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BlogPost
|
||||||
7
web/src/components/BlogPost/BlogPost.stories.js
Normal file
7
web/src/components/BlogPost/BlogPost.stories.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import BlogPost from './BlogPost'
|
||||||
|
|
||||||
|
export const generated = () => {
|
||||||
|
return <BlogPost />
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { title: 'Components/BlogPost' }
|
||||||
11
web/src/components/BlogPost/BlogPost.test.js
Normal file
11
web/src/components/BlogPost/BlogPost.test.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { render } from '@redwoodjs/testing'
|
||||||
|
|
||||||
|
import BlogPost from './BlogPost'
|
||||||
|
|
||||||
|
describe('BlogPost', () => {
|
||||||
|
it('renders successfully', () => {
|
||||||
|
expect(() => {
|
||||||
|
render(<BlogPost />)
|
||||||
|
}).not.toThrow()
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import BlogPost from 'src/components/BlogPost'
|
||||||
|
|
||||||
export const QUERY = gql`
|
export const QUERY = gql`
|
||||||
query BlogPostQuery($id: Int!) {
|
query BlogPostQuery($id: Int!) {
|
||||||
post(id: $id) {
|
post(id: $id) {
|
||||||
@@ -16,5 +18,5 @@ export const Empty = () => <div>Empty</div>
|
|||||||
export const Failure = ({ error }) => <div>Error: {error.message}</div>
|
export const Failure = ({ error }) => <div>Error: {error.message}</div>
|
||||||
|
|
||||||
export const Success = ({ post }) => {
|
export const Success = ({ post }) => {
|
||||||
return JSON.stringify(post)
|
return <BlogPost post={post} />
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Link, routes } from '@redwoodjs/router'
|
import { Link, routes } from '@redwoodjs/router'
|
||||||
|
import BlogPost from 'src/components/BlogPost'
|
||||||
|
|
||||||
export const QUERY = gql`
|
export const QUERY = gql`
|
||||||
query BlogPostsQuery {
|
query BlogPostsQuery {
|
||||||
@@ -18,15 +19,5 @@ export const Empty = () => <div>Empty</div>
|
|||||||
export const Failure = ({ error }) => <div>Error: {error.message}</div>
|
export const Failure = ({ error }) => <div>Error: {error.message}</div>
|
||||||
|
|
||||||
export const Success = ({ posts }) => {
|
export const Success = ({ posts }) => {
|
||||||
return posts.map((post) => (
|
return posts.map((post) => <BlogPost post={post} />)
|
||||||
<article key={post.id}>
|
|
||||||
<header>
|
|
||||||
<h2>
|
|
||||||
<Link to={routes.blogPost({id: post.id})}>{post.title}</Link>
|
|
||||||
</h2>
|
|
||||||
</header>
|
|
||||||
<p>{post.body}</p>
|
|
||||||
<div>Posted on: {post.createdAt.split('T')[0]}</div>
|
|
||||||
</article>
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user