From baa204328bfe9582699cf0b936e7cde213e080bd Mon Sep 17 00:00:00 2001 From: Anushka Mali Date: Fri, 12 Jun 2026 16:53:17 +0530 Subject: [PATCH] Fix stale letter issue in add letter button --- app.py | 12 +++++++----- templates/index.html | 22 ++++++++++++++++++---- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index c3160be..54afc13 100644 --- a/app.py +++ b/app.py @@ -186,14 +186,16 @@ def predict(): @app.route('/add_letter', methods=['POST']) def add_letter(): - global word - global current_letter - if current_letter: - word += current_letter + data = request.get_json() - return "OK" + letter = data.get("letter", "") + + if letter: + word += letter + + return jsonify(success=True) @app.route('/undo_letter', methods=['POST']) diff --git a/templates/index.html b/templates/index.html index cf81b53..f0943d5 100644 --- a/templates/index.html +++ b/templates/index.html @@ -403,10 +403,24 @@ function addLetter(){ - fetch('/add_letter',{ - method:'POST' - }).then(updateWord); - } + const displayedLetter = + currentLetter.textContent + .split(' ')[0]; + + fetch('/add_letter',{ + + method:'POST', + + headers:{ + 'Content-Type':'application/json' + }, + + body:JSON.stringify({ + letter: displayedLetter + }) + + }).then(updateWord); +} function undoLetter(){