Skip to content

Commit

Permalink
перераспределены модули
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrEV committed Jan 18, 2025
1 parent 6a8b1b8 commit e95f0b2
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 70 deletions.
61 changes: 29 additions & 32 deletions js/data.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
import {comments, photoValues, names, descriptions} from './until';
import { getRandomInteger } from './randomInteger';
const comments = [
'Всё отлично!',
'В целом всё неплохо. Но не всё.',
'Когда вы делаете фотографию, хорошо бы убирать палец из кадра. В конце концов это просто непрофессионально.',
'Моя бабушка случайно чихнула с фотоаппаратом в руках и у неё получилась фотография лучше.',
'Я поскользнулся на банановой кожуре и уронил фотоаппарат на кота и у меня получилась фотография лучше.',
'Лица у людей на фотке перекошены, как будто их избивают. Как можно было поймать такой неудачный момент?!'
];

let indexPhoto = 0;
let indexComment = 0;
const names = [
'Виктор Пупов',
'Геннадий Изюмов',
'Оксана Тетёхина',
'Ваня Комментаторов',
'Фотоспец3002'
];

const createComments = () => {
const randomAvatarIndex = getRandomInteger(photoValues.RANDOM_MIN_NUMBER_AVATAR, photoValues.RANDOM_MAX_NUMBER_AVATAR);
const randomNameIndex = getRandomInteger(0, names.length - 1);
const commentValue = comments[getRandomInteger(0, comments.length - 1)];
const commentValue2 = comments[getRandomInteger(0, comments.length - 1)];
const genMessage = commentValue !== commentValue2 ? `${commentValue} ${commentValue2}` : commentValue;
const descriptions = [
'здесь мог быть lorem, но ты просто чилишь',
'Русалка села на шпагат',
'Колобок повесился'
];

return {
id: ++indexComment,
avatar: `img/avatar-${randomAvatarIndex}.svg`,
message: genMessage,
name: names[randomNameIndex],
};
const photoValues = {
PHOTOS_COUNT: 25,
RANDOM_MAX_NUMBER_AVATAR: 6,
RANDOM_MIN_NUMBER_AVATAR: 1,
RANDOM_MAX_NUMBER_COMMENTS: 30,
RANDOM_MIN_NUMBER_COMMENTS: 0,
RANDOM_MAX_NUMBER_LIKES: 200,
RANDOM_MIN_NUMBER_LIKES: 15,
};

const createImage = () => {
const randomDescriptionIndex = getRandomInteger(0, descriptions.length - 1);
const randomLikes = getRandomInteger(photoValues.RANDOM_MIN_NUMBER_LIKES, photoValues.RANDOM_MAX_NUMBER_LIKES);
const randomCommentsCount = getRandomInteger(photoValues.RANDOM_MIN_NUMBER_COMMENTS, photoValues.RANDOM_MAX_NUMBER_COMMENTS);
const commentsArray = Array.from({ length: randomCommentsCount }, createComments);

return {
id: ++indexPhoto,
url: `photos/${indexPhoto}.jpg`,
description: descriptions[randomDescriptionIndex],
likes: randomLikes,
comments: commentsArray,
};
};

export {createComments, createImage};
export {comments, photoValues, names, descriptions};
4 changes: 2 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { photoValues } from './until';
import { createImage } from './data';
import { photoValues } from './data';
import { createImage } from './until';


const generatedPhotos = Array.from({ length: photoValues.PHOTOS_COUNT }, createImage);
Expand Down
7 changes: 0 additions & 7 deletions js/randomInteger.js
Original file line number Diff line number Diff line change
@@ -1,7 +0,0 @@
const getRandomInteger = (a, b) => {
const lower = Math.ceil(Math.min(a, b));
const upper = Math.floor(Math.max(a, b));
return Math.floor(Math.random() * (upper - lower + 1)) + lower;
};

export {getRandomInteger};
66 changes: 37 additions & 29 deletions js/until.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
const comments = [
'Всё отлично!',
'В целом всё неплохо. Но не всё.',
'Когда вы делаете фотографию, хорошо бы убирать палец из кадра. В конце концов это просто непрофессионально.',
'Моя бабушка случайно чихнула с фотоаппаратом в руках и у неё получилась фотография лучше.',
'Я поскользнулся на банановой кожуре и уронил фотоаппарат на кота и у меня получилась фотография лучше.',
'Лица у людей на фотке перекошены, как будто их избивают. Как можно было поймать такой неудачный момент?!'
];
import {comments, photoValues, names, descriptions} from './data';

const names = [
'Виктор Пупов',
'Геннадий Изюмов',
'Оксана Тетёхина',
'Ваня Комментаторов',
'Фотоспец3002'
];
const getRandomInteger = (a, b) => {
const lower = Math.ceil(Math.min(a, b));
const upper = Math.floor(Math.max(a, b));
return Math.floor(Math.random() * (upper - lower + 1)) + lower;
};

let indexPhoto = 0;
let indexComment = 0;

const createComments = () => {
const randomAvatarIndex = getRandomInteger(photoValues.RANDOM_MIN_NUMBER_AVATAR, photoValues.RANDOM_MAX_NUMBER_AVATAR);
const randomNameIndex = getRandomInteger(0, names.length - 1);
const commentValue = comments[getRandomInteger(0, comments.length - 1)];
const commentValue2 = comments[getRandomInteger(0, comments.length - 1)];
const genMessage = commentValue !== commentValue2 ? `${commentValue} ${commentValue2}` : commentValue;

return {
id: ++indexComment,
avatar: `img/avatar-${randomAvatarIndex}.svg`,
message: genMessage,
name: names[randomNameIndex],
};
};

const descriptions = [
'здесь мог быть lorem, но ты просто чилишь',
'Русалка села на шпагат',
'Колобок повесился'
];
const createImage = () => {
const randomDescriptionIndex = getRandomInteger(0, descriptions.length - 1);
const randomLikes = getRandomInteger(photoValues.RANDOM_MIN_NUMBER_LIKES, photoValues.RANDOM_MAX_NUMBER_LIKES);
const randomCommentsCount = getRandomInteger(photoValues.RANDOM_MIN_NUMBER_COMMENTS, photoValues.RANDOM_MAX_NUMBER_COMMENTS);
const commentsArray = Array.from({ length: randomCommentsCount }, createComments);

const photoValues = {
PHOTOS_COUNT: 25,
RANDOM_MAX_NUMBER_AVATAR: 6,
RANDOM_MIN_NUMBER_AVATAR: 1,
RANDOM_MAX_NUMBER_COMMENTS: 30,
RANDOM_MIN_NUMBER_COMMENTS: 0,
RANDOM_MAX_NUMBER_LIKES: 200,
RANDOM_MIN_NUMBER_LIKES: 15,
return {
id: ++indexPhoto,
url: `photos/${indexPhoto}.jpg`,
description: descriptions[randomDescriptionIndex],
likes: randomLikes,
comments: commentsArray,
};
};

export {comments, photoValues, names, descriptions};
export {createComments, createImage, getRandomInteger};

0 comments on commit e95f0b2

Please sign in to comment.