Skip to content

Commit 05e8834

Browse files
committed
проверяем фиды, fetchRssData принимает только ссылку
1 parent 3d86bb1 commit 05e8834

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/js/fetchRssData.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 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 })

src/js/model.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const updateInputValue = (value) => {
3939
};
4040

4141
export 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+
5569
export const setActivePost = (id) => {
5670
console.log(state.posts);
5771
state.activeItem = state.posts.find((post) => post.id === id);

src/js/state.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import onChange from "on-change";
22
import { renderRssFeed } from "./renderRssFeed.js";
33
import { renderErrors, renderInputValue, showModal } from "./view.js";
4+
import { checkRssFeed } from "./model.js";
45

56
const 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
}

0 commit comments

Comments
 (0)