Site > Chat > Add user update

This commit is contained in:
brunosimon
2017-08-14 22:17:40 +02:00
parent 16052bd2ea
commit 0eb639a9db
9 changed files with 164 additions and 13 deletions
+3
View File
@@ -0,0 +1,3 @@
<template src="./template.html"></template>
<script src="./script.js"></script>
<style src="./style.styl" lang="stylus" scoped></style>
+53
View File
@@ -0,0 +1,53 @@
export default
{
name: 'chat',
data()
{
return {
userName: ''
}
},
computed:
{
messages()
{
return this.$store.state.chatMessages
},
user()
{
return this.$store.state.user
}
},
watch:
{
user(value)
{
this.userName = value.name
}
},
mounted()
{
},
methods:
{
onUserNameChange()
{
this.$store.commit('askUpdateUser', { name: this.userName })
},
onUserNameKeyDown(event)
{
// Blur if enter pressed
if(event.keyCode === 13)
{
event.target.blur()
}
}
}
}
+8
View File
@@ -0,0 +1,8 @@
.chat
position fixed
bottom 0
right 20px
.user-name
outline none
border none
+21
View File
@@ -0,0 +1,21 @@
<div class="chat">
<header>
Discussions
</header>
<div class="messages">
<div class="message" v-for="message of messages" :key="message.id">
<div class="date">
{{ message.time }}
</div>
<div class="user" :style="`color: ${message.user.color};`">
{{ message.user.name }}
</div>
<div class="text">
{{ message.text }}
</div>
</div>
</div>
<div class="infos" v-if="user">
Your nickname is <input class="user-name" :style="`color: ${user.color};`" v-model="userName" @change="onUserNameChange($event)" @keydown="onUserNameKeyDown($event)"/>
</div>
</div>
+38 -2
View File
@@ -9,12 +9,18 @@ export default
project()
{
return this.$store.state.project
},
pendingUser()
{
return this.$store.state.pendingUser
}
},
watch:
{
project: 'onProjectChange'
project: 'onProjectChange',
pendingUser: 'onPendingUser'
},
created()
@@ -29,7 +35,6 @@ export default
this.projectsSocket.on('update_projects', (data) =>
{
// console.log('update_projects', data)
this.$store.commit('updateProjects', data.all)
})
},
@@ -38,6 +43,12 @@ export default
{
onProjectChange(value)
{
if(!value)
{
return
}
// Project socket
const projectURL = `${process.env.NODE_ENV === 'production' ? '' : 'http://localhost:1571'}/project/${value.slug}`
this.projectSocket = socketIoClient(projectURL)
@@ -66,6 +77,31 @@ export default
{
this.$store.commit('createVersion', data)
})
// Chat socket
const chatURL = `${process.env.NODE_ENV === 'production' ? '' : 'http://localhost:1571'}/project/${value.slug}/chat`
this.chatSocket = socketIoClient(chatURL)
this.chatSocket.on('connect', () =>
{
// console.log('chat connected')
})
this.chatSocket.on('user', (data) =>
{
this.$store.commit('updateUser', data)
})
this.chatSocket.on('message', (data) =>
{
this.$store.commit('createMessage', data)
})
},
onPendingUser(value)
{
this.chatSocket.emit('update_user', value)
}
}
}
+3 -1
View File
@@ -1,5 +1,6 @@
import FilesTree from '@/components/files-tree'
import File from '@/components/file'
import Chat from '@/components/chat'
export default
{
@@ -8,7 +9,8 @@ export default
components:
{
FilesTree,
File
File,
Chat
},
computed:
@@ -3,4 +3,5 @@
<files-tree></files-tree>
<file v-if="file" :content="file.data"></file>
<chat></chat>
</div>