-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
265 lines (239 loc) · 8.77 KB
/
index.html
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LinkUp - Czat</title>
<link rel="stylesheet" href="style.css">
<style>
/* Wygląd zgodny z obrazem */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
height: 100vh;
}
.container {
display: flex;
width: 100%;
}
.sidebar {
background-color: #2b2e4a;
color: white;
padding: 20px;
width: 300px;
}
.chat-window {
flex: 1;
display: flex;
flex-direction: column;
background-color: #f1f1f1;
}
.chat-header {
background-color: #546de5;
color: white;
padding: 10px;
display: flex;
justify-content: space-between;
align-items: center;
}
.chat-content {
flex: 1;
padding: 10px;
overflow-y: auto;
}
.chat-input {
background-color: white;
padding: 10px;
display: flex;
justify-content: space-between;
}
.chat-input input {
width: 80%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
.chat-input button {
background-color: #546de5;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
ul {
list-style: none;
padding: 0;
}
li {
padding: 10px;
border-bottom: 1px solid #ccc;
}
button {
margin-top: 10px;
background-color: #546de5;
color: white;
padding: 10px;
border: none;
cursor: pointer;
border-radius: 5px;
}
button:hover {
background-color: #3949ab;
}
</style>
</head>
<body>
<div class="container">
<div class="sidebar">
<h3>Grupy</h3>
<ul id="groupsList">
<!-- Tutaj pojawią się grupy -->
</ul>
<button id="addGroupButton">Dodaj Grupę</button>
<h3>Znajomi</h3>
<ul id="friendsList">
<!-- Tutaj pojawią się znajomi -->
</ul>
<h3>Zaproszenia do znajomych</h3>
<ul id="friendRequestsList">
<!-- Tutaj pojawią się zaproszenia -->
</ul>
<button id="addFriendButton">Dodaj Znajomego</button>
</div>
<div class="chat-window">
<div class="chat-header">
<h2 id="currentGroup">Wybierz grupę</h2>
<button id="logoutButton">Wyloguj się</button>
</div>
<div class="chat-content">
<ul id="messages">
<!-- Tutaj pojawią się wiadomości -->
</ul>
</div>
<div class="chat-input">
<input type="text" id="messageInput" placeholder="Wpisz wiadomość">
<button id="sendMessageButton">Wyślij</button>
</div>
</div>
</div>
<script>
const groupsList = document.getElementById('groupsList');
const friendsList = document.getElementById('friendsList');
const friendRequestsList = document.getElementById('friendRequestsList');
const messageInput = document.getElementById('messageInput');
const sendMessageButton = document.getElementById('sendMessageButton');
const messagesList = document.getElementById('messages');
const addGroupButton = document.getElementById('addGroupButton');
const addFriendButton = document.getElementById('addFriendButton');
const currentGroupHeader = document.getElementById('currentGroup');
const logoutButton = document.getElementById('logoutButton');
let currentGroup = null;
let groups = JSON.parse(localStorage.getItem('groups')) || [];
let friends = JSON.parse(localStorage.getItem('friends')) || [];
let friendRequests = JSON.parse(localStorage.getItem('friendRequests')) || [];
// Wyświetlanie grup
function renderGroups() {
groupsList.innerHTML = '';
groups.forEach((group, index) => {
const groupItem = document.createElement('li');
groupItem.textContent = group.name;
groupItem.addEventListener('click', () => {
selectGroup(index);
});
groupsList.appendChild(groupItem);
});
}
// Wyświetlanie znajomych
function renderFriends() {
friendsList.innerHTML = '';
friends.forEach(friend => {
const friendItem = document.createElement('li');
friendItem.textContent = friend;
friendsList.appendChild(friendItem);
});
}
// Wyświetlanie zaproszeń do znajomych
function renderFriendRequests() {
friendRequestsList.innerHTML = '';
friendRequests.forEach((request, index) => {
const requestItem = document.createElement('li');
requestItem.textContent = request;
const acceptButton = document.createElement('button');
acceptButton.textContent = 'Akceptuj';
acceptButton.addEventListener('click', () => {
acceptFriendRequest(index);
});
requestItem.appendChild(acceptButton);
friendRequestsList.appendChild(requestItem);
});
}
// Akceptowanie zaproszenia do znajomych
function acceptFriendRequest(index) {
const acceptedFriend = friendRequests[index];
friends.push(acceptedFriend);
friendRequests.splice(index, 1);
renderFriends();
renderFriendRequests();
localStorage.setItem('friends', JSON.stringify(friends));
localStorage.setItem('friendRequests', JSON.stringify(friendRequests));
}
// Wybieranie grupy
function selectGroup(index) {
currentGroup = groups[index];
currentGroupHeader.textContent = currentGroup.name;
renderMessages();
}
// Wyświetlanie wiadomości w wybranej grupie
function renderMessages() {
messagesList.innerHTML = '';
if (currentGroup) {
currentGroup.messages.forEach(message => {
const messageItem = document.createElement('li');
messageItem.textContent = message;
messagesList.appendChild(messageItem);
});
}
}
// Dodawanie wiadomości do grupy
sendMessageButton.addEventListener('click', () => {
const messageText = messageInput.value.trim();
if (messageText && currentGroup) {
currentGroup.messages.push(messageText);
messageInput.value = '';
renderMessages();
localStorage.setItem('groups', JSON.stringify(groups));
}
});
// Dodawanie grupy
addGroupButton.addEventListener('click', () => {
const groupName = prompt('Podaj nazwę grupy:');
if (groupName) {
groups.push({ name: groupName, messages: [] });
renderGroups();
localStorage.setItem('groups', JSON.stringify(groups));
}
});
// Dodawanie znajomego
addFriendButton.addEventListener('click', () => {
const friendName = prompt('Podaj nazwę użytkownika znajomego:');
if (friendName) {
friendRequests.push(friendName);
renderFriendRequests();
localStorage.setItem('friendRequests', JSON.stringify(friendRequests));
}
});
// Obsługa wylogowania
logoutButton.addEventListener('click', () => {
alert('Wylogowano!');
window.location.href = 'login.html'; // Przekierowanie na stronę logowania
});
// Inicjalizacja
renderGroups();
renderFriends();
renderFriendRequests();
</script>
</body>
</html>