discord-client/webpack/vue/auth/channel.vue

106 lines
2.0 KiB
Vue
Raw Normal View History

2018-03-21 17:44:27 +00:00
<template>
<div class='container'>
2018-03-21 17:44:27 +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>
</div>
2018-03-21 17:44:27 +00:00
<div class='body'>
2018-03-22 21:00:57 +00:00
<section class='message-stack'>
<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>
<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>
</span>
<span class='text'>{{ m.msg }}</span>
</div>
2018-03-22 21:00:57 +00:00
</section>
2018-03-22 21:00:57 +00:00
<section class='message-input'>
<textarea :value='message' :placeholder='`Message #${gs.room.get(`text`).name}`' @keydown='keydown' @keyup='keyup'></textarea>
2018-03-22 21:00:57 +00:00
</section>
</div>
2018-03-21 17:44:27 +00:00
</div>
</template><script>
export default {
name: 'channel-',
data(){ return {
gs: gs.get,
message: '', // message text
pressed: {
16: false // SHIFT key
}
}; },
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-03-21 17:44:27 +00:00
}
</script>