File tree Expand file tree Collapse file tree 4 files changed +40
-19
lines changed
Expand file tree Collapse file tree 4 files changed +40
-19
lines changed Original file line number Diff line number Diff line change @@ -19,8 +19,6 @@ export default class ConversationUser extends React.Component {
1919 }
2020
2121 componentDidMount ( ) {
22- Notification . requestPermission ( ) ;
23-
2422 setTimeout ( ( ) => {
2523 this . setState ( {
2624 active : true
@@ -79,7 +77,7 @@ export default class ConversationUser extends React.Component {
7977 < div >
8078 < img src = "images/logo.png" width = "200" height = "150" />
8179 </ div >
82-
80+
8381
8482 < label className = "labelA" > Insert you username</ label >
8583 < input
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import React from 'react';
22import io from 'socket.io-client' ;
33import uid from 'uid' ;
44import MessageList from './MessageList' ;
5- import Notification from './Notification' ;
5+ import Notify from './Notification' ;
66
77export default class Discussions extends React . Component {
88
@@ -19,9 +19,7 @@ export default class Discussions extends React.Component {
1919 this . socket = io ( 'http://localhost:3000' ) ;
2020
2121 this . socket . on ( 'message' , ( message ) => {
22- if ( message . user !== this . user ) {
23- this . _Message ( message ) ;
24- }
22+ this . _Message ( message ) ;
2523 } )
2624
2725 const textValue = document . getElementById ( 'textarea' ) ;
@@ -47,8 +45,8 @@ export default class Discussions extends React.Component {
4745
4846 if ( valueMsj . value !== '' ) {
4947 this . socket . emit ( 'new-message' , message ) ;
50- Notification ( message ) ;
5148 valueMsj . value = '' ;
49+ if ( document . hidden ) Notify ( message ) ;
5250 }
5351 }
5452
Original file line number Diff line number Diff line change 1- export default function Notification ( obj ) {
1+ export default function Notify ( obj ) {
22
3- let titulo = `Tienes un nuevo mensaje de ${ obj . username } ` ;
4- let options = {
5- icon : `${ obj . avatar } ` ,
6- body : obj . message
3+ const title = `Tienes un mensaje nuevo de ${ obj . username } `
4+ const options = {
5+ body : obj . message ,
6+ icon : obj . avatar ,
7+ } ;
8+
9+ if ( ! ( "Notification" in window ) ) {
10+ alert ( "This browser does not support desktop notification" ) ;
711 }
812
9- if ( Notification ) {
10- console . log ( 'excelente' ) ;
11- if ( Notification . permission === "granted" ) {
12- var newNoti = new Notification ( titulo , options ) ;
13- setTimeout ( newNoti . close . bind ( newNoti ) , 6000 ) ;
14- }
13+ // Let's check whether notification permissions have already been granted
14+ else if ( Notification . permission === "granted" ) {
15+ // If it's okay let's create a notification
16+ var notification = new Notification ( title , options ) ;
17+ }
1518
19+ // Otherwise, we need to ask the user for permission
20+ else if ( Notification . permission !== 'denied' ) {
21+ Notification . requestPermission ( function ( permission ) {
22+ // If the user accepts, let's create a notification
23+ if ( permission === "granted" ) {
24+ var notification = new Notification ( title , options ) ;
25+ }
26+ } ) ;
1627 }
1728}
Original file line number Diff line number Diff line change @@ -57,7 +57,21 @@ figure
5757 height calc (100vh - 222.59px )
5858 overflow-y auto
5959 padding 20px
60+ position relative
6061 width 100%
62+ & :after
63+ content ""
64+ display inline-block
65+ background-image url ('images/logo.png' )
66+ background-repeat no-repeat
67+ background-position center
68+ position : fixed ;
69+ top 0
70+ left 0
71+ bottom 0
72+ right 0
73+ opacity .4
74+
6175
6276 .Message
6377 margin-bottom .5em
You can’t perform that action at this time.
0 commit comments