From 19c38ea010bdfdd165e6e508226aa3a66e4add1b Mon Sep 17 00:00:00 2001 From: Jamal Laqdiem Date: Sun, 18 Oct 2026 09:22:33 +0100 Subject: [PATCH] fix: separate the fetching data form the ui rendering. --- front-end/views/hashtag.mjs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/front-end/views/hashtag.mjs b/front-end/views/hashtag.mjs index 7b7e9969..2f9a35fc 100644 --- a/front-end/views/hashtag.mjs +++ b/front-end/views/hashtag.mjs @@ -12,13 +12,9 @@ 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); +// helper function to separate the UI from the data fetching +function renderHashtagUI() { renderOne( state.isLoggedIn, getLogoutContainer(), @@ -52,4 +48,19 @@ function hashtagView(hashtag) { ); } +// Hashtag view: show all tweets containing this tag +function hashtagView(hashtag) { + destroy(); + + const formattedTag = hashtag.startsWith("#") ? hashtag : `#${hashtag}`; + + if (state.currentHashtag === formattedTag) { + renderHashtagUI(); + return; + } + + apiService.getBloomsByHashtag(hashtag); + renderHashtagUI(); +} + export {hashtagView};