diff --git a/components/icons/CrossIcon.tsx b/components/icons/CrossIcon.tsx new file mode 100644 index 0000000..dde0123 --- /dev/null +++ b/components/icons/CrossIcon.tsx @@ -0,0 +1,10 @@ +import {Props} from '@/types' + +export function CrossIcon(props: Props) { + return ( + + ) +} \ No newline at end of file diff --git a/components/ui/Comments.tsx b/components/ui/Comments.tsx index d52e060..475d141 100644 --- a/components/ui/Comments.tsx +++ b/components/ui/Comments.tsx @@ -1,6 +1,6 @@ 'use client' -import React, {ReactNode, useActionState, useEffect, useState} from 'react' +import React, {useActionState, useEffect, useState} from 'react' import {useSession} from 'next-auth/react' import Image from 'next/image' import clsx from 'clsx' @@ -8,6 +8,7 @@ import {addComment, loginWithGitHub} from '@/app/actions/comments' import {Button} from '@/components/ui/Button' import {GitHubIcon} from '@/components/icons/SocialIcons' import {ArrowLeftIcon} from '@/components/icons/ArrowLeftIcon' +import {StatusMessage} from '@/components/ui/StatusMessage' import {getShortDurationFromNow} from '@/lib/dateFns' import ReplyProvider, {useReplyContext} from '@/app/context/ReplyProvider' import CommentFormProvider, {useCommentFormContext} from '@/app/context/CommentFormProvider' @@ -98,23 +99,6 @@ Comments.List = function List({comments}: CommentsListProps) { ) } -type CommentsStatusProps = { - children: ReactNode -} - -Comments.Status = function Status({children}: CommentsStatusProps) { - const errorConditions = ['error', 'problem'] - const isError = errorConditions.some(condition => children?.toString().toLowerCase().includes(condition)) - - return ( -

- {children} -

- ) -} - type InitialState = { message: string } @@ -130,6 +114,8 @@ Comments.Form = function Form({slug}: { slug: string }) { const replyContext = useReplyContext() const commentFormContext = useCommentFormContext() const commentFormRef = commentFormContext?.commentFormRef + const [commentLength, setCommentLength] = useState(0) + const commentMaxLength = 300 useEffect(() => { if (replyContext?.replyTo?.parent_id !== null) { @@ -151,6 +137,11 @@ Comments.Form = function Form({slug}: { slug: string }) { } } + const handleSubmit = () => { + replyContext?.setReplyTo(null) + setCommentLength(0) + } + return (
{!session ? @@ -159,7 +150,7 @@ Comments.Form = function Form({slug}: { slug: string }) { Sign in to comment : -
replyContext?.setReplyTo(null)}> +
diff --git a/components/ui/StatusMessage.tsx b/components/ui/StatusMessage.tsx new file mode 100644 index 0000000..841df0c --- /dev/null +++ b/components/ui/StatusMessage.tsx @@ -0,0 +1,29 @@ +import clsx from 'clsx' +import React, {ReactNode} from 'react' +import {CheckIcon} from '@/components/icons/CheckIcon' +import {CrossIcon} from '@/components/icons/CrossIcon' + +type StatusMessageProps = { + children: ReactNode + className?: string +} + +export function StatusMessage({children, className}: StatusMessageProps) { + const errorConditions = ['error', 'problem'] + const isError = errorConditions.some(condition => children?.toString().toLowerCase().includes(condition)) + + return ( + <> + {children && +
+ {!isError ? + : } +

+ {children} +

+
+ } + + ) +} \ No newline at end of file