File tree Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 11import axios from "axios" ;
22
3- export const fetchRssData = ( state ) => {
4- const proxyUrl = `https://allorigins.hexlet.app/raw?url=${ encodeURIComponent ( state . form . inputValue ) } ` ;
3+ export const fetchRssData = ( link ) => {
4+ const proxyUrl = `https://allorigins.hexlet.app/raw?url=${ encodeURIComponent ( link ) } ` ;
55
66 return axios
77 . get ( proxyUrl , { timeout : 10000 } )
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ export const updateInputValue = (value) => {
3939} ;
4040
4141export const addRssFeed = ( ) => {
42- fetchRssData ( state )
42+ fetchRssData ( state . form . inputValue )
4343 . then ( ( xmlString ) => parseRss ( xmlString ) )
4444 . then ( ( { channel, items } ) => {
4545 state . feeds = [ ...state . feeds , channel ] ;
@@ -52,6 +52,20 @@ export const addRssFeed = () => {
5252 } ) ;
5353} ;
5454
55+ export const checkRssFeed = ( ) => {
56+ state . feeds . forEach ( ( feed ) => {
57+ console . log ( "Проверка фида:" , feed . link ) ;
58+ fetchRssData ( feed . link )
59+ . then ( ( xmlString ) => parseRss ( xmlString ) )
60+ . then ( ( { channel, items } ) => {
61+ console . log ( "в ленте" , channel , ":" , items ) ;
62+ } )
63+ . catch ( ( error ) => {
64+ console . error ( error ) ;
65+ } ) ;
66+ } ) ;
67+ } ;
68+
5569export const setActivePost = ( id ) => {
5670 console . log ( state . posts ) ;
5771 state . activeItem = state . posts . find ( ( post ) => post . id === id ) ;
Original file line number Diff line number Diff line change 11import onChange from "on-change" ;
22import { renderRssFeed } from "./renderRssFeed.js" ;
33import { renderErrors , renderInputValue , showModal } from "./view.js" ;
4+ import { checkRssFeed } from "./model.js" ;
45
56const createState = ( ) => {
67 const object = {
@@ -14,7 +15,10 @@ const createState = () => {
1415 } ;
1516
1617 const state = onChange ( object , ( path , value ) => {
17- // console.log(`состояние изменено: ${path}`, value);
18+ console . log ( `состояние изменено: ${ path } ` , value ) ;
19+ if ( path === "feeds" ) {
20+ checkRssFeed ( ) ;
21+ }
1822 if ( path === "feeds" || path === "posts" ) {
1923 renderRssFeed ( state ) ;
2024 }
You can’t perform that action at this time.
0 commit comments