File tree Expand file tree Collapse file tree 6 files changed +29
-7
lines changed Expand file tree Collapse file tree 6 files changed +29
-7
lines changed Original file line number Diff line number Diff line change 11import { renderUIText } from "./view.js" ;
2- import { updateInputValue , addRssFeed , validateInput } from "./model.js" ;
2+ import {
3+ updateInputValue ,
4+ addRssFeed ,
5+ validateInput ,
6+ setActivePost ,
7+ } from "./model.js" ;
38
49export const initApp = ( ) => {
510 renderUIText ( ) ;
611
712 const input = document . querySelector ( "#url-input" ) ;
813 const form = document . querySelector ( "#rss-form" ) ;
14+ const postsContainer = document . querySelector ( ".posts" ) ;
915
1016 input . addEventListener ( "input" , ( e ) => {
1117 updateInputValue ( e . target . value ) ;
@@ -17,4 +23,12 @@ export const initApp = () => {
1723 . then ( ( ) => addRssFeed ( ) )
1824 . catch ( ( ) => console . log ( "валидация не пройдена" ) ) ;
1925 } ) ;
26+
27+ postsContainer . addEventListener ( "click" , ( e ) => {
28+ const button = e . target . closest ( ".modal-btn" ) ;
29+ console . log ( "id:" , button . dataset . id ) ;
30+ if ( button && button . dataset . id ) {
31+ setActivePost ( button . dataset . id ) ;
32+ }
33+ } ) ;
2034} ;
Original file line number Diff line number Diff line change @@ -51,3 +51,8 @@ export const addRssFeed = () => {
5151 throw error ;
5252 } ) ;
5353} ;
54+
55+ export const setActivePost = ( id ) => {
56+ console . log ( state . posts ) ;
57+ state . activeItem = state . posts . find ( ( post ) => post . id === id ) ;
58+ } ;
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ export const parseRss = (xmlString) => {
88 }
99
1010 const channel = {
11- id : 1 , // добавить
11+ id : doc . querySelector ( "channel > link" ) ?. textContent || "" ,
1212 title : doc . querySelector ( "channel > title" ) ?. textContent || "" ,
1313 description : doc . querySelector ( "channel > description" ) ?. textContent || "" ,
1414 link : doc . querySelector ( "channel > link" ) ?. textContent || "" ,
Original file line number Diff line number Diff line change @@ -33,9 +33,9 @@ export const renderRssFeed = (state) => {
3333 ( post ) => `
3434 <li class="list-group-item d-flex justify-content-between align-items-start border-0 border-end-0">
3535 <a href="${ post . link } " class="fw-bold" data-id="${ post . id } " target="_blank" rel="noopener noreferrer">${ post . title } </a>
36- <button type="button" class="btn btn-outline-primary btn-sm" data-id="${ post . id } " data-bs-toggle="modal" data-bs-target="#modal">Просмотр</button>
36+ <button type="button" class="btn btn-outline-primary btn-sm modal-btn " data-id="${ post . id } " data-bs-toggle="modal" data-bs-target="#modal">Просмотр</button>
3737 </li>
38- `
38+ ` ,
3939 )
4040 . join ( "" ) }
4141 </ul>
Original file line number Diff line number Diff line change 11import onChange from "on-change" ;
22import { renderRssFeed } from "./renderRssFeed.js" ;
3- import { renderErrors , renderInputValue } from "./view.js" ;
3+ import { renderErrors , renderInputValue , showModal } from "./view.js" ;
44
55const createState = ( ) => {
66 const object = {
@@ -19,8 +19,7 @@ const createState = () => {
1919 renderRssFeed ( state ) ;
2020 }
2121 if ( path === "activeItem" ) {
22- // поиск по массиву постов
23- // рендер модалки
22+ showModal ( state . activeItem ) ;
2423 }
2524 if ( path === "form.inputValue" ) {
2625 renderInputValue ( value ) ;
Original file line number Diff line number Diff line change @@ -33,3 +33,7 @@ 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