Skip to content

Commit d60cd57

Browse files
committed
fix: изменена структура хранения статусов ui
1 parent 17a2be7 commit d60cd57

File tree

3 files changed

+40
-37
lines changed

3 files changed

+40
-37
lines changed

src/js/model/feed.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import { addNew } from "./post.js";
66
import { handle } from "./error.js";
77

88
export const fetchAndParse = (url) => {
9-
state.ui.pending = true;
9+
// state.ui.pending = true;
10+
state.ui.status = 'pending';
1011
// state.ui.error = null;
1112
return fetchRssData(url)
1213
.then((xmlString) => {
13-
state.ui.pending = false;
14-
state.ui.success = true;
14+
// state.ui.pending = false;
15+
state.ui.status = 'success';
1516
return parseRss(xmlString);
1617
})
1718
.catch((error) => {
18-
state.ui.pending = false;
19+
// state.ui.pending = false;
1920
handle(error, error.message === "noRss" ? "parse" : "fetch");
2021
throw error;
2122
});

src/js/model/form.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ const schema = yup
99
.test("no-duplicate", "exists", (value) => !state.feedsList.includes(value));
1010

1111
export const validateInput = () => {
12-
state.ui.success = false;
12+
// state.ui.success = false;
1313
return schema
14-
.validate(state.form.inputValue)
15-
.then(() => {
16-
state.ui.error = null;
14+
.validate(state.form.inputValue)
15+
.then(() => {
16+
state.ui.status = "success";
17+
state.ui.error = null;
1718
return state.form.inputValue;
1819
})
1920
.catch((error) => {
21+
state.ui.status = "error";
2022
state.ui.error = error.errors.join();
2123
throw error;
2224
});

src/js/state.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,41 @@ const createState = () => {
1313
posts: [],
1414
activeItem: null,
1515
ui: {
16+
status: null, // 'error', 'success', 'pending'
1617
error: null,
17-
pending: false,
18-
success: false,
1918
},
2019
};
2120

2221
return onChange(object, (path, value) => {
2322
console.log(`состояние изменено: ${path}`, value);
24-
if (path === "feeds") {
25-
view.feeds.renderFeeds(value);
26-
model.update.checkFeeds();
27-
}
28-
if (path === "posts") {
29-
view.posts.renderPosts(value);
30-
}
31-
if (path === "activeItem") {
32-
if (state.activeItem !== null) {
33-
view.modal.showModal(state.activeItem);
34-
model.post.markAsRead(state.activeItem.id);
35-
view.posts.renderViewedPost(state.activeItem.id);
36-
} else {
37-
view.modal.closeModal();
38-
}
39-
}
40-
if (path === "form.inputValue") {
41-
view.form.renderInputValue(value);
42-
}
43-
if (path === "ui.error") {
44-
view.ui.renderUi("error", value);
45-
}
46-
if (path === "ui.success") {
47-
view.ui.renderUi("success");
48-
}
49-
if (path === "ui.pending") {
50-
view.ui.renderUi("pending");
23+
switch (path) {
24+
case "feeds":
25+
view.feeds.renderFeeds(value);
26+
model.update.checkFeeds();
27+
break;
28+
case "posts":
29+
view.posts.renderPosts(value);
30+
break;
31+
case "activeItem":
32+
if (state.activeItem !== null) {
33+
view.modal.showModal(state.activeItem);
34+
model.post.markAsRead(state.activeItem.id);
35+
view.posts.renderViewedPost(state.activeItem.id);
36+
} else {
37+
view.modal.closeModal();
38+
}
39+
break;
40+
case "form.inputValue":
41+
view.form.renderInputValue(value);
42+
break;
43+
case "ui.status":
44+
view.ui.renderUi(value, state.ui.error);
45+
break;
46+
case "ui.error":
47+
if (state.ui.status === "error") {
48+
view.ui.renderUi("error", value);
49+
}
50+
break;
5151
}
5252
});
5353
};

0 commit comments

Comments
 (0)