Commit
·
63fbd68
1
Parent(s):
ccc7b17
get env
Browse files- .gitignore +1 -0
- frontend/app/Sidebar.js +74 -24
- frontend/app/WebSocketContext.js +8 -1
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.env.local
|
frontend/app/Sidebar.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
// Sidebar.js
|
| 2 |
import { useState } from 'react';
|
| 3 |
import { useRouter } from 'next/navigation';
|
| 4 |
|
|
@@ -9,13 +8,26 @@ export default function Sidebar({
|
|
| 9 |
handleUserSelect,
|
| 10 |
setFilteredUsers,
|
| 11 |
}) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
const handleSearchChange = async (e) => {
|
| 13 |
const query = e.target.value;
|
| 14 |
setSearchQuery(query);
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
if (query.length > 2) {
|
| 17 |
try {
|
| 18 |
-
const response = await fetch(
|
| 19 |
const data = await response.json();
|
| 20 |
setFilteredUsers(data);
|
| 21 |
} catch (error) {
|
|
@@ -27,28 +39,66 @@ export default function Sidebar({
|
|
| 27 |
};
|
| 28 |
|
| 29 |
return (
|
| 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 |
|
|
|
|
|
|
|
| 1 |
import { useState } from 'react';
|
| 2 |
import { useRouter } from 'next/navigation';
|
| 3 |
|
|
|
|
| 8 |
handleUserSelect,
|
| 9 |
setFilteredUsers,
|
| 10 |
}) {
|
| 11 |
+
const [isSidebarOpen, setIsSidebarOpen] = useState(false);
|
| 12 |
+
|
| 13 |
+
const toggleSidebar = () => {
|
| 14 |
+
setIsSidebarOpen((prev) => !prev);
|
| 15 |
+
};
|
| 16 |
+
|
| 17 |
const handleSearchChange = async (e) => {
|
| 18 |
const query = e.target.value;
|
| 19 |
setSearchQuery(query);
|
| 20 |
|
| 21 |
+
const servicesUrl = process.env.NEXT_PUBLIC_SERVICES_URL;
|
| 22 |
+
|
| 23 |
+
if (!servicesUrl) {
|
| 24 |
+
console.error('Environment variable NEXT_PUBLIC_SERVICES_URL is not defined.');
|
| 25 |
+
return;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
if (query.length > 2) {
|
| 29 |
try {
|
| 30 |
+
const response = await fetch(`${servicesUrl}/search?query=${query}`);
|
| 31 |
const data = await response.json();
|
| 32 |
setFilteredUsers(data);
|
| 33 |
} catch (error) {
|
|
|
|
| 39 |
};
|
| 40 |
|
| 41 |
return (
|
| 42 |
+
<>
|
| 43 |
+
{/* Hamburger Menu Button */}
|
| 44 |
+
<button
|
| 45 |
+
onClick={toggleSidebar}
|
| 46 |
+
style={{
|
| 47 |
+
position: 'fixed',
|
| 48 |
+
top: '10px',
|
| 49 |
+
left: isSidebarOpen ? '210px' : '10px',
|
| 50 |
+
zIndex: 1000,
|
| 51 |
+
backgroundColor: '#4b2e83',
|
| 52 |
+
color: '#fff',
|
| 53 |
+
border: 'none',
|
| 54 |
+
borderRadius: '5px',
|
| 55 |
+
padding: '10px',
|
| 56 |
+
cursor: 'pointer',
|
| 57 |
+
transition: 'left 0.3s ease',
|
| 58 |
+
}}
|
| 59 |
+
>
|
| 60 |
+
☰
|
| 61 |
+
</button>
|
| 62 |
+
|
| 63 |
+
{/* Sidebar */}
|
| 64 |
+
<div
|
| 65 |
+
style={{
|
| 66 |
+
position: 'fixed',
|
| 67 |
+
top: 0,
|
| 68 |
+
left: isSidebarOpen ? 0 : '-260px', // Sidebar slides out of view when collapsed
|
| 69 |
+
width: '250px',
|
| 70 |
+
height: '100%',
|
| 71 |
+
backgroundColor: '#333',
|
| 72 |
+
padding: '20px',
|
| 73 |
+
boxShadow: '2px 0 5px rgba(0, 0, 0, 0.5)',
|
| 74 |
+
transition: 'left 0.3s ease',
|
| 75 |
+
zIndex: 999,
|
| 76 |
+
}}
|
| 77 |
+
>
|
| 78 |
+
<h3 style={{ color: '#fff', marginBottom: '20px' }}>Select Recipient</h3>
|
| 79 |
+
|
| 80 |
+
<input
|
| 81 |
+
type="text"
|
| 82 |
+
placeholder="Search Users..."
|
| 83 |
+
value={searchQuery}
|
| 84 |
+
onChange={handleSearchChange}
|
| 85 |
+
style={searchInputStyle}
|
| 86 |
+
/>
|
| 87 |
+
|
| 88 |
+
<ul style={{ listStyleType: 'none', padding: 0 }}>
|
| 89 |
+
{filteredUsers.map((recipient, index) => (
|
| 90 |
+
<li key={index} style={{ color: '#fff', cursor: 'pointer', marginBottom: '10px' }}>
|
| 91 |
+
<span
|
| 92 |
+
style={{ textDecoration: 'none', color: '#fff' }}
|
| 93 |
+
onClick={() => handleUserSelect(recipient)}
|
| 94 |
+
>
|
| 95 |
+
{recipient}
|
| 96 |
+
</span>
|
| 97 |
+
</li>
|
| 98 |
+
))}
|
| 99 |
+
</ul>
|
| 100 |
+
</div>
|
| 101 |
+
</>
|
| 102 |
);
|
| 103 |
}
|
| 104 |
|
frontend/app/WebSocketContext.js
CHANGED
|
@@ -11,7 +11,14 @@ export const WebSocketProvider = ({ children }) => {
|
|
| 11 |
const [status, setStatus] = useState('Disconnected');
|
| 12 |
|
| 13 |
useEffect(() => {
|
| 14 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
socket.onopen = () => {
|
| 17 |
console.log('WebSocket connection opened.');
|
|
|
|
| 11 |
const [status, setStatus] = useState('Disconnected');
|
| 12 |
|
| 13 |
useEffect(() => {
|
| 14 |
+
const relayUrl = process.env.NEXT_PUBLIC_RELAY_URL;
|
| 15 |
+
|
| 16 |
+
if (!relayUrl) {
|
| 17 |
+
console.error('Environment variable NEXT_PUBLIC_RELAY_URL is not defined.');
|
| 18 |
+
return;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
const socket = new WebSocket(relayUrl);
|
| 22 |
|
| 23 |
socket.onopen = () => {
|
| 24 |
console.log('WebSocket connection opened.');
|