1
- import { renderOne , renderEach , destroy } from "../lib/render.mjs" ;
1
+ import { renderOne , renderEach , destroy } from "../lib/render.mjs" ;
2
2
import {
3
3
state ,
4
4
apiService ,
@@ -14,36 +14,43 @@ import {createHeading} from "../components/heading.mjs";
14
14
15
15
// Hashtag view: show all tweets containing this tag
16
16
17
- function hashtagView ( hashtag ) {
17
+ async function hashtagView ( hashtag ) {
18
18
destroy ( ) ;
19
19
20
- apiService . getBloomsByHashtag ( hashtag ) ;
20
+ const hashtagWithHash = hashtag . startsWith ( "#" ) ? hashtag : `#${ hashtag } ` ;
21
+ if ( hashtagWithHash !== state . currentHashtag ) {
22
+ await apiService . getBloomsByHashtag ( hashtagWithHash ) ;
23
+ }
21
24
22
- renderOne (
23
- state . isLoggedIn ,
24
- getLogoutContainer ( ) ,
25
- "logout-template" ,
26
- createLogout
27
- ) ;
28
- document
29
- . querySelector ( "[data-action='logout']" )
30
- ?. addEventListener ( "click" , handleLogout ) ;
31
- renderOne (
32
- state . isLoggedIn ,
33
- getLoginContainer ( ) ,
34
- "login-template" ,
35
- createLogin
36
- ) ;
37
- document
38
- . querySelector ( "[data-action='login']" )
39
- ?. addEventListener ( "click" , handleLogin ) ;
25
+ if ( state . isLoggedIn ) {
26
+ renderOne (
27
+ true ,
28
+ getLogoutContainer ( ) ,
29
+ "logout-template" ,
30
+ createLogout
31
+ ) ;
32
+ document
33
+ . querySelector ( "[data-action='logout']" )
34
+ ?. addEventListener ( "click" , handleLogout ) ;
35
+ } else {
36
+ renderOne (
37
+ false ,
38
+ getLoginContainer ( ) ,
39
+ "login-template" ,
40
+ createLogin
41
+ ) ;
42
+ document
43
+ . querySelector ( "[data-action='login']" )
44
+ ?. addEventListener ( "click" , handleLogin ) ;
45
+ }
40
46
41
47
renderOne (
42
48
state . currentHashtag ,
43
49
getHeadingContainer ( ) ,
44
50
"heading-template" ,
45
51
createHeading
46
52
) ;
53
+
47
54
renderEach (
48
55
state . hashtagBlooms || [ ] ,
49
56
getTimelineContainer ( ) ,
@@ -52,4 +59,4 @@ function hashtagView(hashtag) {
52
59
) ;
53
60
}
54
61
55
- export { hashtagView } ;
62
+ export { hashtagView } ;
0 commit comments