Skip to content

Commit 81aa5b7

Browse files
authored
Merge pull request #4 from YouAreNotReady/module5-task1
2 parents b05ed32 + c330e58 commit 81aa5b7

File tree

10 files changed

+97
-82
lines changed

10 files changed

+97
-82
lines changed

index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ <h2 class="data-error__title">Не удалось загрузить данны
234234
</section>
235235
</template>
236236

237-
<script src="/js/main.js"></script>
238-
<script src="/js/functions.js"></script>
237+
<script src="/js/main.js" type="module"></script>
239238
</body>
240239
</html>

js/data-generator.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { getRandomInteger, getRandomArrayElement } from './util.js';
2+
3+
const DESCRIPTIONS = [
4+
'Закат над морем',
5+
'Городская улица ночью',
6+
'Заснеженный лес',
7+
'Кафе на набережной',
8+
'Горная вершина',
9+
'Цветущая сакура',
10+
];
11+
12+
const MESSAGES = [
13+
'Всё отлично!',
14+
'В целом всё неплохо. Но не всё.',
15+
'Когда вы делаете фотографию, хорошо бы убирать палец из кадра. В конце концов это просто непрофессионально.',
16+
'Моя бабушка случайно чихнула с фотоаппаратом в руках и у неё получилась фотография лучше.',
17+
'Я поскользнулся на банановой кожуре и уронил фотоаппарат на кота и у меня получилась фотография лучше.',
18+
'Лица у людей на фотке перекошены, как будто их избивают. Как можно было поймать такой неудачный момент?!',
19+
];
20+
21+
const NAMES = [
22+
'Артем',
23+
'Александр',
24+
'Виктор',
25+
'Василий',
26+
'Петр',
27+
'Анастасия',
28+
'Валерия',
29+
'Виктория',
30+
'Дарья',
31+
'Елизавета',
32+
];
33+
34+
const PHOTO_OBJECTS_AMOUNT = 25;
35+
const MIN_LIKES = 15;
36+
const MAX_LIKES = 200;
37+
const MIN_COMMENTS = 0;
38+
const MAX_COMMENTS = 30;
39+
40+
const createIdGenerator = function(min, max) {
41+
const previousValues = [];
42+
43+
return function() {
44+
let lastGeneratedId = getRandomInteger(min, max);
45+
46+
if(previousValues.length >= (max - min + 1)) {
47+
console.log('Закончились уникальные идентификаторы');
48+
return null;
49+
}
50+
51+
while(previousValues.includes(lastGeneratedId)) {
52+
lastGeneratedId = getRandomInteger(min, max);
53+
}
54+
55+
previousValues.push(lastGeneratedId);
56+
return lastGeneratedId;
57+
};
58+
};
59+
60+
const generateCommentId = createIdGenerator(1, PHOTO_OBJECTS_AMOUNT * MAX_COMMENTS);
61+
62+
const createCommentObject = () => ({
63+
id: generateCommentId(),
64+
avatar: 'img/avatar-' + getRandomInteger(1, 6) + '.svg',
65+
message: getRandomArrayElement(MESSAGES),
66+
name: getRandomArrayElement(NAMES),
67+
});
68+
69+
70+
const createPhotoObject = (_, index) => ({
71+
id: index,
72+
url: 'photos/' + index++ + '.jpg',
73+
description: getRandomArrayElement(DESCRIPTIONS),
74+
likes: getRandomInteger(MIN_LIKES, MAX_LIKES),
75+
comments: Array.from({length: getRandomInteger(MIN_COMMENTS, MAX_COMMENTS)}, createCommentObject)
76+
});
77+
78+
79+
const generatePhotoObjects = () => Array.from({length: PHOTO_OBJECTS_AMOUNT}, createPhotoObject);
80+
81+
export { generatePhotoObjects };

js/hashtag-checker.js

Whitespace-only changes.

js/image-effect.js

Whitespace-only changes.

js/image-filtration.js

