File tree Expand file tree Collapse file tree 5 files changed +47
-10
lines changed Expand file tree Collapse file tree 5 files changed +47
-10
lines changed Original file line number Diff line number Diff line change 44 addRssFeed ,
55 validateInput ,
66 setActivePost ,
7- // checkRssFeed,
87 feedsChecking ,
98} from "./model.js" ;
109
@@ -15,6 +14,7 @@ export const initApp = () => {
1514 const input = document . querySelector ( "#url-input" ) ;
1615 const form = document . querySelector ( "#rss-form" ) ;
1716 const postsContainer = document . querySelector ( ".posts" ) ;
17+ const closeModalBtns = document . querySelectorAll ( '[data-bs-dismiss="modal"]' ) ;
1818
1919 input . addEventListener ( "input" , ( e ) => {
2020 updateInputValue ( e . target . value ) ;
@@ -35,6 +35,10 @@ export const initApp = () => {
3535 setActivePost ( button . dataset . id ) ;
3636 }
3737 } ) ;
38- } ;
39-
4038
39+ closeModalBtns . forEach ( ( btn ) => {
40+ btn . addEventListener ( 'click' , ( ) => {
41+ setActivePost ( null ) ;
42+ } ) ;
43+ } ) ;
44+ } ;
Original file line number Diff line number Diff line change @@ -109,6 +109,9 @@ export const checkRssFeed = () => {
109109} ;
110110
111111export const setActivePost = ( id ) => {
112+ if ( id === null ) {
113+ state . activeItem = null ;
114+ return ;
115+ } ;
112116 state . activeItem = state . posts . find ( ( post ) => post . id === id ) ;
113- console . log ( state . activeItem ) ;
114117} ;
Original file line number Diff line number Diff line change 1+ export const showModal = ( item ) => {
2+ const modal = document . querySelector ( "#modal" ) ;
3+ modal . classList . add ( "d-block" , "show" ) ;
4+ modal . setAttribute ( 'aria-hidden' , true )
5+
6+ const modalTitle = modal . querySelector ( '.modal-title' ) ;
7+ const modalText = modal . querySelector ( '.modal-body' ) ;
8+
9+ modalTitle . textContent = item . title ;
10+ modalText . textContent = item . description ;
11+ modal . querySelector ( "a" ) . href = item . link ;
12+
13+ const backdrop = document . createElement ( 'div' ) ;
14+ backdrop . classList . add ( 'modal-backdrop' , 'fade' , 'show' ) ;
15+ modal . before ( backdrop ) ;
16+
17+ } ;
18+
19+ export const closeModal = ( ) => {
20+ const modal = document . querySelector ( "#modal" ) ;
21+ modal . classList . remove ( "d-block" , "show" ) ;
22+ modal . setAttribute ( "aria-hidden" , false ) ;
23+
24+ const modalTitle = modal . querySelector ( ".modal-title" ) ;
25+ const modalText = modal . querySelector ( ".modal-body" ) ;
26+
27+ modalTitle . textContent = '' ;
28+ modalText . textContent = '' ;
29+ modal . querySelector ( "a" ) . href = '#' ;
30+
31+ document . querySelector ( ".modal-backdrop" ) . remove ( ) ;
32+ } ;
Original file line number Diff line number Diff line change 11import onChange from "on-change" ;
22import { renderFeeds , renderPosts } from "./renderRssFeed.js" ;
3- import { renderErrors , renderInputValue , showModal } from "./view.js" ;
3+ import { closeModal , showModal } from "./renderModal.js" ;
4+ import { renderErrors , renderInputValue } from "./view.js" ;
45import { feedsChecking } from "./model.js" ;
56
67const createState = ( ) => {
@@ -24,7 +25,7 @@ const createState = () => {
2425 renderPosts ( state . posts ) ;
2526 }
2627 if ( path === "activeItem" ) {
27- showModal ( state . activeItem ) ;
28+ ( state . activeItem !== null ) ? showModal ( state . activeItem ) : closeModal ( ) ;
2829 }
2930 if ( path === "form.inputValue" ) {
3031 renderInputValue ( value ) ;
@@ -41,3 +42,4 @@ export default createState;
4142
4243
4344
45+
Original file line number Diff line number Diff line change @@ -33,7 +33,3 @@ export const renderErrors = (errors) => {
3333export const renderInputValue = ( value ) => {
3434 input . value = value ;
3535} ;
36-
37- export const showModal = ( activeItem ) => {
38- console . log ( "Активный пост:" , activeItem ) ;
39- } ;
You can’t perform that action at this time.
0 commit comments