Skip to content

Commit

Permalink
add app view
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatyana-js committed Oct 29, 2024
1 parent 6f00842 commit f9d46c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export default () => {
.then((responce) => {
const parseData = parse(responce.data.contents);
const { posts } = parseData;
const existPostsTitle = new Set(watchedState.posts.map((post) => post.title));
const newPosts = posts.filter((post) => !_.has(existPostsTitle, post.title));
const existPosts = watchedState.posts.map((post) => post.url);
const newPosts = posts.filter((post) => !existPosts.includes(post.url));
const updatePosts = newPosts.map((post) => ({ ...post, id: _.uniqueId() }));
watchedState.posts = [...updatePosts, ...watchedState.posts];
})
Expand All @@ -70,6 +70,7 @@ export default () => {
setTimeout(() => getUpdateContent(watchedState.feeds), timeout);
});
};

getUpdateContent(watchedState.feeds);

elements.form.addEventListener('submit', (e) => {
Expand Down
20 changes: 17 additions & 3 deletions src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default (elements, i18n, state) => {

const renderFeeds = () => {
const feedContainer = document.querySelector('.feeds');
feedContainer.innerHTML = '';
const blok = renderBlock(t('feedTitle'));
const lists = document.createElement('ul');
lists.classList.add('list-group', 'border-0', 'rounded-0');
Expand All @@ -45,12 +46,13 @@ export default (elements, i18n, state) => {

li.append(h3, p);
lists.append(li);
feedContainer.append(blok, lists);
});
feedContainer.append(blok, lists);
};

const renderPosts = () => {
const postsContainer = document.querySelector('.posts');
postsContainer.innerHTML = '';
const post = renderBlock(t('postsTitle'));
const lists = document.createElement('ul');
lists.classList.add('list-group', 'border-0', 'rounded-0');
Expand All @@ -75,8 +77,8 @@ export default (elements, i18n, state) => {

li.append(link, button);
lists.append(li);
postsContainer.append(post, lists);
});
postsContainer.append(post, lists);
};

const renderModal = () => {
Expand All @@ -94,7 +96,7 @@ export default (elements, i18n, state) => {
modalLink.url = url;
};

const watchedState = onChange(state, (path, value) => {
const watchedState = onChange(state, (path, value, previousValue) => {
const {
errorElement, input, form, staticEl,
} = elements;
Expand Down Expand Up @@ -135,6 +137,18 @@ export default (elements, i18n, state) => {
errorElement.textContent = t('errors.invalidRSS');
}
break;
case 'posts':
if (value.length !== previousValue.length) {
renderPosts();
}
break;
case 'feeds':
if (value) {
renderFeeds();
form.reset();
input.focus();
}
break;
case 'ui.touchedPostId':
state.ui.touchedPostId.forEach((postId) => {
const post = document.getElementById(postId);
Expand Down

0 comments on commit f9d46c3

Please sign in to comment.