Skip to content

Commit b7f4f5c

Browse files
committed
рендер модалки
1 parent c3b17c7 commit b7f4f5c

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

src/js/main.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
addRssFeed,
55
validateInput,
66
setActivePost,
7-
// checkRssFeed,
87
feedsChecking,
98
} from "./model.js";
109

@@ -15,6 +14,7 @@ export const initApp = () => {
1514
const input = document.querySelector("#url-input");
1615
const form = document.querySelector("#rss-form");
1716
const postsContainer = document.querySelector(".posts");
17+
const closeModalBtns = document.querySelectorAll('[data-bs-dismiss="modal"]');
1818

1919
input.addEventListener("input", (e) => {
2020
updateInputValue(e.target.value);
@@ -35,6 +35,10 @@ export const initApp = () => {
3535
setActivePost(button.dataset.id);
3636
}
3737
});
38-
};
39-
4038

39+
closeModalBtns.forEach((btn) => {
40+
btn.addEventListener('click', () => {
41+
setActivePost(null);
42+
});
43+
});
44+
};

src/js/model.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ export const checkRssFeed = () => {
109109
};
110110

111111
export const setActivePost = (id) => {
112+
if (id === null) {
113+
state.activeItem = null;
114+
return;
115+
};
112116
state.activeItem = state.posts.find((post) => post.id === id);
113-
console.log(state.activeItem);
114117
};

src/js/renderModal.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export const showModal = (item) => {
2+
const modal = document.querySelector("#modal");
3+
modal.classList.add("d-block", "show");
4+
modal.setAttribute('aria-hidden', true)
5+
6+
const modalTitle = modal.querySelector('.modal-title');
7+
const modalText = modal.querySelector('.modal-body');
8+
9+
modalTitle.textContent = item.title;
10+
modalText.textContent = item.description;
11+
modal.querySelector("a").href = item.link;
12+
13+
const backdrop = document.createElement('div');
14+
backdrop.classList.add('modal-backdrop', 'fade', 'show');
15+
modal.before(backdrop);
16+
17+
};
18+
19+
export const closeModal = () => {
20+
const modal = document.querySelector("#modal");
21+
modal.classList.remove("d-block", "show");
22+
modal.setAttribute("aria-hidden", false);
23+
24+
const modalTitle = modal.querySelector(".modal-title");
25+
const modalText = modal.querySelector(".modal-body");
26+
27+
modalTitle.textContent = '';
28+
modalText.textContent = '';
29+
modal.querySelector("a").href = '#';
30+
31+
document.querySelector(".modal-backdrop").remove();
32+
};

src/js/state.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import onChange from "on-change";
22
import { renderFeeds, renderPosts } from "./renderRssFeed.js";
3-
import { renderErrors, renderInputValue, showModal } from "./view.js";
3+
import { closeModal, showModal } from "./renderModal.js";
4+
import { renderErrors, renderInputValue } from "./view.js";
45
import { feedsChecking } from "./model.js";
56

67
const createState = () => {
@@ -24,7 +25,7 @@ const createState = () => {
2425
renderPosts(state.posts);
2526
}
2627
if (path === "activeItem") {
27-
showModal(state.activeItem);
28+
(state.activeItem !== null) ? showModal(state.activeItem) : closeModal();
2829
}
2930
if (path === "form.inputValue") {
3031
renderInputValue(value);
@@ -41,3 +42,4 @@ export default createState;
4142

4243

4344

45+

src/js/view.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,3 @@ export const renderErrors = (errors) => {
3333
export const renderInputValue = (value) => {
3434
input.value = value;
3535
};
36-
37-
export const showModal = (activeItem) => {
38-
console.log("Активный пост:", activeItem);
39-
};

0 commit comments

Comments
 (0)