-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nikita Khrulev
committed
Nov 24, 2024
1 parent
a636aac
commit 37b65d5
Showing
6 changed files
with
103 additions
and
38 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { createMockPosts } from './posts'; | ||
import { createMockPosts } from './mock'; | ||
|
||
createMockPosts(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { createRandomId, getRandomInteger } from './utils'; | ||
import { printPosts } from './posts'; | ||
import { POSTS_DATA } from './data'; | ||
|
||
const { POSTS_COUNT, NAMES, DESCRIPTIONS, COMMENTS } = POSTS_DATA; | ||
|
||
const generatePhotoId = createRandomId(1, POSTS_COUNT); | ||
const generateCommentId = createRandomId(1, 30 * POSTS_COUNT); | ||
|
||
const createSingleComment = () => ({ | ||
id: generateCommentId(), | ||
avatar: `img/avatar-${getRandomInteger(1, 6)}.svg`, | ||
message: COMMENTS[getRandomInteger(0, COMMENTS.length - 1)], | ||
name: NAMES[getRandomInteger(0, NAMES.length - 1)] | ||
}); | ||
|
||
const createComments = () => Array.from({length: getRandomInteger(0, 30)}, createSingleComment); | ||
|
||
const createPhotoPost = () => { | ||
const id = generatePhotoId(); | ||
return { | ||
id: id, | ||
url: `photos/${id}.jpg`, | ||
description: DESCRIPTIONS[getRandomInteger(0, DESCRIPTIONS.length - 1)], | ||
likes: getRandomInteger(15, 200), | ||
comments: createComments(), | ||
}; | ||
}; | ||
|
||
const createMockPosts = () => { | ||
const data = Array.from({length: POSTS_COUNT}, createPhotoPost); | ||
|
||
printPosts(data); | ||
}; | ||
|
||
|
||
export {createMockPosts}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,18 @@ | ||
import { createRandomId, getRandomInteger } from './utils'; | ||
import { POSTS_DATA } from './mock-data'; | ||
|
||
const { POSTS_COUNT, NAMES, DESCRIPTIONS, COMMENTS } = POSTS_DATA; | ||
|
||
const generatePhotoId = createRandomId(1, POSTS_COUNT); | ||
const generateCommentId = createRandomId(1, 30 * POSTS_COUNT); | ||
|
||
const createSingleComment = () => ({ | ||
id: generateCommentId(), | ||
avatar: `img/avatar-${getRandomInteger(1, 6)}.svg`, | ||
message: COMMENTS[getRandomInteger(0, COMMENTS.length - 1)], | ||
name: NAMES[getRandomInteger(0, NAMES.length - 1)] | ||
}); | ||
|
||
const createComments = () => Array.from({length: getRandomInteger(0, 30)}, createSingleComment); | ||
|
||
const createPhotoPost = () => { | ||
const id = generatePhotoId(); | ||
return { | ||
id: id, | ||
url: `photos/${id}.jpg`, | ||
description: DESCRIPTIONS[getRandomInteger(0, DESCRIPTIONS.length - 1)], | ||
likes: getRandomInteger(15, 200), | ||
comments: createComments(), | ||
}; | ||
}; | ||
|
||
const createMockPosts = () => { | ||
const data = Array.from({length: POSTS_COUNT}, createPhotoPost); | ||
return data; | ||
const picturesContainer = document.querySelector('.pictures'); | ||
const pictureTemplate = document.querySelector('#picture').content.querySelector('.picture'); | ||
const postsFragment = document.createDocumentFragment(); | ||
|
||
const printPosts = (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); | ||
postsFragment.append(singlePost); | ||
}); | ||
picturesContainer.append(postsFragment); | ||
}; | ||
|
||
|
||
export {createMockPosts}; | ||
export {printPosts}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters