forked from microsoft/github-copilot-vibe-coding-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.jsx
More file actions
84 lines (74 loc) · 2.83 KB
/
Copy pathApp.jsx
File metadata and controls
84 lines (74 loc) · 2.83 KB
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
import { useState } from 'react';
import { useUsername } from './context/UsernameContext';
import PostList from './components/PostList';
import PostDetail from './components/PostDetail';
import CreatePostModal from './components/CreatePostModal';
import UsernameModal from './components/UsernameModal';
import APIStatusIndicator from './components/APIStatusIndicator';
import './App.css';
function App() {
const { username } = useUsername();
const [selectedPost, setSelectedPost] = useState(null);
const [showCreatePost, setShowCreatePost] = useState(false);
const [apiAvailable, setApiAvailable] = useState(true);
const [showUsernameModal, setShowUsernameModal] = useState(!username);
const handlePostCreated = () => {
setShowCreatePost(false);
window.location.reload();
};
return (
<div className="min-h-screen bg-gray-100">
<APIStatusIndicator onStatusChange={setApiAvailable} />
<div className="max-w-2xl mx-auto px-4 py-8">
<div className="mb-8 flex items-center justify-between">
<h1 className="text-4xl font-bold text-gray-900">Social Media</h1>
{username && (
<div className="flex items-center gap-4">
<span className="text-lg font-semibold text-gray-700">@{username}</span>
<button
onClick={() => setShowUsernameModal(true)}
className="bg-gray-500 text-white px-4 py-2 rounded-lg hover:bg-gray-600 text-sm"
>
Change Username
</button>
</div>
)}
</div>
{apiAvailable && username && (
<>
<PostList
onPostClick={setSelectedPost}
onCreatePostClick={() => setShowCreatePost(true)}
apiAvailable={apiAvailable}
/>
{selectedPost && (
<PostDetail
post={selectedPost}
onClose={() => setSelectedPost(null)}
apiAvailable={apiAvailable}
/>
)}
{showCreatePost && (
<CreatePostModal
isOpen={showCreatePost}
onClose={() => setShowCreatePost(false)}
onPostCreated={handlePostCreated}
/>
)}
</>
)}
{!apiAvailable && (
<div className="bg-red-50 border border-red-200 text-red-700 px-6 py-4 rounded-lg text-center">
<h2 className="text-xl font-bold mb-2">Backend API Unavailable</h2>
<p>
The application cannot connect to the backend API at http://localhost:8000. Please ensure the
API server is running and try again.
</p>
</div>
)}
</div>
<UsernameModal isOpen={showUsernameModal} onClose={() => setShowUsernameModal(false)} />
</div>
);
}
export default App;