Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tktcorporation committed Oct 10, 2022
1 parent 114dee4 commit 3d22080
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
15 changes: 15 additions & 0 deletions web/src/components/Comment/Comment.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Comment from './Comment'

export const generated = () => {
return (
<Comment
comment={{
name: 'Rob Cameron',
body: 'This is the first comment!',
createdAt: '2020-01-01T12:34:56Z',
}}
/>
)
}

export default { title: 'Components/Comment' }
14 changes: 14 additions & 0 deletions web/src/components/Comment/Comment.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { render } from '@redwoodjs/testing/web'

import Comment from './Comment'

// Improve this test with help from the Redwood Testing Doc:
// https://redwoodjs.com/docs/testing#testing-components

describe('Comment', () => {
it('renders successfully', () => {
expect(() => {
render(<Comment />)
}).not.toThrow()
})
})
30 changes: 30 additions & 0 deletions web/src/components/Comment/Comment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const formattedDate = (datetime: ConstructorParameters<typeof Date>[0]) => {
const parsedDate = new Date(datetime)
const month = parsedDate.toLocaleString('default', { month: 'long' })
return `${parsedDate.getDate()} ${month} ${parsedDate.getFullYear()}`
}

// Just a temporary type. We'll replace this later
interface Props {
comment: {
name: string
createdAt: string
body: string
}
}

const Comment = ({ comment }: Props) => {
return (
<div className="bg-gray-200 p-8 rounded-lg">
<header className="flex justify-between">
<h2 className="font-semibold text-gray-700">{comment.name}</h2>
<time className="text-xs text-gray-500" dateTime={comment.createdAt}>
{formattedDate(comment.createdAt)}
</time>
</header>
<p className="text-sm mt-2">{comment.body}</p>
</div>
)
}

export default Comment

0 comments on commit 3d22080

Please sign in to comment.