Created
June 9, 2022 16:34
-
-
Save JamDev0/a7a63f83e0c03f69de5ff22032e9aba3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import { FormEvent, useState } from 'react'; | |
| interface PostFooterProps { | |
| CommentsContent: { | |
| Id: number; | |
| UserName: string; | |
| ProfilePic: string; | |
| IsTheCurrentUser: boolean; | |
| PublishTime: number; | |
| Content: string; | |
| LikesAmount: number; | |
| }[] | null; | |
| } | |
| export function PostFooter({ CommentsContent }: PostFooterProps) { | |
| const [CurrentComments, setCurrentComments] = useState<PostFooterProps["CommentsContent"] | null>(CommentsContent); | |
| function HandleCreateNewComment(event: FormEvent<HTMLFormElement>){ | |
| event.preventDefault(); | |
| if(event.nativeEvent.submitter.name === "Cancel") { | |
| setIsCreatingComment(!IsCreatingComment); | |
| } else if(event.nativeEvent.submitter.name === "Publish") { | |
| setCurrentComments([...CurrentComments, { | |
| UserName: 'Juan Garcia', | |
| ProfilePic: 'https://avatars.githubusercontent.com/u/61752887?v=4', | |
| IsTheCurrentUser: true, | |
| PublishTime: 0, | |
| Content: TextareaValue, | |
| LikesAmount: 0, | |
| Id: CurrentComments?.length as number + 1, | |
| }]); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment