diff --git a/app/assets/stylesheets/config/_colors.scss b/app/assets/stylesheets/config/_colors.scss index f551eb7..ad0d7e7 100644 --- a/app/assets/stylesheets/config/_colors.scss +++ b/app/assets/stylesheets/config/_colors.scss @@ -5,7 +5,7 @@ $red: #EE5F5B; $blue: #469AE0; $yellow: #FDB631; $orange: #E67E22; -$green: #32B796; +$green: #5ED17E; $gray: #000000; $light-gray: #F4F4F4; $warn: #3d63cc; diff --git a/app/assets/stylesheets/pages/_contacts.scss b/app/assets/stylesheets/pages/_contacts.scss index 93c6e99..ac0798c 100644 --- a/app/assets/stylesheets/pages/_contacts.scss +++ b/app/assets/stylesheets/pages/_contacts.scss @@ -137,6 +137,7 @@ a:hover { display: flex; justify-content: space-between; align-items: center; + flex-wrap: wrap; } .modal-text { @@ -146,11 +147,6 @@ a:hover { align-items: center; } -.modal-flex { - display: flex; - flex-wrap: wrap; -} - @media only screen and (max-width: 1100px) { .modal-picture { width: 50px; diff --git a/app/assets/stylesheets/pages/_index.scss b/app/assets/stylesheets/pages/_index.scss index da7fa11..52316dd 100644 --- a/app/assets/stylesheets/pages/_index.scss +++ b/app/assets/stylesheets/pages/_index.scss @@ -2,3 +2,18 @@ @import "home"; @import "contacts"; @import "settings"; + +.accept-call-button { + border-style: none; + padding: 0; + background: none; + color: $brand-success; +} + +.flex-inline { + display: flex-inline; + justify-content: space-between; + .accept-call-button { + margin-right: 1em; + } +} diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 479ef60..3f14af6 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -32,10 +32,25 @@ class PagesController < ApplicationController contact = User.find(params[:contact_id]) request = Request.create!(chat_room: chat_room, user: contact) puts "Made a request to call #{contact.email}" + + caller_info = nil + if current_user.first_name.nil? || current_user.last_name.nil? + caller_info = current_user.email + else + caller_info = "#{current_user.first_name} #{current_user.last_name}" + end + + caller_photo = "https://upload.wikimedia.org/wikipedia/commons/8/89/Portrait_Placeholder.png" + unless current_user.photo.url.nil? + caller_photo = current_user.photo.url + end + ActionCable.server.broadcast('notifications', { message: { user_id: contact.id, - chat_room_id: chat_room.id + chat_room_id: chat_room.id, + caller_info: caller_info, + caller_photo: caller_photo } }) end diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index d7551ce..15bc1ae 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -36,3 +36,8 @@ if (contactsPage) { removeActiveClass(contacts); } +const triggerCalleeModalEvent = () => { + $("#calleeModal").modal('show'); +} + +export { triggerCalleeModalEvent } diff --git a/app/javascript/packs/notifications.js b/app/javascript/packs/notifications.js index 8054fa3..09e1d7d 100644 --- a/app/javascript/packs/notifications.js +++ b/app/javascript/packs/notifications.js @@ -1,4 +1,5 @@ import ActionCable from 'actioncable' +import { triggerCalleeModalEvent } from "./application.js"; // create App object with key cable == new consumer (function() { @@ -19,17 +20,20 @@ App.cable.subscriptions.create({ console.log('Connected to NotificationsChannel') }, received: data => { - // console.log(data["message"]["user_id"]) - // console.log(userId) console.log("received broadcast") - // console.log(data.body) + if (data.head === 302 && data.body["caller"] === userId && data.path) { window.location.pathname = data.path - } else if (data["message"]["user_id"] === userId) { // Some error appears here but it is not fatal - console.log("TRIGGER MODAL") + } else if (data["message"]["user_id"] === userId) { + + // DISPLAY ACCEPT BUTTON const acceptButton = document.getElementById('accept-button') acceptButton.style.display = "block" + triggerCalleeModalEvent() + document.getElementById('caller-name').innerHTML = data["message"]["caller_info"] + document.getElementById('caller-photo').src = data["message"]["caller_photo"] + chatRoomId = data["message"]["chat_room_id"] console.log(`user with id: ${userId} needs to subscribe to chatroom ${[chatRoomId]}`) } else { diff --git a/app/views/pages/_contact.html.erb b/app/views/pages/_contact.html.erb index cc03a6c..72039ed 100644 --- a/app/views/pages/_contact.html.erb +++ b/app/views/pages/_contact.html.erb @@ -23,7 +23,6 @@ <%= link_to connection_path(contact), method: :delete do %> <% end %> - @@ -35,8 +34,8 @@ <%= link_to "#", class:"pull-right", 'data-dismiss':"modal", 'data-target':"#myModal#{contact.id}" do %> <% end %> -
- -
+ diff --git a/app/views/pages/index.html.erb b/app/views/pages/index.html.erb index 9a1d490..b5eb6d9 100644 --- a/app/views/pages/index.html.erb +++ b/app/views/pages/index.html.erb @@ -33,11 +33,44 @@
+ -
- - -
+ + <%= javascript_pack_tag 'notifications' %> <%= javascript_pack_tag 'local_video' %>