Skip to content

Commit 7f6070a

Browse files
committed
Add Livestream page and update routing in App.js
1 parent b878e44 commit 7f6070a

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

src/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Account from './pages/Account';
1111
import React, { useEffect } from 'react';
1212
import Main from './pages/Main';
1313
import ChangeProfile from './controller/ChangeProfile';
14+
import Livestream from './pages/Livestream';
1415
function App() {
1516
useEffect(() => {
1617
document.title = "Video sharing";
@@ -28,6 +29,7 @@ function App() {
2829
<Route path="/profile" element={<Profile />} />
2930
<Route path="/main" element={<Main />} />
3031
<Route path="/change" element={<ChangeProfile />} />
32+
<Route path="/livestream" element={<Livestream />} />
3133
</Routes>
3234
</Router>
3335
);

src/components/NavbarApp.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ const NavbarApp = () => {
6464
<div className='auth-buttons'>
6565
{ !userToken?
6666
<div className='auth-buttons'>
67+
<button className="login-button" type="button" onClick={()=>{navigate('/livestream')}}>
68+
Phát trực tiếp
69+
</button>
6770
<button className="register-button" type="button" onClick={()=>{navigate('/register')}}>
6871
Đăng ký
6972
</button>

src/pages/Livestream.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import React, { useState } from "react";
2+
3+
// Hàm tạo mã sự kiện ngẫu nhiên gồm 5 ký tự
4+
const generateEventCode = () => {
5+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
6+
let result = '';
7+
for (let i = 0; i < 5; i++) {
8+
result += characters.charAt(Math.floor(Math.random() * characters.length));
9+
}
10+
return result;
11+
};
12+
13+
const Livestream = () => {
14+
const [eventCode, setEventCode] = useState(generateEventCode());
15+
const [message, setMessage] = useState('');
16+
const [chatMessages, setChatMessages] = useState([]);
17+
18+
// Hàm xử lý khi người dùng gửi tin nhắn
19+
const handleSendMessage = () => {
20+
if (message.trim()) {
21+
setChatMessages([...chatMessages, { text: message, timestamp: new Date().toLocaleTimeString() }]);
22+
setMessage('');
23+
}
24+
};
25+
26+
return (
27+
<div className="flex bg-[#f0f4f9] min-h-screen p-5">
28+
<div className="w-2/3 p-4 bg-white rounded-lg shadow-lg">
29+
<h1 className="text-2xl font-bold mb-4">Cài đặt sự kiện phát trực tiếp</h1>
30+
31+
{/* Mã sự kiện phát trực tiếp */}
32+
<div className="mb-6">
33+
<label className="block text-gray-700 font-semibold mb-2">Mã sự kiện phát trực tiếp:</label>
34+
<div className="flex items-center">
35+
<input
36+
type="text"
37+
value={eventCode}
38+
readOnly
39+
className="border border-gray-300 rounded-lg p-2 text-center font-mono text-lg w-[120px] bg-gray-100 mr-4"
40+
/>
41+
<button
42+
onClick={() => setEventCode(generateEventCode())}
43+
className="px-4 py-2 bg-blue-500 text-white font-semibold rounded-lg hover:bg-blue-600"
44+
>
45+
Tạo mã mới
46+
</button>
47+
</div>
48+
</div>
49+
50+
{/* Khung phát trực tiếp */}
51+
<div className="aspect-w-16 aspect-h-9 bg-black mb-4 rounded-lg">
52+
{/* Khung video giả lập */}
53+
<p className="text-center text-white font-bold text-xl">Khung Video Trực Tiếp</p>
54+
</div>
55+
56+
{/* Thông tin thêm */}
57+
<p className="text-gray-500 text-sm">Đang phát trực tiếp: Đây là khung video phát trực tiếp của bạn.</p>
58+
</div>
59+
60+
{/* Thanh trò chuyện trực tiếp */}
61+
<div className="w-1/3 ml-4 p-4 bg-white rounded-lg shadow-lg flex flex-col">
62+
<h2 className="text-xl font-bold mb-4">Trò chuyện trực tiếp</h2>
63+
64+
{/* Hiển thị tin nhắn trò chuyện */}
65+
<div className="flex-grow overflow-y-auto mb-4 border rounded-lg p-2 bg-gray-50">
66+
{chatMessages.length === 0 ? (
67+
<p className="text-gray-500 text-center">Chưa có tin nhắn nào.</p>
68+
) : (
69+
chatMessages.map((msg, index) => (
70+
<div key={index} className="mb-2">
71+
<p className="text-sm"><span className="font-semibold">Người dùng:</span> {msg.text}</p>
72+
<p className="text-xs text-gray-400">{msg.timestamp}</p>
73+
</div>
74+
))
75+
)}
76+
</div>
77+
78+
{/* Nhập và gửi tin nhắn */}
79+
<div className="flex items-center">
80+
<input
81+
type="text"
82+
value={message}
83+
onChange={(e) => setMessage(e.target.value)}
84+
placeholder="Nhập tin nhắn..."
85+
className="border rounded-lg p-2 flex-grow mr-2"
86+
/>
87+
<button
88+
onClick={handleSendMessage}
89+
className="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600"
90+
>
91+
Gửi
92+
</button>
93+
</div>
94+
</div>
95+
</div>
96+
);
97+
};
98+
99+
export default Livestream;

0 commit comments

Comments
 (0)