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 0ff871b commit 8ceb198
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
15 changes: 7 additions & 8 deletions web/src/components/Article/Article.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ import type { Post } from 'types/graphql'

import { Link, routes } from '@redwoodjs/router'

import CommentForm from 'src/components/CommentForm'
import CommentsCell from 'src/components/CommentsCell'

const truncate = (text: string, length: number) => {
return text.substring(0, length) + '...'
}

interface Props {
article: Omit<Post, 'createdAt'>
summary?: boolean
}

const Article = ({ article, summary = false }: Props) => {
const Article = ({ article, summary = false }) => {
return (
<article className="mt-10">
<article>
<header>
<h2 className="text-xl text-blue-700 font-semibold">
<Link to={routes.article({ id: article.id })}>{article.title}</Link>
Expand All @@ -26,7 +22,10 @@ const Article = ({ article, summary = false }: Props) => {
</div>
{!summary && (
<div className="mt-12">
<CommentsCell />
<CommentForm postId={article.id} />
<div className="mt-12">
<CommentsCell />
</div>
</div>
)}
</article>
Expand Down
8 changes: 6 additions & 2 deletions web/src/components/CommentForm/CommentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ interface FormValues {
comment: string
}

const CommentForm = () => {
interface Props {
postId: number
}

const CommentForm = ({ postId }: Props) => {
const [createComment, { loading, error }] = useMutation(CREATE)

const onSubmit: SubmitHandler<FormValues> = (input) => {
createComment({ variables: { input } })
createComment({ variables: { input: { postId, ...input } } })
}

return (
Expand Down

0 comments on commit 8ceb198

Please sign in to comment.