Skip to content

Commit e36e2fd

Browse files
committed
подключен axios, реализован базовый fetch данных ленты
1 parent 7230d3f commit e36e2fd

File tree

4 files changed

+152
-16
lines changed

4 files changed

+152
-16
lines changed

package-lock.json

Lines changed: 131 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"dependencies": {
1818
"@popperjs/core": "^2.11.8",
19+
"axios": "^1.9.0",
1920
"bootstrap": "^5.3.6",
2021
"i18next": "^25.1.3",
2122
"on-change": "^5.0.1",

src/js/main.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { updateInputValue, addRssFeed, validateInput } from "./model";
1+
import {
2+
updateInputValue,
3+
addRssFeed,
4+
validateInput,
5+
fetchRssData,
6+
} from "./model";
27
import { renderUIText } from "./view.js";
38

49
renderUIText();
@@ -13,8 +18,6 @@ input.addEventListener("input", (e) => {
1318
form.addEventListener("submit", (e) => {
1419
e.preventDefault();
1520
validateInput()
16-
.then(() => {
17-
addRssFeed();
18-
})
21+
.then(() => addRssFeed()).then(() => fetchRssData())
1922
.catch(() => console.log("валидация не пройдена"));
2023
});

src/js/model.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import onChange from "on-change";
22
import * as yup from "yup";
33
import i18next from "../i18n.js";
4+
import axios from "axios";
45

56
import createState from './state.js';
67

@@ -35,6 +36,18 @@ export const updateInputValue = (value) => {
3536
state.errors = null;
3637
};
3738

39+
export const fetchRssData = () => {
40+
axios
41+
.get(
42+
`https://allorigins.hexlet.app/raw?url=${encodeURIComponent(state.inputValue)}`,
43+
{
44+
timeout: 5000,
45+
}
46+
)
47+
.then((response) => console.log(response.data))
48+
.catch((error) => console.error("fetching error:", error));
49+
}
50+
3851
export const addRssFeed = () => {
3952
state.rssFeed = [...state.rssFeed, state.inputValue];
4053
console.log("обновлён список rss", state.rssFeed);

0 commit comments

Comments
 (0)