Skip to content

Commit

Permalink
Merge pull request #8 from nikitakhrulev/module7-task1
Browse files Browse the repository at this point in the history
Отрисуй меня полностью
  • Loading branch information
craz3r authored Nov 26, 2024
2 parents e4a209c + ead703a commit 6e139d2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,6 @@ <h2 class="success__title">Изображение успешно загруже
<h2 class="data-error__title">Не удалось загрузить данные</h2>
</section>
</template>
<script src="./js/functions.js"></script>
<script type="module" src="./js/main.js"></script>
</body>
</html>
3 changes: 2 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createMockPosts } from './mock';
import { createMockPosts } from './mock.js';

createMockPosts();

4 changes: 2 additions & 2 deletions js/mock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createRandomId, getRandomInteger } from './utils';
import { printPosts } from './posts';
import { printThumbnails } from './thumbnails';
import { POSTS_DATA } from './data';

const { POSTS_COUNT, NAMES, DESCRIPTIONS, COMMENTS } = POSTS_DATA;
Expand Down Expand Up @@ -30,7 +30,7 @@ const createPhotoPost = () => {
const createMockPosts = () => {
const data = Array.from({length: POSTS_COUNT}, createPhotoPost);

printPosts(data);
printThumbnails(data);
};


Expand Down
6 changes: 3 additions & 3 deletions js/posts.js → js/thumbnails.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ const picturesContainer = document.querySelector('.pictures');
const pictureTemplate = document.querySelector('#picture').content.querySelector('.picture');
const postsFragment = document.createDocumentFragment();

const printPosts = (data) => {
const printThumbnails = (data) => {
data.forEach((post) => {
const singlePost = pictureTemplate.cloneNode(true);
const singlePostImg = singlePost.querySelector('img');
singlePostImg.src = post.url;
singlePostImg.alt = post.description;
singlePost.querySelector('.picture__likes').innerText = post.likes;
singlePost.querySelector('.picture__comments').append(post.comments.length);
singlePost.querySelector('.picture__comments').innerText = post.comments.length;
postsFragment.append(singlePost);
});
picturesContainer.append(postsFragment);
};

export {printPosts};
export {printThumbnails};

0 comments on commit 6e139d2

Please sign in to comment.