Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions backend/data/blooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Bloom:


def add_bloom(*, sender: User, content: str) -> Bloom:
if len(content) > 280:
raise ValueError("Blooms are limited to 280 characters!")

hashtags = [word[1:] for word in content.split(" ") if word.startswith("#")]

now = datetime.datetime.now(tz=datetime.UTC)
Expand Down
2 changes: 1 addition & 1 deletion backend/populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ 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.",
"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.",
)

justsomeguy_access_token = create_user("JustSomeGuy", "mysterious")
Expand Down
2 changes: 1 addition & 1 deletion db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
8 changes: 8 additions & 0 deletions front-end/components/bloom-form.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ async function handleBloomSubmit(event) {
const textarea = form.querySelector("textarea");
const content = textarea.value.trim();

const maxLength = parseInt(textarea.getAttribute("maxlength"), 10);

if(Number.isFinite(maxLength) && content.length > maxLength){
alert(`your message is too long! Limit is ${maxLength}`);
textarea.focus();
return;
}

try {
// Make form inert while we call the back end
form.inert = true;
Expand Down