ChandimaPrabath commited on
Commit
63fbd68
·
1 Parent(s): ccc7b17
.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(`https://Hans-R-D-nexus-services.hf.space/search?query=${query}`);
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
- <div style={{ width: '250px', backgroundColor: '#333', padding: '20px' }}>
31
- <h3 style={{ color: '#fff' }}>Select Recipient</h3>
32
- <input
33
- type="text"
34
- placeholder="Search Users..."
35
- value={searchQuery}
36
- onChange={handleSearchChange}
37
- style={searchInputStyle}
38
- />
39
- <ul style={{ listStyleType: 'none', padding: 0 }}>
40
- {filteredUsers.map((recipient, index) => (
41
- <li key={index} style={{ color: '#fff', cursor: 'pointer' }}>
42
- <span
43
- style={{ textDecoration: 'none', color: '#fff' }}
44
- onClick={() => handleUserSelect(recipient)}
45
- >
46
- {recipient}
47
- </span>
48
- </li>
49
- ))}
50
- </ul>
51
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 socket = new WebSocket('wss://Hans-R-D-nexus-relay.hf.space/ws');
 
 
 
 
 
 
 
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.');