From bd16822c487cadfac91fccd460b2e53b266dc548 Mon Sep 17 00:00:00 2001 From: reesericci Date: Wed, 14 Feb 2024 20:43:11 +0000 Subject: [PATCH 1/2] Add cursor chat --- app/assets/stylesheets/application.tailwind.css | 3 +-- app/channels/cursor_chat_channel.rb | 13 +++++++++++++ app/javascript/application.js | 1 + app/javascript/controllers/cursorchat_controller.js | 8 ++++++++ app/views/layouts/domain.html.erb | 8 +++++++- config/importmap.rb | 1 + 6 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 app/channels/cursor_chat_channel.rb create mode 100644 app/javascript/controllers/cursorchat_controller.js diff --git a/app/assets/stylesheets/application.tailwind.css b/app/assets/stylesheets/application.tailwind.css index 5bf606a..e1e9b65 100644 --- a/app/assets/stylesheets/application.tailwind.css +++ b/app/assets/stylesheets/application.tailwind.css @@ -2,7 +2,6 @@ @tailwind components; @tailwind utilities; - /* @layer components { .testing { @apply bg-red-200; @@ -276,7 +275,7 @@ button, input[type=submit] { input[type=text], input[type=email], input[type=number], .input2, x-selectmenu::part(button) { background-color: #262626 !important; border: 1.5px solid var(--cultured)!important; - border-radius: 5px !important; + border-radius: 5px; min-width: 350px; color: white; } diff --git a/app/channels/cursor_chat_channel.rb b/app/channels/cursor_chat_channel.rb new file mode 100644 index 0000000..84e62a9 --- /dev/null +++ b/app/channels/cursor_chat_channel.rb @@ -0,0 +1,13 @@ +class CursorChatChannel < ApplicationCable::Channel + include Y::Actioncable::Sync + + def subscribed + # initiate sync & subscribe to updates, with optional persistence mechanism + sync_for(session) + end + + def receive(message) + # broadcast update to all connected clients on all servers + sync_to(session, message) + end +end diff --git a/app/javascript/application.js b/app/javascript/application.js index 922cc79..9d14d68 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -2,3 +2,4 @@ import "controllers" import "@hotwired/turbo-rails" import "selectlist" import("selectlist") + diff --git a/app/javascript/controllers/cursorchat_controller.js b/app/javascript/controllers/cursorchat_controller.js new file mode 100644 index 0000000..894405b --- /dev/null +++ b/app/javascript/controllers/cursorchat_controller.js @@ -0,0 +1,8 @@ +import { initCursorChat } from "cursor-chat" +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + connect() { + initCursorChat() + } +} \ No newline at end of file diff --git a/app/views/layouts/domain.html.erb b/app/views/layouts/domain.html.erb index 2ec6f8b..cd8a61a 100644 --- a/app/views/layouts/domain.html.erb +++ b/app/views/layouts/domain.html.erb @@ -1,5 +1,7 @@ +<%= stylesheet_link_tag "https://unpkg.com/cursor-chat/dist/style.css" %> + <%# https://icons.hackclub.com/ %> -
+
<%# link to the dns action %> <%= link_to records_path(@domain) do %> @@ -35,4 +37,8 @@ <%= yield_nested %>
+
+ +
+
\ No newline at end of file diff --git a/config/importmap.rb b/config/importmap.rb index 29a5601..d22dfb8 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -8,3 +8,4 @@ pin "url-safe-base64", to: "https://ga.jspm.io/npm:url-safe-base64@1.3.0/src/index.js" pin_all_from "app/javascript" pin "selectlist", to: "https://esm.sh/selectlist-polyfill@0.3.0", preload: true +pin "cursor-chat", to: "https://esm.sh/gh/obl-ong/cursor-chat-actioncable@9befe0089b/dist/cursor-chat.es.js" From 959759067da327817a8d60e068ca50fe1241d3d6 Mon Sep 17 00:00:00 2001 From: reesericci Date: Sat, 17 Feb 2024 02:49:03 +0000 Subject: [PATCH 2/2] remove y::actioncable dependency --- app/channels/cursor_chat_channel.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/channels/cursor_chat_channel.rb b/app/channels/cursor_chat_channel.rb index 84e62a9..ddbc409 100644 --- a/app/channels/cursor_chat_channel.rb +++ b/app/channels/cursor_chat_channel.rb @@ -1,13 +1,9 @@ class CursorChatChannel < ApplicationCable::Channel - include Y::Actioncable::Sync - def subscribed - # initiate sync & subscribe to updates, with optional persistence mechanism - sync_for(session) + stream_from params[:id] end - def receive(message) - # broadcast update to all connected clients on all servers - sync_to(session, message) + def receive(data) + ActionCable.server.broadcast(params[:id], data) end end