diff --git a/.gitignore b/.gitignore
index 45e876d..b48e935 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
node_modules/
client/node_modules/
server/node_modules/
+*.stationenv/
+*.env
+.DS_Store
\ No newline at end of file
diff --git a/client/.env.example b/client/.env.example
new file mode 100644
index 0000000..9b4e331
--- /dev/null
+++ b/client/.env.example
@@ -0,0 +1 @@
+VITE_API_URL=http://localhost:5000
\ No newline at end of file
diff --git a/client/src/App.jsx b/client/src/App.jsx
index 7384d5c..2e9d407 100644
--- a/client/src/App.jsx
+++ b/client/src/App.jsx
@@ -4,18 +4,20 @@ import Home from './pages/Home';
import Courses from './pages/Courses';
import Quiz from './pages/Quiz';
import Navbar from './components/Navbar';
+import Profile from './pages/Profile';
function App() {
return (
- <>
-
-
- } />
- } />
- } />
-
- >
- );
+ <>
+
+
+ } />
+ } />
+ } />
+ } />
+
+ >
+ );
}
export default App;
diff --git a/client/src/index.css b/client/src/index.css
index 6959f2a..65c3ab6 100644
--- a/client/src/index.css
+++ b/client/src/index.css
@@ -5,9 +5,27 @@
border: 2px solid red;
}
+.red-underline {
+ text-decoration: underline;
+ text-decoration-color: red;
+}
+
+.post-card {
+ margin-bottom: 15px;
+ border: 1px solid #ccc;
+ padding: 10px;
+ cursor: pointer;
+ transition: background-color 0.2s ease;
+ background-color: white; /* default */
+}
+
+.post-card:hover {
+ background-color: rgba(245, 245, 245, 0.7);
+}
+
body {
margin: 0;
font-family: Arial, sans-serif;
}
-
\ No newline at end of file
+
diff --git a/client/src/pages/Profile.jsx b/client/src/pages/Profile.jsx
new file mode 100644
index 0000000..8b8576d
--- /dev/null
+++ b/client/src/pages/Profile.jsx
@@ -0,0 +1,47 @@
+import { useEffect, useState } from "react";
+import { Link, useParams } from "react-router-dom";
+// import { useParams } from "react-router-dom";
+
+function Profile() {
+ const { username } = useParams();
+ const [user, setUser] = useState(null);
+ const API_URL = import.meta.env.VITE_API_URL;
+
+ useEffect(() => {
+ fetch(`${API_URL}/api/users/${username}`)
+ .then((res) => res.json())
+ .then((data) => {
+ console.log("Fetched user:", data);
+ setUser(data);
+ })
+ .catch((err) => console.error("Error fetching user:", err));
+ }, [username]);
+
+ if (!user) return
Loading...
;
+
+ return (
+
+
{user.username}s Profile
+
Number of posts: {user.post_count}
+
Posts
+ {user.posts.length === 0 ? (
+
No posts yet
+ ) : (
+ user.posts.map((post) => (
+
+
+
{post.title}
+
{post.content}
+
+
+ ))
+ )}
+
+ );
+}
+
+export default Profile;
diff --git a/server/app.py b/server/app.py
index 5df866b..b487763 100644
--- a/server/app.py
+++ b/server/app.py
@@ -58,6 +58,21 @@ def create_post():
posts[post_id] = post
return jsonify(post), 201
+@app.route('/api/users/', methods=['GET'])
+def get_user_profile(username):
+ if username not in users:
+ return jsonify({'error':'User not found'}), 404
+ user_posts = [
+ post for post in posts.values()
+ if post['author'] == username
+ ]
+
+ return jsonify({
+ 'username': username,
+ 'posts': user_posts,
+ 'post_count': len(user_posts)
+ })
+
if __name__ == '__main__':
import os
port = int(os.environ.get('PORT', 5000))