Skip to content

Commit 86153e9

Browse files
edited some more features
1 parent d27d8b2 commit 86153e9

File tree

2 files changed

+87
-13
lines changed

2 files changed

+87
-13
lines changed

app.js

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,14 @@ async function joinSwarm(seedBuffer) {
105105
}
106106

107107
function sendMessage(e) {
108+
e.preventDefault();
108109
const message = document.querySelector("#message").value;
109110
document.querySelector("#message").value = "";
110-
e.preventDefault();
111111

112-
const name = userName || "You"; // Use the sender's name or 'You'
112+
const name =
113+
userName || b4a.toString(swarm.keyPair.publicKey, "hex").substr(0, 6); // Use the sender's name or 'You'
113114

114-
onMessageAdded(name, message); // Display the message in the sender's system
115+
onMessageAdded("You", message); // Display the message in the sender's system
115116

116117
// Prepare the message data as an object
117118
const messageData = {
@@ -134,17 +135,42 @@ function onMessageAdded(from, message) {
134135
// Create the message element
135136
const $message = document.createElement("p");
136137
$message.textContent = message;
137-
$message.classList.add("message-item");
138+
$message.classList.add(
139+
from != "You" ? "message-item-right" : "message-item-left"
140+
);
138141

139142
// Create the sender element
140143
const $sender = document.createElement("p");
141144
$sender.textContent = from;
142-
$sender.classList.add("by");
145+
$sender.classList.add(from != "You" ? "by-right" : "by-left");
143146

144147
// Append message and sender to the container div
145148
$messageDiv.appendChild($message);
146149
$messageDiv.appendChild($sender);
147150

148151
// Append the container div to the #messages
149-
document.querySelector("#messages").appendChild($messageDiv);
152+
const messagesContainer = document.querySelector("#messages");
153+
messagesContainer.appendChild($messageDiv);
154+
155+
messagesContainer.scrollTop = messagesContainer.scrollHeight;
150156
}
157+
158+
// Message Edit
159+
document.querySelector("#message").addEventListener("keydown", (e) => {
160+
if (e.key === "Enter" && e.shiftKey) {
161+
e.preventDefault();
162+
163+
const messageInput = document.querySelector("#message");
164+
const cursorPosition = messageInput.selectionStart;
165+
166+
const textBefore = messageInput.value.substring(0, cursorPosition);
167+
const textAfter = messageInput.value.substring(cursorPosition);
168+
169+
// Update the message input value with a newline at the current cursor position
170+
messageInput.value = textBefore + "\n" + textAfter;
171+
172+
// Move the cursor to the correct position after the newline
173+
messageInput.selectionStart = messageInput.selectionEnd =
174+
cursorPosition + 1;
175+
}
176+
});

index.html

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,35 +146,69 @@
146146
height: 0px; /* Adjust the height of the horizontal scrollbar */
147147
}
148148

149-
.message-item {
149+
.message-item-left {
150150
padding-inline: 14px;
151-
padding-block: 10px;
151+
padding-block: 6px;
152152
margin-bottom: 5px;
153-
background-color: #3c3d37;
153+
background-color: #3c3d3756;
154154
border-radius: 10px;
155155
border-bottom-left-radius: 0;
156156
width: fit-content;
157157
border: 0.4px solid #bbb;
158158
max-width: 60%;
159159
color: #ecdfcc;
160+
backdrop-filter: blur(20px);
161+
align-self: flex-start;
162+
}
163+
.message-item-right {
164+
padding-inline: 14px;
165+
padding-block: 6px;
166+
margin-bottom: 5px;
167+
background-color: #3c3d3756;
168+
border-radius: 10px;
169+
border-bottom-right-radius: 0;
170+
width: fit-content;
171+
border: 0.4px solid #bbb;
172+
max-width: 60%;
173+
color: #ecdfcc;
174+
backdrop-filter: blur(20px);
175+
align-self: flex-end;
160176
}
161177
.hidden {
162178
display: none !important;
163179
}
164-
.by {
180+
.by-left {
165181
font-size: 10px;
166182
font-weight: 300;
167183
color: #ecdfcc;
168-
background-color: #3c3d37;
184+
background-color: #2e073f;
169185
width: fit-content;
170186
padding-inline: 10px;
171187
padding-block: 3px;
172188
border-radius: 50px;
173189
border-top-left-radius: 0;
174-
border: 0.4px solid #bbb;
190+
border: 0px solid #bbb;
191+
align-self: flex-start;
192+
}
193+
.by-right {
194+
font-size: 10px;
195+
font-weight: 300;
196+
color: #ecdfcc;
197+
background-color: #2e073f;
198+
width: fit-content;
199+
padding-inline: 10px;
200+
padding-block: 3px;
201+
border-radius: 50px;
202+
border-top-left-radius: 0;
203+
border: 0px solid #bbb;
204+
align-self: flex-end;
175205
}
176206
.message--div {
177207
margin-block: 10px;
208+
width: 96%;
209+
position: relative;
210+
display: flex;
211+
flex-direction: column;
178212
}
179213
/* Pop Up */
180214
.popup {
@@ -216,12 +250,26 @@
216250
cursor: pointer;
217251
}
218252
.logo {
219-
width: 14px;
253+
width: 20px;
254+
}
255+
.blob {
256+
width: 300px;
257+
height: 300px;
258+
border-radius: 50%;
259+
position: fixed;
260+
z-index: -1;
261+
filter: blur(100px);
220262
}
221263
</style>
222264
<script type="module" src="./app.js"></script>
223265
</head>
224266
<body>
267+
<div
268+
class="blob"
269+
style="background-color: #7a1cac94; top: -40px; left: -100px"></div>
270+
<div
271+
class="blob"
272+
style="background-color: #eb367894; bottom: -250px; right: 0px"></div>
225273
<div id="bar"><pear-ctrl></pear-ctrl></div>
226274
<main>
227275
<button class="change--name">

0 commit comments

Comments
 (0)