2018-03-21 17:44:27 +00:00
|
|
|
<template>
|
|
|
|
|
2018-03-21 23:53:32 +00:00
|
|
|
<div class='container'>
|
2018-03-21 17:44:27 +00:00
|
|
|
|
2018-03-21 23:53:32 +00:00
|
|
|
<div class='header'>
|
2018-03-22 13:57:03 +00:00
|
|
|
<div class='title'>{{ gs.room.get('text') ? gs.room.get('text').name : '?' }}</div>
|
2018-03-21 23:53:32 +00:00
|
|
|
</div>
|
2018-03-21 17:44:27 +00:00
|
|
|
|
2018-03-21 23:53:32 +00:00
|
|
|
<div class='body'>
|
2018-03-22 20:58:14 +00:00
|
|
|
|
2018-04-03 15:13:11 +00:00
|
|
|
<section class='message-stack' ref='stack'>
|
2018-03-22 20:58:14 +00:00
|
|
|
|
|
|
|
<div class='message' v-for='m in gs.content.messages'>
|
2018-03-28 13:54:19 +00:00
|
|
|
<div class='icon' :style='`background-image: url("https://picsum.photos/150/?random&nonce=${m.uid}");`'></div>
|
2018-03-22 20:58:14 +00:00
|
|
|
<span class='meta'>
|
2018-03-28 13:54:19 +00:00
|
|
|
<span class='author'>{{ gs.content.user(m.uid).username || `guest ${m.uid}` }}</span>
|
|
|
|
<span class='date' >{{ m.ts || 'inconnu' }}</span>
|
2018-03-22 20:58:14 +00:00
|
|
|
</span>
|
|
|
|
<span class='text'>{{ m.msg }}</span>
|
|
|
|
</div>
|
|
|
|
|
2018-03-22 21:00:57 +00:00
|
|
|
</section>
|
2018-03-22 20:58:14 +00:00
|
|
|
|
2018-03-22 21:00:57 +00:00
|
|
|
<section class='message-input'>
|
2018-04-02 19:15:28 +00:00
|
|
|
<textarea :value='message' :placeholder='`Message #${gs.room.get(`text`).name}`' @keydown='keydown' @keyup='keyup'></textarea>
|
2018-03-22 21:00:57 +00:00
|
|
|
</section>
|
2018-03-22 20:58:14 +00:00
|
|
|
|
2018-03-21 23:53:32 +00:00
|
|
|
</div>
|
2018-03-21 17:44:27 +00:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</template><script>
|
|
|
|
export default {
|
|
|
|
|
|
|
|
name: 'channel-',
|
|
|
|
|
2018-04-02 19:15:28 +00:00
|
|
|
data(){ return {
|
|
|
|
gs: gs.get,
|
|
|
|
message: '', // message text
|
|
|
|
pressed: {
|
|
|
|
16: false // SHIFT key
|
2018-04-03 15:13:11 +00:00
|
|
|
},
|
|
|
|
stack_length: 0
|
2018-04-02 19:15:28 +00:00
|
|
|
|
|
|
|
}; },
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
|
|
/* (1) Auto-grow text area
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
auto_grow(e){
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
e.target.style.height = '0';
|
|
|
|
e.target.style.height = `calc( ${e.target.scrollHeight}px )`;
|
|
|
|
}, 1);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Mange Key Down
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
keydown(e){
|
|
|
|
|
|
|
|
// Manage auto grow
|
|
|
|
this.auto_grow(e);
|
|
|
|
|
|
|
|
// register pressed keys
|
|
|
|
this.pressed[e.keyCode] = true;
|
|
|
|
|
|
|
|
// if not ENTER OR SHIFT -> do nothing
|
|
|
|
if( e.keyCode !== 13 || this.pressed[16] )
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// bufferize message + remove trailing line
|
|
|
|
let buffer = e.target.value.replace(/\n*$/, '');
|
|
|
|
this.message = buffer;
|
|
|
|
|
|
|
|
// send message
|
|
|
|
if( !gs.get.content.send_message(buffer) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// empty message
|
|
|
|
this.message = '';
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) Mange Key Up
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
keyup(e){
|
|
|
|
|
|
|
|
// unregister pressed keys
|
|
|
|
this.pressed[e.keyCode] = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-03 15:13:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
updated(){
|
|
|
|
|
|
|
|
let stack_length = this.$refs.stack.children.length;
|
|
|
|
|
|
|
|
|
|
|
|
/* (1) If new messages -> scroll to bottom */
|
2018-04-03 15:14:52 +00:00
|
|
|
if( stack_length > this.stack_length )
|
|
|
|
this.$refs.stack.scrollTop = this.$refs.stack.scrollHeight;
|
2018-04-03 15:13:11 +00:00
|
|
|
|
|
|
|
/* (2) If new messages -> update stack length */
|
|
|
|
if( stack_length != this.stack_length )
|
|
|
|
this.stack_length = stack_length;
|
|
|
|
|
2018-04-02 19:15:28 +00:00
|
|
|
}
|
2018-03-21 17:44:27 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|