From 9415011b5fd192f1bafeaa9b6eacbb7921382a00 Mon Sep 17 00:00:00 2001 From: David Gay Date: Wed, 19 May 2021 22:53:38 -0400 Subject: Chat --- app/views/application/_chat.html.erb | 13 ++++++--- app/views/chat_messages/_list.html.erb | 3 ++ app/views/chat_messages/_message.html.erb | 47 +++++++++++++++++++++++++++++++ app/views/layouts/application.html.erb | 1 + 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 app/views/chat_messages/_list.html.erb create mode 100644 app/views/chat_messages/_message.html.erb (limited to 'app/views') diff --git a/app/views/application/_chat.html.erb b/app/views/application/_chat.html.erb index 868986b..8abe73c 100644 --- a/app/views/application/_chat.html.erb +++ b/app/views/application/_chat.html.erb @@ -1,8 +1,13 @@ -
-
- Chat output will go here. +
+
- Chat input will go here. + <%= form_with model: ChatMessage.new, html: { autocomplete: "off" }, local: false, + data: { action: "chat#send" }, class: "flex" do |f| %> + <%= f.collection_select :chat_room_id, ChatRoom.accessible_to(current_char.user), + :id, :short_name, class: "flex-none" %> + <%= f.text_field :body, size: "1", maxlength: 255, required: true, + data: { chat_target: "message" }, class: "flex-grow inline-flex" %> + <% end %>
diff --git a/app/views/chat_messages/_list.html.erb b/app/views/chat_messages/_list.html.erb new file mode 100644 index 0000000..8b12fd2 --- /dev/null +++ b/app/views/chat_messages/_list.html.erb @@ -0,0 +1,3 @@ +<% @chat_messages.each do |chat_message| %> + <%= render "message", chat_message: chat_message %> +<% end %> diff --git a/app/views/chat_messages/_message.html.erb b/app/views/chat_messages/_message.html.erb new file mode 100644 index 0000000..e9663ec --- /dev/null +++ b/app/views/chat_messages/_message.html.erb @@ -0,0 +1,47 @@ +<% chat_room_text_class = case chat_message.chat_room.gid + when "cosmic" then "text-gray-400" + when "trade" then "text-blue-400" + when "help" then "text-pink-300" + when "system" then "text-red-500" + when "achievement" then "text-purple-400" + when "news" then "text-yellow-400" + else "text-gray-400" + end + + chat_room_prefix = case chat_message.chat_room.gid + when "cosmic" then "[C]" + when "trade" then "[T]" + when "help" then "[H]" + when "system" then "[S]" + when "achievement" then "[A]" + when "news" then "[N]" + else nil + end +%> +

+ + <%= chat_message.created_at.strftime("%H:%M") %> + <%= chat_room_prefix %> + + <% if chat_message.chat_room.gid == "system" %> + <%= chat_message.body %> + <% elsif chat_message.chat_room.gid == "news" %> + <%= chat_message.body %> + <% elsif chat_message.chat_room.gid == "achievement" %> + <%#= render "components/text/title", title: chat_message.target.current_title %> + + <%# TODO: Sort out this subject/target stuff that I just half-blindly ported over from old Esoterra. %> + <%= chat_message.target&.name %> <%= chat_message.body %> + + <% else %> + <% if chat_message.sender %> + <%#= render "components/text/title", title: chat_message.sender.current_title %> + <% end %> + + <% if chat_message.sender %> + <%= chat_message.sender.name %>: + <% end %> + <%= chat_message.body %> + + <% end %> +

diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 3fe6f28..7ae44a9 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -30,6 +30,7 @@ data-turbolinks-permanent> <%= render "chat" %>
+
<% else %>