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};