Skip to content

Commit 1432bba

Browse files
committed
add miniatures render
1 parent ae2116c commit 1432bba

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

js/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
import { createPhotos } from './generate-data';
1+
import { renderThumbnails } from './thumbnails.js';
2+
3+
renderThumbnails();
24

3-
createPhotos();

js/thumbnails.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { createPhotos } from './generate-data';
2+
export const renderThumbnails = () => {
3+
const photos = createPhotos();
4+
5+
const photoTemplate = document.querySelector('#picture').content;
6+
const photoContainer = document.querySelector('.pictures');
7+
8+
const renderPhoto = (element) => {
9+
const newPhotoTemplate = photoTemplate.cloneNode(true);
10+
const image = newPhotoTemplate.querySelector('.picture__img');
11+
image.src = element.url;
12+
image.alt = element.description;
13+
const comments = newPhotoTemplate.querySelector('.picture__comments');
14+
comments.textContent = element.comments.length;
15+
const likes = newPhotoTemplate.querySelector('.picture__likes');
16+
likes.textContent = element.likes;
17+
return newPhotoTemplate;
18+
};
19+
20+
const fragment = new DocumentFragment();
21+
22+
photos.forEach((photo) => {
23+
const element = renderPhoto(photo);
24+
fragment.append(element);
25+
});
26+
27+
photoContainer.append(fragment);
28+
};

0 commit comments

Comments
 (0)