forked from jhdevgr/buzon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (44 loc) · 1.79 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import Buzon from './buzon.js';
(function() {
const persons = [
{ name: 'Enzo', avatar: './img/pacman2.png' },
{ name: 'Gonzalo', avatar: './img/pacman2.png' },
{ name: 'Samu', avatar: './img/pacman2.png' },
];
const $mainImage = document.querySelector('#main-image');
const $mainTitle = document.querySelector('#main-title');
const $mainDate = document.querySelector('#main-date');
const $buzonList = document.querySelector('#buzon-list');
const $buzonItemTemplate = document.querySelector('#buzon-item-template');
const buzon = new Buzon({
startDate: '2021-04-07',
persons
});
const currentPerson = buzon.getPerson();
const cycleStartDate = new Date(buzon.getCycleStartDate().getTime() + buzon.dayLength);
function dateFormat(date) {
return date.toLocaleDateString("es-ES", { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }).replace(/^(.)|\s+(.)/g, function (letter) {
return letter.toUpperCase()
}).replaceAll('De', 'de');
}
$mainImage.src = currentPerson.avatar;
$mainTitle.innerText = currentPerson.name;
$mainDate.innerText = dateFormat(cycleStartDate);
const currentPersonIndex = persons.indexOf(currentPerson);
const buzonList = [
...persons.slice(currentPersonIndex),
...persons.slice(0, currentPersonIndex)
]
.filter((person) => person !== currentPerson)
.map((person, index) => ({
...person,
startDate: new Date(cycleStartDate.getTime() + (buzon.weekLength * (index + 1)))
}));
$buzonList.innerHTML = buzonList.map(getItemTemplate).join('');
function getItemTemplate(person) {
return $buzonItemTemplate.innerHTML
.split('{{name}}').join(person.name)
.split('{{date}}').join(dateFormat(person.startDate))
.split('{{image}}').join(person.avatar);
}
})();