tweaks to events on hub start

This commit is contained in:
Ryan Peters 2021-07-22 22:51:24 -04:00
parent 4a67c41bf1
commit 98f1dbea6c

View File

@ -8,6 +8,8 @@
let $yourNameText = $('#your-name-text'); let $yourNameText = $('#your-name-text');
let $yourColorText = $('#your-color-text'); let $yourColorText = $('#your-color-text');
let isTeacher = window.location.hash === '#4ELQcUq7UnFGghAZCVr4Chr9JmtncigfkGu5WSf9';
let isLive = false; let isLive = false;
let isLiveMode = function () { let isLiveMode = function () {
@ -30,6 +32,16 @@
connection.invoke('SaveName', $yourNameText.val(), color); connection.invoke('SaveName', $yourNameText.val(), color);
}; };
let updateCode = function (editor, index) {
let user = $yourNameText.val();
let code = editor.getValue();
connection.invoke('UpdateCode', user, index, code, isTeacher).catch(function (err) {
return console.error(err.toString());
});
};
let setHeight = function () { let setHeight = function () {
var editorHeight = $(window).height() - $('header').outerHeight() - $('footer').outerHeight(); var editorHeight = $(window).height() - $('header').outerHeight() - $('footer').outerHeight();
@ -45,8 +57,6 @@
isLiveMode(); isLiveMode();
setHeight(); setHeight();
let isTeacher = window.location.hash === '#4ELQcUq7UnFGghAZCVr4Chr9JmtncigfkGu5WSf9';
if (isTeacher) { if (isTeacher) {
$liveModeLink.hide(); $liveModeLink.hide();
$liveModeStatus.hide(); $liveModeStatus.hide();
@ -56,21 +66,6 @@
let $editors = $('.ace_editor'); let $editors = $('.ace_editor');
$editors.each(function (i, e) {
let editor = ace.edit(e);
editor.session.on('change', function () {
let user = $yourNameText.val();
let code = editor.getValue();
connection.invoke('UpdateCode', user, i, code, isTeacher).catch(function (err) {
return console.error(err.toString());
});
});
});
connection.on('ReceiveCode', function (user, index, code) { connection.on('ReceiveCode', function (user, index, code) {
if (!isTeacher && isLive) { if (!isTeacher && isLive) {
@ -97,6 +92,18 @@
sendName(); sendName();
$editors.each(function (i, e) {
let editor = ace.edit(e);
editor.session.on('change', function () {
updateCode(editor, i);
});
// send initial code
updateCode(editor, i);
});
}).catch(function (err) { }).catch(function (err) {
return console.error(err.toString()); return console.error(err.toString());
}); });