Adding a notification after sending

This commit is contained in:
Sébastien Thuret 2021-10-09 11:25:56 +02:00
parent 130aaecb76
commit b8f41c8d94
No known key found for this signature in database
GPG key ID: 4742E2D66933BB08
2 changed files with 31 additions and 1 deletions

View file

@ -613,6 +613,13 @@ def create_app(args):
def spec():
return jsonify(swag)
@app.route("/suggest", methods=["POST"])
@limiter.exempt
def suggest():
# TODO:
return jsonify({"success": True})
SWAGGER_URL = "/docs" # URL for exposing Swagger UI (without trailing '/')
API_URL = "/spec"

View file

@ -511,6 +511,8 @@
sendSuggestion: function(e) {
e.preventDefault();
var self = this;
var request = new XMLHttpRequest();
self.transRequest = request;
@ -520,7 +522,28 @@
data.append("source", self.sourceLang);
data.append("target", self.targetLang);
request.open('POST', BaseUrl + '/translate', true);
request.open('POST', BaseUrl + '/suggest', true);
request.onload = function() {
try{
var res = JSON.parse(this.response);
if (res.success){
M.toast({html: 'Thanks for your correction.'})
self.closeSuggestTranslation(e)
}else{
throw new Error(res.error || "Unknown error");
}
}catch(e){
self.error = e.message;
self.closeSuggestTranslation(e)
}
};
request.onerror = function() {
self.error = "Error while calling /suggest";
self.loadingTranslation = false;
};
request.send(data);
},
deleteText: function(e){
e.preventDefault();