diff --git a/backend/data/blooms.py b/backend/data/blooms.py index 7e280cf..7cf459a 100644 --- a/backend/data/blooms.py +++ b/backend/data/blooms.py @@ -16,10 +16,13 @@ class Bloom: def add_bloom(*, sender: User, content: str) -> Bloom: - hashtags = [word[1:] for word in content.split(" ") if word.startswith("#")] + if len(content) > 280: + raise ValueError("Bloom content exceeds the 280 character limit.") + hashtags = [word[1:] for word in content.split(" ") if word.startswith("#")] now = datetime.datetime.now(tz=datetime.UTC) bloom_id = int(now.timestamp() * 1000000) + with db_cursor() as cur: cur.execute( "INSERT INTO blooms (id, sender_id, content, send_timestamp) VALUES (%(bloom_id)s, %(sender_id)s, %(content)s, %(timestamp)s)", diff --git a/backend/main.py b/backend/main.py index 7ba155f..ff696c2 100644 --- a/backend/main.py +++ b/backend/main.py @@ -46,6 +46,10 @@ def main(): jwt = JWTManager(app) jwt.user_lookup_loader(lookup_user) + @app.route("/") + def index(): + return "PurpleForest backend is running!" + app.add_url_rule("/register", methods=["POST"], view_func=register) app.add_url_rule("/login", methods=["POST"], view_func=login) diff --git a/backend/populate.py b/backend/populate.py index 414218b..e952aaf 100644 --- a/backend/populate.py +++ b/backend/populate.py @@ -64,8 +64,8 @@ def main(): writer_access_token = create_user("AS", "neverSt0pTalking") send_bloom( writer_access_token, - "In this essay I will convince you that my views are correct in ways you have never imagined. If it doesn't change your life, read it again. Marshmallows are magnificent. They have great squish, tasty good, and you can even toast them over a fire. Toast them just right until they have a tiny bit of crunch when you bite into them, and have just started melting in the middle.", - ) + "In this essay I will convince you my views are correct in ways you never imagined. If it doesn't change your life, read it again. Marshmallows are magnificent—great squish, tasty, and perfect toasted with a crisp outside and melty middle." + ) justsomeguy_access_token = create_user("JustSomeGuy", "mysterious") send_bloom(justsomeguy_access_token, "Hello.") diff --git a/db/schema.sql b/db/schema.sql index 61e7580..13a5a51 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -9,7 +9,7 @@ CREATE TABLE users ( CREATE TABLE blooms ( id BIGSERIAL NOT NULL PRIMARY KEY, sender_id INT NOT NULL REFERENCES users(id), - content TEXT NOT NULL, + content TEXT NOT NULL CHECK (char_length(content) <= 280), send_timestamp TIMESTAMP NOT NULL ); diff --git a/front-end/components/bloom-form.mjs b/front-end/components/bloom-form.mjs index e047f9a..6021334 100644 --- a/front-end/components/bloom-form.mjs +++ b/front-end/components/bloom-form.mjs @@ -52,7 +52,18 @@ function handleTyping(event) { .closest("[data-form]") ?.querySelector("[data-counter]"); const maxLength = parseInt(textarea.getAttribute("maxlength"), 10); - counter.textContent = `${textarea.value.length} / ${maxLength}`; + const currentLength = textarea.value.length; + + counter.textContent = `${currentLength} / ${maxLength}`; + + if (currentLength >= maxLength) { + counter.style.color = "red"; + counter.setAttribute("aria-live", "polite"); + counter.textContent += " — character limit reached!"; + } else { + counter.style.color = ""; + } } + export {createBloomForm, handleBloomSubmit, handleTyping}; diff --git a/front-end/index.html b/front-end/index.html index 89d6b13..624127a 100644 --- a/front-end/index.html +++ b/front-end/index.html @@ -219,6 +219,7 @@