diff --git a/app/assets/stylesheets/components/_hand.scss b/app/assets/stylesheets/components/_hand.scss new file mode 100644 index 0000000..49312e2 --- /dev/null +++ b/app/assets/stylesheets/components/_hand.scss @@ -0,0 +1,12 @@ +.hand { + position: absolute; + bottom: 20px; + z-index: 10000000000; + left: 48%; + font-size: 26px; + cursor: pointer; +} + +.call-container { + // position: relative; +} diff --git a/app/assets/stylesheets/components/_index.scss b/app/assets/stylesheets/components/_index.scss index 3b518a7..4a6c1e4 100644 --- a/app/assets/stylesheets/components/_index.scss +++ b/app/assets/stylesheets/components/_index.scss @@ -2,3 +2,4 @@ @import "alert"; @import "navbar"; @import "banner"; +@import "hand"; diff --git a/app/assets/stylesheets/components/_navbar.scss b/app/assets/stylesheets/components/_navbar.scss index 4261f89..5053d17 100644 --- a/app/assets/stylesheets/components/_navbar.scss +++ b/app/assets/stylesheets/components/_navbar.scss @@ -66,6 +66,7 @@ img { width: 3em; padding: 0.2em; + border-radius: 50%; } } diff --git a/app/channels/chat_rooms_channel.rb b/app/channels/chat_rooms_channel.rb index 20b3201..c796060 100644 --- a/app/channels/chat_rooms_channel.rb +++ b/app/channels/chat_rooms_channel.rb @@ -5,5 +5,13 @@ class ChatRoomsChannel < ApplicationCable::Channel def unsubscribed # Any cleanup needed when channel is unsubscribed + puts "I am now destroyed" + # redirect_to root_path + # ActionCable.server.broadcast('notifications', { + # head: 302, # redirection code, just to make it clear what you're doing + # path: chat_room_path(chat_room), # you'll need to use url_helpers, so include them in your file + # body: { caller: other_caller.id } + # } + # redirect_to root_path end end diff --git a/app/controllers/chat_rooms_controller.rb b/app/controllers/chat_rooms_controller.rb index 37b681c..57f3ec2 100644 --- a/app/controllers/chat_rooms_controller.rb +++ b/app/controllers/chat_rooms_controller.rb @@ -14,6 +14,13 @@ class ChatRoomsController < ApplicationController ActionCable.server.broadcast "chat_room_#{params[:room]}", session_params end + def destroy + # chat_room = ChatRoom.find(params[:id]) + # chat_room.destroy + ActionCable.server.broadcast "chat_room_#{params[:id]}", { hangUp: true } + head :ok + end + private def session_params diff --git a/app/javascript/packs/chatrooms.js b/app/javascript/packs/chatrooms.js index a29046f..787598c 100644 --- a/app/javascript/packs/chatrooms.js +++ b/app/javascript/packs/chatrooms.js @@ -19,10 +19,26 @@ App['chatroom' + chatroomId] = App.cable.subscriptions.create({ connected: () => { }, received: data => { - console.log(data) + if (data.hangUp) { + document.location.pathname = '/contacts' + } + }, + disconnected: () => { + document.location.pathname = '/contacts' } }) +const hangUpIcon = document.querySelector('.fa-hand-paper') +hangUpIcon.addEventListener('click', event => { + fetch(`/chat_rooms/${chatroomId}`, { + method: 'DELETE', + headers: { + 'X-CSRF-Token': document.querySelector('meta[name=csrf-token]').content + } + }) + document.location.pathname = '/contacts' +}) + // Testing ActionCable const testBtn = document.getElementById('test-btn') testBtn.addEventListener('click', event => { diff --git a/app/models/user.rb b/app/models/user.rb index 6043bee..5c094b0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,6 +10,8 @@ class User < ApplicationRecord has_many :chat_rooms, through: :chat_room_participations has_many :requests + validates :email, uniqueness: true + mount_uploader :photo, PhotoUploader def contacts diff --git a/app/views/chat_rooms/show.html.erb b/app/views/chat_rooms/show.html.erb index 57f416c..b10234e 100644 --- a/app/views/chat_rooms/show.html.erb +++ b/app/views/chat_rooms/show.html.erb @@ -6,8 +6,10 @@