11import { loaderController } from "./components/loader/loaderController.js" ;
2+ import { notificationsController } from "./components/notifications/notificationsController.js" ;
23import { showPostsController } from "./modules/show-posts/showPostsController.js" ;
34
45
56// Get the DOM nodes we need to interact with.
67document . addEventListener ( "DOMContentLoaded" , ( ) => {
78
8- // Here I go to the DOM and select the nodes I need to manage in my code.
9- const container = document . querySelector ( ".posts-container" )
10- const loader = document . querySelector ( ".loader" )
9+ // Here I go to the DOM and select the nodes I need to manage in my code and I manage them in my controllers.
10+ const container = document . querySelector ( ".posts-container" ) // ".posts-container" is a Node
11+ const loader = document . querySelector ( ".loader" ) // ".loader" is a Node
12+ const notifications = document . querySelector ( ".notifications" )
1113
12- const { show, hide } = loaderController ( loader )
14+
15+ const { show, hide } = loaderController ( loader ) ;
16+ const { showNotification } = notificationsController ( notifications )
1317
1418 /*
1519 'main.js' needs to know when posts start and finish loading,
@@ -18,19 +22,19 @@ document.addEventListener("DOMContentLoaded", () => {
1822 For that reason, we use 'CustomEvent' in 'showPostsController.js'.
1923
2024 Here, we listen to those custom events ('load-posts-started' and 'load-posts-finished')
21- on the container element. When triggered, we call 'show()' to display the loader,
25+ on the " container" element. When triggered, we call 'show()' to display the loader,
2226 and 'hide()' to remove it once loading is complete.
2327 */
2428 container . addEventListener ( 'load-posts-started' , ( ) => {
25- show ( )
29+ show ( ) ;
2630 } )
2731 container . addEventListener ( 'load-posts-finished' , ( ) => {
28- hide ( )
29- /* showNotification('Posts Loaded')*/
32+ hide ( ) ;
33+ showNotification ( 'Posts Loaded' , 'success' ) // <-- Here we add type as “success”.
3034 } )
3135 container . addEventListener ( 'load-tweets-error' , ( event ) => {
32- /* const errorMesage = event.detail;
33- showNotification(errorMesage) */
36+ const errorMessage = event . detail ; // <-- Here we are passing the error obtained from "showPostsController.js".
37+ showNotification ( errorMessage ) // <-- Here we do not add the type “success” so it will be “error”.
3438 } )
3539
3640 // Then this next code happens in showPostsController.js
0 commit comments