Synchronize resetCode for pair programming

This commit is contained in:
kiragrammel
2023-09-12 18:24:27 +02:00
committed by Sebastian Serth
parent cc90861bd5
commit f37ba34389
3 changed files with 20 additions and 0 deletions

View File

@ -63,6 +63,7 @@ $(document).on('turbolinks:load', function () {
}
break;
case 'current_content':
case 'reset_content':
if (is_other_session(data.session_id)) {
CodeOceanEditor.setEditorContent(data);
}
@ -70,6 +71,10 @@ $(document).on('turbolinks:load', function () {
}
},
reset_content(content) {
this.perform('reset_content', content);
},
editor_change(delta, active_file) {
const message = {session_id: session_id, active_file: active_file, delta: delta}
this.perform('editor_change', message);

View File

@ -119,6 +119,7 @@ CodeOceanEditorSubmissions = {
url: $('#start-over').data('url') || $('#start-over-active-file').data('url')
}).done(function(response) {
this.hideSpinner();
App.synchronized_editor?.reset_content(response);
this.setEditorContent(response, onlyActiveFile);
}.bind(this));
},

View File

@ -46,6 +46,11 @@ class SynchronizedEditorChannel < ApplicationCable::Channel
ActionCable.server.broadcast(specific_channel, message)
end
def reset_content(content)
message = create_reset_content_message(content)
ActionCable.server.broadcast(specific_channel, message)
end
def create_message(action, status)
{
action:,
@ -54,4 +59,13 @@ class SynchronizedEditorChannel < ApplicationCable::Channel
session_id: @session_id,
}
end
def create_reset_content_message(content)
{
action: content['action'],
files: content['files'],
user: current_user.to_page_context,
session_id: @session_id,
}
end
end