Whitespace-only changes.

js/image-scaling.js

Whitespace-only changes.

js/image-upload.js

Whitespace-only changes.

js/main.js

Lines changed: 7 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,7 @@
1-
const DESCRIPTIONS = [
2-
'Закат над морем',
3-
'Городская улица ночью',
4-
'Заснеженный лес',
5-
'Кафе на набережной',
6-
'Горная вершина',
7-
'Цветущая сакура',
8-
];
9-
10-
const MESSAGES = [
11-
'Всё отлично!',
12-
'В целом всё неплохо. Но не всё.',
13-
'Когда вы делаете фотографию, хорошо бы убирать палец из кадра. В конце концов это просто непрофессионально.',
14-
'Моя бабушка случайно чихнула с фотоаппаратом в руках и у неё получилась фотография лучше.',
15-
'Я поскользнулся на банановой кожуре и уронил фотоаппарат на кота и у меня получилась фотография лучше.',
16-
'Лица у людей на фотке перекошены, как будто их избивают. Как можно было поймать такой неудачный момент?!',
17-
];
18-
19-
const NAMES = [
20-
'Артем',
21-
'Александр',
22-
'Виктор',
23-
'Василий',
24-
'Петр',
25-
'Анастасия',
26-
'Валерия',
27-
'Виктория',
28-
'Дарья',
29-
'Елизавета',
30-
];
31-
32-
const getRandomInteger = function(min, max) {
33-
const rand = min + Math.random() * (max + 1 - min);
34-
return Math.floor(rand);
35-
};
36-
37-
const createIdGenerator = function(min, max) {
38-
const previousValues = [];
39-
40-
return function() {
41-
let lastGeneratedId = getRandomInteger(min, max);
42-
43-
if(previousValues.length >= (max - min + 1)) {
44-
console.log('Закончились уникальные идентификаторы');
45-
return null;
46-
}
47-
48-
while(previousValues.includes(lastGeneratedId)) {
49-
lastGeneratedId = getRandomInteger(min, max);
50-
}
51-
52-
previousValues.push(lastGeneratedId);
53-
return lastGeneratedId;
54-
};
55-
};
56-
57-
const getRandomArrayElement = (array) => array[getRandomInteger(0, array.length - 1)];
58-
59-
const generatePhotoId = createIdGenerator(1, 25);
60-
61-
const generatePhotoUrlId = createIdGenerator(1, 25);
62-
63-
const generateCommentId = createIdGenerator(1, 750);
64-
65-
const createCommentObject = () => ({
66-
id: generateCommentId(),
67-
avatar: 'img/avatar-' + getRandomInteger(1, 6) + '.svg',
68-
message: getRandomArrayElement(MESSAGES),
69-
name: getRandomArrayElement(NAMES),
70-
});
71-
72-
const createPhotoObject = () => ({
73-
id: generatePhotoId(),
74-
url: 'photos/' + generatePhotoUrlId() + '.jpg',
75-
description: getRandomArrayElement(DESCRIPTIONS),
76-
likes: getRandomInteger(15, 200),
77-
comments: Array.from({length: getRandomInteger(0, 30)}, createCommentObject)
78-
});
79-
80-
const testPhotoObjects = Array.from({length: 25}, createPhotoObject);
1+
import { generatePhotoObjects } from './data-generator.js';
2+
import './hashtag-checker.js';
3+
import './image-scaling.js';
4+
import './image-effect.js';
5+
import './image-upload.js';
6+
import './server-upload.js';
7+
import './image-filtration.js';

js/server-upload.js

Whitespace-only changes.

js/util.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const getRandomInteger = function(min, max) {
2+
const rand = min + Math.random() * (max + 1 - min);
3+
return Math.floor(rand);
4+
};
5+
6+
const getRandomArrayElement = (array) => array[getRandomInteger(0, array.length - 1)];
7+
8+
export { getRandomInteger, getRandomArrayElement };

0 commit comments

Comments
 (0)