Skip to content
This repository has been archived by the owner on Sep 4, 2023. It is now read-only.

Commit

Permalink
Disable swap button while models are loading. (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrenatal authored Nov 10, 2022
1 parent d8bd2ef commit 7c7f4fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions extension/view/popup/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ label {
align-self: center;
grid-area: swap;
font-size: 1.1rem;
cursor: pointer;
}

#status {
Expand Down
17 changes: 16 additions & 1 deletion extension/view/popup/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class Mediator {
message.payload[1].forEach(translationMessage => {
document.querySelector("#output").value = translationMessage.translatedParagraph;
});
if ($(".swap").disabled){
$(".swap").disabled = false;
$(".swap").style.cursor = "pointer";
}
break;
default:
}
Expand Down Expand Up @@ -88,7 +92,14 @@ const setLangs = (selector, langsToSet, value, exclude) => {
const translateCall = () => {
if (langFrom.value === "0" || langTo.value === "0") return;
const text = `${document.querySelector("#input").value} `;
if (!text.trim().length) return;
if (!text.trim().length) {
$("#output").value = "";
if ($(".swap").disabled){
$(".swap").disabled = false;
$(".swap").style.cursor = "pointer";
}
return;
}
const paragraphs = text.replace("\n", " ");
$("#output").setAttribute("disabled", true);
if (!mediator) {
Expand Down Expand Up @@ -149,13 +160,17 @@ const storeLangs = () => {

$(".swap").addEventListener("click", () => {
if (mediator){
$(".swap").disabled = true;
$(".swap").style.cursor = "wait";
browser.runtime.onMessage.removeListener(mediator.bgListener);
mediator.translation = null;
mediator = null;
}
const prevLangFrom = langFrom.value
langFrom.value = langTo.value;
const oldInput = $("#input").value;
$("#input").value = $("#output").value;
$("#output").value = oldInput;

if (prevLangFrom in supportedToCodes) {
setLangs(langTo, supportedToCodes, prevLangFrom, langFrom.value);
Expand Down

0 comments on commit 7c7f4fc

Please sign in to comment.