Skip to content

London | Ameneh Keshavarz | Module Legacy Code | WEEK 1 | Extra long blooms #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
5 changes: 4 additions & 1 deletion backend/data/blooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
4 changes: 4 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions backend/populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 magnificentgreat 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.")
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
13 changes: 12 additions & 1 deletion front-end/components/bloom-form.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
1 change: 1 addition & 0 deletions front-end/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ <h2 id="bloom-form-title" class="bloom-form__title">Share a Bloom</h2>
placeholder="What's happening?"
maxlength="280"
spellcheck="true"
maxlength="280"
required
></textarea>
<div class="bloom-form__counter" data-counter>0/280</div>
Expand Down