forked from retoor/snek
feat: convert JavaScript classes to ES modules with export/import across app and templates
Convert all JavaScript classes in app.js and schedule.js from implicit globals to ES module exports, add import statements in template scripts for the app instance, and mark all script tags with type="module" to enable module scoping. Also fix a potential null reference in web.html by using optional chaining on lastMessage.scrollIntoView and hoist the lastMessage variable to outer scope for proper closure behavior.
This commit is contained in:
@@ -19,7 +19,9 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<script>
|
||||
<script type="module">
|
||||
import { app } from "/app.js";
|
||||
|
||||
const channelUid = "{{ channel.uid.value }}";
|
||||
|
||||
function getInputField(){
|
||||
@@ -120,6 +122,8 @@
|
||||
loadExtra();
|
||||
});
|
||||
|
||||
let lastMessage
|
||||
|
||||
function updateLayout(doScrollDown) {
|
||||
const messagesContainer = document.querySelector(".chat-messages");
|
||||
updateTimes();
|
||||
@@ -134,7 +138,7 @@
|
||||
});
|
||||
lastMessage = messagesContainer.querySelector(".message:last-child");
|
||||
if (doScrollDown) {
|
||||
lastMessage.scrollIntoView({ inline: "nearest" });
|
||||
lastMessage?.scrollIntoView({ inline: "nearest" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +175,7 @@
|
||||
}
|
||||
|
||||
const messagesContainer = document.querySelector(".chat-messages");
|
||||
const lastMessage = messagesContainer.querySelector(".message:last-child");
|
||||
lastMessage = messagesContainer.querySelector(".message:last-child");
|
||||
const doScrollDownBecauseLastMessageIsVisible = !lastMessage || isElementVisible(lastMessage);
|
||||
|
||||
const message = document.createElement("div");
|
||||
|
||||
Reference in New Issue
Block a user