-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
114dee4
commit 3d22080
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |