Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempted a restyle on the chat interface + mic button #189

Merged
merged 8 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added public/images/almond.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/almond_error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions public/images/almond_mic_round_grey.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions public/images/almond_mic_round_white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions public/images/almond_mic_white_round.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/bubble_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion public/javascripts/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ $(function() {
$('.form-delete-app').on('submit', function() {
return confirm("Are you sure?");
});
});
$(window).scroll(function() {
if ($(window).scrollTop() > 100) {
$('#back_top').removeClass('hidden');
console.log("hidden")
} else {
console.log("not hidden")
$('#back_top').addClass('hidden')
}
});
});
137 changes: 72 additions & 65 deletions public/javascripts/conversation.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ $(() => {
function updateConnectionFeedback() {
if (!ws || !open) {
$('#input-form-group').addClass('has-warning');
$('#input-form-group .spinner-container').addClass('hidden');
- $('#input-form-group .glyphicon-warning-sign, #input-form-group .help-block').removeClass('hidden');
$('#almond_thinking_container').remove();
$('#toolbar .form-inline .help-block').removeClass('hidden');
return;
}

$('#input-form-group').removeClass('has-warning');
$('#input-form-group .glyphicon-warning-sign, #input-form-group .help-block').addClass('hidden');
$('#toolbar .form-inline .help-block').addClass('hidden');
}

function updateSpinner(thinking) {
if (!ws || !open)
return;

if (thinking)
$('#input-form-group .spinner-container').removeClass('hidden');
$('#almond_thinking_container').removeClass('hidden');
else
$('#input-form-group .spinner-container').addClass('hidden');
$('#almond_thinking_container').remove();
}


Expand Down Expand Up @@ -101,6 +101,7 @@ $(() => {

function addVoteButtons() {
$('.comment-options').remove();
//$('#almond_thinking_container').remove();
$('#comment-block').val('');
const upvote = $('<i>').addClass('far fa-thumbs-up').attr('id', 'upvoteLast');
const downvote = $('<i>').addClass('far fa-thumbs-down').attr('id', 'downvoteLast');
Expand Down Expand Up @@ -142,13 +143,13 @@ $(() => {
function maybeScroll(container) {
if (!$('#input:focus').length)
return;

//keep scroll bar to the bottom
scrollChat();
setTimeout(scrollChat, 1000);
}

function scrollChat() {
let chat = document.getElementById('conversation');
let chat = document.getElementById('chat');
chat.scrollTop = chat.scrollHeight;
}

Expand Down Expand Up @@ -179,6 +180,7 @@ $(() => {
rdlMessage.append($('<span>').addClass('message-rdl-content')
.text(rdl.displayText));
container.append(rdlMessage);

maybeScroll(container);
}

Expand Down Expand Up @@ -289,44 +291,44 @@ $(() => {
lastMessageId = parsed.id;

switch (parsed.type) {
case 'text':
case 'result':
// FIXME: support more type of results
textMessage(parsed.text, parsed.icon);
currentGrid = null;
break;

case 'picture':
picture(parsed.url, parsed.icon);
currentGrid = null;
break;

case 'rdl':
rdl(parsed.rdl, parsed.icon);
currentGrid = null;
break;

case 'choice':
choice(parsed.idx, parsed.title);
break;

case 'button':
buttonMessage(parsed.title, parsed.json);
break;

case 'link':
linkMessage(parsed.title, parsed.url);
break;

case 'hypothesis':
$('#input').val(parsed.hypothesis);
break;

case 'command':
$('#input').val('');
collapseButtons();
appendUserMessage(parsed.command);
break;
case 'text':
case 'result':
// FIXME: support more type of results
textMessage(parsed.text, parsed.icon);
currentGrid = null;
break;

case 'picture':
picture(parsed.url, parsed.icon);
currentGrid = null;
break;

case 'rdl':
rdl(parsed.rdl, parsed.icon);
currentGrid = null;
break;

case 'choice':
choice(parsed.idx, parsed.title);
break;

case 'button':
buttonMessage(parsed.title, parsed.json);
break;

case 'link':
linkMessage(parsed.title, parsed.url);
break;

case 'hypothesis':
$('#input').val(parsed.hypothesis);
break;

case 'command':
$('#input').val('');
collapseButtons();
appendUserMessage(parsed.command);
break;
}
}

Expand All @@ -351,33 +353,38 @@ $(() => {
updateSpinner(true);
ws.send(JSON.stringify({ type: 'command', text: text }));
}

function handleParsedCommand(json, title) {
updateSpinner(true);
ws.send(JSON.stringify({ type: 'parsed', json: json, title: title }));
}

function handleThingTalk(tt) {
updateSpinner(true);
ws.send(JSON.stringify({ type: 'tt', code: tt }));
}

function handleChoice(idx, title) {
handleParsedCommand({ code: ['bookkeeping', 'choice', String(idx)], entities: {} }, title);
}

function handleSpecial(special, title) {
handleParsedCommand({ code: ['bookkeeping', 'special', 'special:'+special ], entities: {} }, title);
handleParsedCommand({ code: ['bookkeeping', 'special', 'special:' + special], entities: {} }, title);
}

function appendUserMessage(text) {
container.append($('<span>').addClass('message message-text from-user')
.text(text));
container.append('<div id="almond_thinking_container" ><div id="almond_thinking_txt"><p>Almond is thinking</p></div><div id="almond_thinking"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></div></div>');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work if you refresh the page: existing messages are resent by the server, and the spinner gets stuck.
Also, hardcoding the message here is problematic for a number of reasons, including translation.
I would do away with the message and entirely and only show the spinner, and also make it fewer dots. 3-5 should be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work if you refresh the page: existing messages are resent by the server, and the spinner gets stuck.

Noticed later, trying to figure out a fix for that

Also, hardcoding the message here is problematic for a number of reasons, including translation.

I know, that is a quick and dirty test, alredy implemented correctly

I would do away with the message and entirely and only show the spinner, and also make it fewer dots. 3-5 should be enough.

ok

}

$('#input-form').submit((event) => {
var text = $('#input').val();
if (currCommand !== "")
pastCommandsUp.push(currCommand);
pastCommandsUp.push(currCommand);
if (pastCommandsDown.length !== 0) {
pastCommandsUp = pastCommandsUp.concat(pastCommandsDown);
pastCommandsDown = [];
pastCommandsUp = pastCommandsUp.concat(pastCommandsDown);
pastCommandsDown = [];
}
pastCommandsUp.push(text);

Expand All @@ -391,21 +398,21 @@ $(() => {
});

$('#input-form').on('keydown', (event) => { // button is pressed
if (event.keyCode === 38) { // Up
// removes last item from array pastCommandsUp, displays it as currCommand, adds current input text to pastCommandsDown
currCommand = pastCommandsUp.pop();
if ($('#input').val() !== "")
pastCommandsDown.push($('#input').val());
$('#input').val(currCommand);
}

if (event.keyCode === 40) { // Down
// removes last item from array pastCommandsDown, displays it as currCommand, adds current input text to pastCommandsUp
currCommand = pastCommandsDown.pop();
if ($('#input').val() !== "")
pastCommandsUp.push($('#input').val());
$('#input').val(currCommand);
}
if (event.keyCode === 38) { // Up
// removes last item from array pastCommandsUp, displays it as currCommand, adds current input text to pastCommandsDown
currCommand = pastCommandsUp.pop();
if ($('#input').val() !== "")
pastCommandsDown.push($('#input').val());
$('#input').val(currCommand);
}

if (event.keyCode === 40) { // Down
// removes last item from array pastCommandsDown, displays it as currCommand, adds current input text to pastCommandsUp
currCommand = pastCommandsDown.pop();
if ($('#input').val() !== "")
pastCommandsUp.push($('#input').val());
$('#input').val(currCommand);
}
});

$('#save-log').click(() => {
Expand Down Expand Up @@ -449,4 +456,4 @@ $(() => {
}
});
});
});
});
Loading