Fix typing in messages while messages are sent
This commit is contained in:
parent
f085882acb
commit
14c7bb1b4a
|
@ -39,8 +39,7 @@ const state = {
|
||||||
messages: [],
|
messages: [],
|
||||||
websocket: null,
|
websocket: null,
|
||||||
URL: (window.location.href + "connect").replace("http", "ws"),
|
URL: (window.location.href + "connect").replace("http", "ws"),
|
||||||
channel: "default",
|
channel: "default"
|
||||||
message: ""
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let windowVisible = true;
|
let windowVisible = true;
|
||||||
|
@ -140,17 +139,16 @@ const actions = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
msgInput: event => (state, actions) => {
|
msgInput: event => (state, actions) => {
|
||||||
let val = event.target.value;
|
|
||||||
if (event.keyCode == 13) { // enter key
|
if (event.keyCode == 13) { // enter key
|
||||||
|
let val = event.target.value;
|
||||||
const channel = state.channel;
|
const channel = state.channel;
|
||||||
actions.sendMessage([channel, val]);
|
actions.sendMessage([channel, val]);
|
||||||
actions.normalMessage(["user", {
|
actions.normalMessage(["user", {
|
||||||
channel,
|
channel,
|
||||||
message: val
|
message: val
|
||||||
}]);
|
}]);
|
||||||
val = "";
|
event.target.value = "";
|
||||||
}
|
}
|
||||||
return { message: val };
|
|
||||||
},
|
},
|
||||||
channelInput: event => (state, actions) => {
|
channelInput: event => (state, actions) => {
|
||||||
return { channel: event.target.value };
|
return { channel: event.target.value };
|
||||||
|
@ -179,7 +177,7 @@ const view = (state, actions) => h.div([
|
||||||
]),
|
]),
|
||||||
h.ul({class: "messages", onupdate: (element, old) => scrollDown()}, state.messages.map(viewMessage)),
|
h.ul({class: "messages", onupdate: (element, old) => scrollDown()}, state.messages.map(viewMessage)),
|
||||||
h.input({ onkeyup: actions.channelInput, placeholder: "Channel", value: state.channel }),
|
h.input({ onkeyup: actions.channelInput, placeholder: "Channel", value: state.channel }),
|
||||||
h.input({ onkeyup: actions.msgInput, placeholder: "Message", value: state.message }),
|
h.input({ onkeyup: actions.msgInput, placeholder: "Message" }),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const main = hyperapp.app(state, actions, view, document.getElementById("app"));
|
const main = hyperapp.app(state, actions, view, document.getElementById("app"));
|
||||||
|
|
Loading…
Reference in New Issue