diff --git a/package.json b/package.json index fda3351..9bf0eaf 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "typescript": "~3.7.2" }, "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", + "start": "set NODE_OPTIONS=--openssl-legacy-provider && react-scripts start", + "build": "set NODE_OPTIONS=--openssl-legacy-provider && react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, diff --git a/src/App.tsx b/src/App.tsx index 1880d7c..50150b3 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,13 +2,14 @@ import React from 'react'; import Layout from './components/Layout'; import GlobalStyles from './styles/GlobalStyles'; +import { ThemeProvider } from './contexts/ThemeContext'; function App() { return ( - <> + - + ); } diff --git a/src/components/Comments/index.tsx b/src/components/Comments/index.tsx new file mode 100644 index 0000000..f6d375c --- /dev/null +++ b/src/components/Comments/index.tsx @@ -0,0 +1,147 @@ +import React, { useState } from 'react'; +import { + Container, + CommentItem, + Avatar, + Content, + Header, + Author, + Time, + Text, + CommentForm, + TextArea, + SubmitButton, + ShowCommentsButton, + CommentsCount, +} from './styles'; + +interface Comment { + id: string; + author: string; + avatar: string; + text: string; + time: string; +} + +interface CommentsProps { + tweetId: string; + commentsCount: number; + onCommentAdd: (tweetId: string, comment: Comment) => void; + comments: Comment[]; + isExpanded: boolean; + onToggleComments: () => void; +} + +const Comments: React.FC = ({ + tweetId, + commentsCount, + onCommentAdd, + comments, + isExpanded, + onToggleComments, +}) => { + const [commentText, setCommentText] = useState(''); + const [showForm, setShowForm] = useState(false); + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + if (commentText.trim()) { + const newComment: Comment = { + id: Date.now().toString(), + author: 'Elton Lazzarin', + avatar: 'https://avatars1.githubusercontent.com/u/53025782?s=400&u=f1ffa8eaccb8545222b7c642532161f11e74a03d&v=4', + text: commentText.trim(), + time: 'now', + }; + + onCommentAdd(tweetId, newComment); + setCommentText(''); + setShowForm(false); + } + }; + + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) { + handleSubmit(e); + } + }; + + return ( + + {commentsCount > 0 && ( + + + {isExpanded ? 'Hide' : 'Show'} {commentsCount} comment{commentsCount !== 1 ? 's' : ''} + + + )} + + {isExpanded && ( + <> + {comments.map((comment) => ( + + + {comment.author} + + +
+ {comment.author} + +
+ {comment.text} +
+
+ ))} + + )} + + {showForm ? ( + + + Your avatar + +
+