forked from snxraven/LinkUp-P2P-Chat
Update
This commit is contained in:
parent
7ba32ea7c0
commit
b62636ed0e
21
app.js
21
app.js
@ -6,7 +6,6 @@ import Localdrive from 'localdrive';
|
||||
import fs from 'fs';
|
||||
import Hyperdrive from 'hyperdrive';
|
||||
import Corestore from 'corestore';
|
||||
|
||||
const store = new Corestore('./storage');
|
||||
const drive = new Hyperdrive(store);
|
||||
|
||||
@ -236,8 +235,13 @@ function sendMessage(e) {
|
||||
}
|
||||
}
|
||||
|
||||
// appends element to #messages element with content set to sender and message
|
||||
function scrollToBottom() {
|
||||
var container = document.getElementById("messages-container");
|
||||
container.scrollTop = container.scrollHeight;
|
||||
}
|
||||
|
||||
function onMessageAdded(from, message, avatar) {
|
||||
|
||||
const $div = document.createElement('div');
|
||||
$div.classList.add('message');
|
||||
|
||||
@ -255,21 +259,18 @@ function onMessageAdded(from, message, avatar) {
|
||||
const $text = document.createElement('div');
|
||||
$text.classList.add('message-text');
|
||||
|
||||
// Split message by line breaks and create a new paragraph for each line
|
||||
const lines = message.split('\n');
|
||||
lines.forEach(line => {
|
||||
const $line = document.createElement('p');
|
||||
$line.textContent = line;
|
||||
$text.appendChild($line);
|
||||
});
|
||||
// Render Markdown content
|
||||
const md = window.markdownit();
|
||||
$text.innerHTML = md.render(message);
|
||||
|
||||
$content.appendChild($header);
|
||||
$content.appendChild($text);
|
||||
$div.appendChild($content);
|
||||
|
||||
document.querySelector('#messages').appendChild($div);
|
||||
}
|
||||
scrollToBottom();
|
||||
|
||||
}
|
||||
async function updateIcon(username, avatarBuffer) {
|
||||
// Update the icon in the local HTML if necessary
|
||||
// This can be adjusted as per your needs
|
||||
|
@ -6,6 +6,7 @@
|
||||
<title>LinkUp</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
<script type="module" src="./app.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/markdown-it/dist/markdown-it.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
@ -53,7 +54,9 @@
|
||||
<!-- User list will be populated here -->
|
||||
</div>
|
||||
</div>
|
||||
<div id="messages-container">
|
||||
<div id="messages"></div>
|
||||
</div>
|
||||
<form id="message-form">
|
||||
<textarea id="message" rows="4"></textarea>
|
||||
<input type="submit" value="Send" />
|
||||
|
@ -27,6 +27,7 @@
|
||||
"hyperdrive": "^11.8.1",
|
||||
"hyperswarm": "^4.7.14",
|
||||
"localdrive": "^1.11.4",
|
||||
"marked": "^12.0.2",
|
||||
"serve-drive": "^5.0.8"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user