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
14 changes: 13 additions & 1 deletion backend/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,20 @@ def send_bloom():
return type_check_error

user = get_current_user()
#Extract content safely
content = request.json.get("content", "")
# Limit content length
MAX_BLOOM_LENGTH = 280
if len(content) > MAX_BLOOM_LENGTH:
return make_response(
{
"success": False,
"message": f"Bloom cannot exceed {MAX_BLOOM_LENGTH} characters",
},
400,
)

blooms.add_bloom(sender=user, content=request.json["content"])
blooms.add_bloom(sender=user, content=content)

return jsonify(
{
Expand Down
3 changes: 1 addition & 2 deletions backend/populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +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.",
)
"In this essay I will convince you that my views are correct in ways you have never imagined. Marshmallows are magnificent!" )

justsomeguy_access_token = create_user("JustSomeGuy", "mysterious")
send_bloom(justsomeguy_access_token, "Hello.")
Expand Down
2 changes: 1 addition & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ idna==3.10
itsdangerous==2.2.0
Jinja2==3.1.5
MarkupSafe==3.0.2
psycopg2==2.9.10
psycopg2-binary==2.9.10
pycparser==2.22
PyJWT==2.10.1
python-dotenv==1.0.1
Expand Down
2 changes: 1 addition & 1 deletion front-end/components/bloom.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const createBloom = (template, bloom) => {
function _formatHashtags(text) {
if (!text) return text;
return text.replace(
/\B#[^#]+/g,
/(^|\s)(#[\w]+)/g,
(match) => `<a href="/hashtag/${match.slice(1)}">${match}</a>`
);
}
Expand Down
7 changes: 7 additions & 0 deletions front-end/views/hashtag.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import {createHeading} from "../components/heading.mjs";
// Hashtag view: show all tweets containing this tag

function hashtagView(hashtag) {
//only fetch data from the server and avoid the flashing on slow network
if (state.currentHashtag !== hashtag) {
state.currentHashtag = hashtag;
state.hashtagBlooms = [];
apiService.getBloomsByHashtag(hashtag);
}
//this one if statement fixes the flashing behavior by checking if the hashtag selected is already running or not
destroy();

apiService.getBloomsByHashtag(hashtag);
Expand Down
4 changes: 2 additions & 2 deletions front-end/views/profile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ function profileView(username) {
createLogin
);
document
.querySelector("[data-action='login']")
?.addEventListener("click", handleLogin);
.querySelector("[data-form='login']")
?.addEventListener("submit", handleLogin);

const profileData = state.profiles.find((p) => p.username === username);
if (profileData) {
Expand Down