Skip to content

Commit 233b9ae

Browse files
committed
добавлены state для ui (success, pending), без рендеринга
1 parent 3ebf221 commit 233b9ae

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

src/js/model.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const schema = yup
1919
);
2020

2121
export const validateInput = () => {
22+
state.ui.success = false;
2223
return schema
2324
.validate(state.form.inputValue)
2425
.then(() => {
@@ -38,13 +39,20 @@ export const updateInputValue = (value) => {
3839
};
3940

4041
const fetchAndParseFeed = (url) => {
42+
state.ui.pending = true;
43+
//перерендер
4144
return fetchRssData(url)
4245
.then((xmlString) => {
46+
state.ui.pending = false;
47+
state.ui.success = true;
48+
//перерендер
4349
return parseRss(xmlString);
4450
})
4551
.catch((error) => {
52+
state.ui.pending = false;
53+
//тоже перерендер
4654
throw error;
47-
})
55+
});
4856
};
4957

5058
const addNewPosts = (posts) => {

src/js/renderRssFeed.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ export const renderFeeds = (feeds) => {
2323
`;
2424
};
2525

26+
export const renderFeedsPending = () => {
27+
const postsContainer = document.querySelector(".feeds");
28+
postsContainer.innerHTML = `
29+
<div
30+
id="posts-spinner"
31+
class="spinner-border text-primary d-none"
32+
role="status">
33+
<span>Загрузка фидов...</span>
34+
</div>
35+
`;
36+
};
37+
2638
export const renderPosts = (posts) => {
2739
const postsContainer = document.querySelector(".posts");
2840

@@ -48,8 +60,20 @@ export const renderPosts = (posts) => {
4860
`;
4961
};
5062

63+
export const renderPostsPending = () => {
64+
const postsContainer = document.querySelector(".posts");
65+
postsContainer.innerHTML = `
66+
<div
67+
id="posts-spinner"
68+
class="spinner-border text-primary d-none"
69+
role="status">
70+
<span>Загрузка постов...</span>
71+
</div>
72+
`;
73+
};
74+
5175
export const renderViewedPost = (id) => {
5276
const viewedPost = document.querySelector(`[data-id="${id}"]`);
5377
viewedPost.classList.remove("fw-bold");
5478
viewedPost.classList.add("fw-normal");
55-
}
79+
};

src/js/state.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const createState = () => {
1616
activeItem: null,
1717
ui: {
1818
error: null,
19-
loading: ''
19+
pending: false,
20+
success: false
2021
}
2122
};
2223

@@ -51,3 +52,4 @@ const createState = () => {
5152

5253
export default createState;
5354

55+

src/js/view.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,3 @@ export const renderErrors = (error) => {
3333
export const renderInputValue = (value) => {
3434
input.value = value;
3535
};
36-

0 commit comments

Comments
 (0)