File size: 13,479 Bytes
d8b1d97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Community - WebBag Wonders</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://unpkg.com/react@18/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body class="bg-gray-50">
    <div id="root"></div>

    <script type="text/babel">
        const { useState } = React;

        function Navbar() {
            return (
                <nav className="bg-white shadow-sm py-4 px-6 flex items-center justify-between sticky top-0 z-50">
                    <div className="flex items-center space-x-2">
                        <i className="fas fa-briefcase text-blue-500 text-2xl"></i>
                        <span className="text-xl font-semibold text-gray-800">WebBag Wonders</span>
                    </div>
                    <div className="flex-1 max-w-md mx-4">
                        <div className="relative">
                            <input 
                                type="text" 
                                placeholder="Search community..." 
                                className="w-full py-2 px-4 rounded-full border border-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-300"
                            />
                            <button className="absolute right-3 top-2 text-gray-400">
                                <i className="fas fa-search"></i>
                            </button>
                        </div>
                    </div>
                    <div className="flex items-center space-x-4">
                        <button className="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-full text-sm font-medium">
                            Sign In
                        </button>
                        <div className="w-10 h-10 rounded-full bg-gray-200 flex items-center justify-center">
                            <i className="fas fa-user text-gray-600"></i>
                        </div>
                    </div>
                </nav>
            );
        }

        function Comment({ comment }) {
            return (
                <div className="ml-6 mt-4 pl-4 border-l-2 border-gray-200">
                    <div className="flex items-center mb-2">
                        <div className="w-8 h-8 rounded-full bg-gray-300 flex items-center justify-center mr-2">
                            <i className="fas fa-user text-gray-600 text-xs"></i>
                        </div>
                        <span className="text-sm font-medium text-gray-800">{comment.author}</span>
                    </div>
                    <p className="text-gray-600 text-sm">{comment.text}</p>
                </div>
            );
        }

        function Post({ post }) {
            const [isLiked, setIsLiked] = useState(false);
            const [likeCount, setLikeCount] = useState(post.likes);
            const [showComments, setShowComments] = useState(false);
            const [newComment, setNewComment] = useState("");
            
            const handleLike = () => {
                setIsLiked(!isLiked);
                setLikeCount(isLiked ? likeCount - 1 : likeCount + 1);
            };
            
            const handleAddComment = (e) => {
                e.preventDefault();
                if (newComment.trim()) {
                    post.comments.push({
                        id: Date.now(),
                        author: "You",
                        text: newComment
                    });
                    setNewComment("");
                }
            };

            return (
                <div className="bg-white rounded-xl p-6 shadow-md border border-gray-100 mb-6">
                    <div className="flex items-center mb-4">
                        <div className="w-10 h-10 rounded-full bg-gray-300 flex items-center justify-center mr-3">
                            <i className="fas fa-user text-gray-600"></i>
                        </div>
                        <div>
                            <h4 className="font-medium text-gray-800">{post.author}</h4>
                            <p className="text-gray-500 text-xs">{post.timeAgo}</p>
                        </div>
                    </div>
                    
                    <p className="text-gray-700 mb-4">{post.content}</p>
                    
                    {post.image && (
                        <img 
                            src={post.image} 
                            alt="Post" 
                            className="w-full rounded-lg mb-4"
                        />
                    )}
                    
                    <div className="flex items-center text-gray-500 text-sm">
                        <button 
                            onClick={handleLike}
                            className={`flex items-center mr-4 ${isLiked ? 'text-blue-500' : ''}`}
                        >
                            <i className={`fas fa-heart mr-1 ${isLiked ? 'text-blue-500' : ''}`}></i>
                            <span>{likeCount}</span>
                        </button>
                        <button 
                            onClick={() => setShowComments(!showComments)}
                            className="flex items-center"
                        >
                            <i className="fas fa-comment mr-1"></i>
                            <span>{post.comments.length}</span>
                        </button>
                    </div>
                    
                    {showComments && (
                        <div className="mt-4">
                            <form onSubmit={handleAddComment} className="mb-4 flex">
                                <input
                                    type="text"
                                    value={newComment}
                                    onChange={(e) => setNewComment(e.target.value)}
                                    placeholder="Add a comment..."
                                    className="flex-1 py-2 px-3 border border-gray-300 rounded-l-lg focus:outline-none focus:ring-1 focus:ring-blue-300"
                                />
                                <button 
                                    type="submit"
                                    className="bg-blue-500 text-white px-4 py-2 rounded-r-lg hover:bg-blue-600"
                                >
                                    Post
                                </button>
                            </form>
                            
                            {post.comments.map(comment => (
                                <Comment key={comment.id} comment={comment} />
                            ))}
                        </div>
                    )}
                </div>
            );
        }

        function CommunityPage() {
            const [posts, setPosts] = useState([
                {
                    id: 1,
                    author: "JaneDoe",
                    timeAgo: "2 hours ago",
                    content: "Just discovered this amazing website for learning React! Check it out at https://react-tutorial.app",
                    likes: 15,
                    comments: [
                        { id: 1, author: "JohnSmith", text: "Thanks for sharing!" },
                        { id: 2, author: "DevUser", text: "This is really helpful!" }
                    ]
                },
                {
                    id: 2,
                    author: "TechEnthusiast",
                    timeAgo: "5 hours ago",
                    content: "What's your favorite development tool or extension? Mine is VSCode with the GitHub Copilot!",
                    likes: 8,
                    comments: [
                        { id: 3, author: "CodeMaster", text: "I love using Postman for API testing" },
                        { id: 4, author: "WebDev", text: "Tailwind CSS is my go-to for styling" }
                    ],
                    image: "http://static.photos/technology/640x360/1"
                },
                {
                    id: 3,
                    author: "BookLover",
                    timeAgo: "1 day ago",
                    content: "Just finished reading 'Clean Code' by Robert Martin. Highly recommend for all developers!",
                    likes: 22,
                    comments: [
                        { id: 5, author: "ProgrammingFan", text: "One of my favorites too!" }
                    ],
                    image: "http://static.photos/books/640x360/2"
                }
            ]);

            const [newPost, setNewPost] = useState("");

            const handleAddPost = (e) => {
                e.preventDefault();
                if (newPost.trim()) {
                    setPosts([
                        {
                            id: Date.now(),
                            author: "You",
                            timeAgo: "Just now",
                            content: newPost,
                            likes: 0,
                            comments: []
                        },
                        ...posts
                    ]);
                    setNewPost("");
                }
            };

            return (
                <div className="container mx-auto px-4 py-8">
                    <h1 className="text-2xl font-bold text-gray-800 mb-6">Community Posts</h1>
                    
                    <form onSubmit={handleAddPost} className="bg-white rounded-xl p-6 shadow-md border border-gray-100 mb-6">
                        <textarea
                            value={newPost}
                            onChange={(e) => setNewPost(e.target.value)}
                            placeholder="Share something with the community..."
                            className="w-full p-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-1 focus:ring-blue-300 mb-3"
                            rows="3"
                        ></textarea>
                        <div className="flex justify-end">
                            <button 
                                type="submit"
                                className="bg-blue-500 text-white px-6 py-2 rounded-lg hover:bg-blue-600"
                            >
                                Post
                            </button>
                        </div>
                    </form>
                    
                    <div>
                        {posts.map(post => (
                            <Post key={post.id} post={post} />
                        ))}
                    </div>
                </div>
            );
        }

        function Footer() {
            return (
                <footer className="bg-white border-t border-gray-200 py-8 mt-12">
                    <div className="container mx-auto px-4">
                        <div className="flex flex-col md:flex-row justify-between items-center">
                            <div className="mb-4 md:mb-0">
                                <div className="flex items-center space-x-2">
                                    <i className="fas fa-briefcase text-blue-500 text-xl"></i>
                                    <span className="text-lg font-semibold text-gray-800">WebBag Wonders</span>
                                </div>
                                <p className="text-gray-500 text-sm mt-2">Your digital companion for all things web</p>
                            </div>
                            <div className="flex space-x-6">
                                <a href="#" className="text-gray-500 hover:text-blue-500">
                                    <i className="fab fa-twitter"></i>
                                </a>
                                <a href="#" className="text-gray-500 hover:text-blue-500">
                                    <i className="fab fa-facebook"></i>
                                </a>
                                <a href="#" className="text-gray-500 hover:text-blue-500">
                                    <i className="fab fa-instagram"></i>
                                </a>
                                <a href="#" className="text-gray-500 hover:text-blue-500">
                                    <i className="fab fa-github"></i>
                                </a>
                            </div>
                        </div>
                        <div className="border-t border-gray-200 mt-6 pt-6 text-center text-gray-500 text-sm">
                            <p>© 2023 WebBag Wonders. All rights reserved.</p>
                        </div>
                    </div>
                </footer>
            );
        }

        function App() {
            return (
                <div className="min-h-screen flex flex-col">
                    <Navbar />
                    <CommunityPage />
                    <Footer />
                </div>
            );
        }

        ReactDOM.render(<App />, document.getElementById('root'));
    </script>
</body>
</html>