diff --git a/backend/data/blooms.py b/backend/data/blooms.py index 7e280cf..db3c369 100644 --- a/backend/data/blooms.py +++ b/backend/data/blooms.py @@ -16,7 +16,11 @@ 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 cannot exceed 280 characters") + + hashtags = re.findall(r'#(\w+)', content) now = datetime.datetime.now(tz=datetime.UTC) bloom_id = int(now.timestamp() * 1000000) diff --git a/front-end/index.html b/front-end/index.html index 89d6b13..b1793d4 100644 --- a/front-end/index.html +++ b/front-end/index.html @@ -4,14 +4,14 @@ Purple Forest - +

Purple Forest Share a Bloom

Please enable JavaScript in your browser.

- + diff --git a/front-end/views/hashtag.mjs b/front-end/views/hashtag.mjs index 7b7e996..86bb048 100644 --- a/front-end/views/hashtag.mjs +++ b/front-end/views/hashtag.mjs @@ -1,42 +1,25 @@ -import {renderOne, renderEach, destroy} from "../lib/render.mjs"; +import {renderOne, renderEach,} from "../lib/render.mjs"; import { state, apiService, - getLogoutContainer, - getLoginContainer, getTimelineContainer, getHeadingContainer, } from "../index.mjs"; -import {createLogin, handleLogin} from "../components/login.mjs"; -import {createLogout, handleLogout} from "../components/logout.mjs"; import {createBloom} from "../components/bloom.mjs"; import {createHeading} from "../components/heading.mjs"; // Hashtag view: show all tweets containing this tag function hashtagView(hashtag) { - destroy(); - apiService.getBloomsByHashtag(hashtag); + // changed to only fetch hashtags when hashtag changes + if (state.currentHashtag !== hashtag) { + state.currentHashtag = hashtag; + state.isLoadingHashtag = true; + apiService.getBloomsByHashtag(hashtag); + } - renderOne( - state.isLoggedIn, - getLogoutContainer(), - "logout-template", - createLogout - ); - document - .querySelector("[data-action='logout']") - ?.addEventListener("click", handleLogout); - renderOne( - state.isLoggedIn, - getLoginContainer(), - "login-template", - createLogin - ); - document - .querySelector("[data-action='login']") - ?.addEventListener("click", handleLogin); + renderOne( state.currentHashtag,