move input and info inside chat component

master
f0x 5 years ago
parent 8e3f2a10f0
commit a58f183c21

@ -8,9 +8,7 @@ const sdk = require('matrix-js-sdk')
const Sidebar = require('./components/sidebar.js') const Sidebar = require('./components/sidebar.js')
const Login = require('./components/Login.js') const Login = require('./components/Login.js')
const Info = require('./components/info.js')
const Chat = require('./components/chat.js') const Chat = require('./components/chat.js')
const Input = require('./components/input.js')
// Things that will get settings: // Things that will get settings:
// colorscheme // colorscheme
@ -88,10 +86,7 @@ let App = create({
<> <>
<Sidebar client={this.state.client} rooms={this.state.rooms} selectRoom={(roomId) => {this.setState({roomId: roomId})}}/> <Sidebar client={this.state.client} rooms={this.state.rooms} selectRoom={(roomId) => {this.setState({roomId: roomId})}}/>
<div className="main"> <div className="main">
<Info room={this.state.rooms[this.state.roomId]} />
<Chat client={this.state.client} roomId={this.state.roomId}/> <Chat client={this.state.client} roomId={this.state.roomId}/>
{this.state.roomId !== undefined
&& <Input client={this.state.client} roomId={this.state.roomId}/>}
</div> </div>
</> </>
) )

@ -8,6 +8,8 @@ const jdenticon = require('jdenticon')
const defaultValue = require('default-value') const defaultValue = require('default-value')
const Event = require('./events/Event.js') const Event = require('./events/Event.js')
const Info = require('./info.js')
const Input = require('./input.js')
jdenticon.config = { jdenticon.config = {
lightness: { lightness: {
@ -103,11 +105,17 @@ let chat = create({
}) })
} }
//TODO: replace with something that only renders events in view //TODO: replace with something that only renders events in view
return <div className="chat" ref={this.setRef}> return (
<div className="events"> <>
{events} <Info room={room} />
</div> <div className="chat" ref={this.setRef}>
</div> <div className="events">
{events}
</div>
</div>
<Input client={this.state.client} roomId={this.state.roomId}/>
</>
)
} }
}) })

@ -11,14 +11,37 @@ let input = create({
if (ref !=null) { if (ref !=null) {
ref.addEventListener("keydown", (e) => { ref.addEventListener("keydown", (e) => {
// only send on plain 'enter' // only send on plain 'enter'
if (e.key == "Enter" && !e.shiftKey && !e.altKey && !e.ctrlKey) { if (e.key == "Enter") {
this.send(e) if (!e.shiftKey && !e.altKey && !e.ctrlKey) {
this.send(e)
return
}
} }
}) })
ref.addEventListener('change', this.resize_textarea)
ref.addEventListener('cut', this.resize_textarea_delayed)
ref.addEventListener('paste', this.resize_textarea_delayed)
ref.addEventListener('drop', this.resize_textarea_delayed)
ref.addEventListener('keydown', this.resize_textarea_delayed)
this.setState({ref: ref}) this.setState({ref: ref})
} }
}, },
resize_textarea: function(element) {
if (element == undefined) {
return;
}
let ref = element.target;
if (ref != undefined) {
ref.style.height = 'auto';
ref.style.height = ref.scrollHeight+'px';
}
},
resize_textarea_delayed: function(e) {
setTimeout(() => this.resize_textarea(e), 5);
},
send: function(e) { send: function(e) {
let content = { let content = {
"body": e.target.value, "body": e.target.value,
@ -32,7 +55,7 @@ let input = create({
render: function() { render: function() {
return <div className="input"> return <div className="input">
<input ref={this.setRef} placeholder="unencrypted message"></input> <textarea ref={this.setRef} rows="1" spellCheck="false" placeholder="unencrypted message"></textarea>
</div> </div>
} }
}) })

@ -18,6 +18,7 @@ $brown: #A3685A;
$accent: $blue; $accent: $blue;
$spacing: 0.7rem; $spacing: 0.7rem;
$borderwidth: 0.2rem;
@font-face { @font-face {
font-family: "Open Sans"; font-family: "Open Sans";
@ -60,7 +61,7 @@ html, body {
background: $bg1; background: $bg1;
} }
.input { .input, .info {
background: $bg2; background: $bg2;
} }
@ -182,7 +183,7 @@ body {
max-width: 15vw; max-width: 15vw;
.filter { .filter {
margin-bottom: $spacing; border-bottom: $borderwidth solid $bg;
input { input {
width: 100%; width: 100%;
@ -191,6 +192,8 @@ body {
border: none; border: none;
color: white; color: white;
font-size: 1rem; font-size: 1rem;
margin: 0;
font-weight: bold;
} }
} }
} }
@ -251,6 +254,8 @@ body {
padding: $spacing; padding: $spacing;
color: $accent; color: $accent;
font-weight: bold; font-weight: bold;
border-bottom: $borderwidth solid $bg;
box-sizing: border-box;
} }
.chat { .chat {
@ -324,14 +329,21 @@ body {
.input { .input {
display: flex; display: flex;
border-top: $borderwidth solid $bg;
input { textarea {
background: transparent; background: transparent;
box-sizing: border-box; box-sizing: border-box;
flex: 1 1 auto; flex: 1 1 auto;
padding: $spacing; padding: $spacing;
font-size: 1.2rem; font-size: 1.2rem;
border: none; border: none;
resize: none;
overflow: hidden;
overflow-y: auto;
outline: none;
max-height: 150px;
} }
} }

Loading…
Cancel
Save