From f37ba343896cd71450f7e93b880113a3f9c9554e Mon Sep 17 00:00:00 2001 From: kiragrammel Date: Tue, 12 Sep 2023 18:24:27 +0200 Subject: [PATCH] Synchronize resetCode for pair programming --- .../channels/synchronized_editor_channel.js | 5 +++++ app/assets/javascripts/editor/submissions.js | 1 + app/channels/synchronized_editor_channel.rb | 14 ++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/app/assets/javascripts/channels/synchronized_editor_channel.js b/app/assets/javascripts/channels/synchronized_editor_channel.js index 1368dccb..ffe72d44 100644 --- a/app/assets/javascripts/channels/synchronized_editor_channel.js +++ b/app/assets/javascripts/channels/synchronized_editor_channel.js @@ -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); diff --git a/app/assets/javascripts/editor/submissions.js b/app/assets/javascripts/editor/submissions.js index 0ec459cd..ad1edb8e 100644 --- a/app/assets/javascripts/editor/submissions.js +++ b/app/assets/javascripts/editor/submissions.js @@ -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)); }, diff --git a/app/channels/synchronized_editor_channel.rb b/app/channels/synchronized_editor_channel.rb index 923e5834..6f1835c8 100644 --- a/app/channels/synchronized_editor_channel.rb +++ b/app/channels/synchronized_editor_channel.rb @@ -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