-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
141 lines (126 loc) · 3.07 KB
/
index.js
File metadata and controls
141 lines (126 loc) · 3.07 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const main = document.querySelector('#main');
const emsadData = './emsad.json';
const githubApi = 'https://api.github.com/users/emsad87/repos';
const getData = async (dataFile) => {
try {
const resp = await fetch(dataFile);
const data = await resp.json();
dataOut(data);
} catch (err) {
console.log(err);
}
};
const getGithub = async (githubApi) => {
try {
const resp = await fetch(githubApi);
const data = await resp.json();
githubData(data);
} catch (err) {
console.log(err);
}
};
const fetchMulti = async (data1, data2) => {
try {
[data1, data2] = await Promise.all([fetch(data1), fetch(data2)]);
[data1, data2] = await Promise.all([data1.json(), data2.json()]);
dataOut(data1);
githubData(data2);
} catch (err) {
console.log(err);
}
};
const githubData = (data) => {
const repoList = (repos) => {
let repo = '';
for (let i in repos) {
repo += `
<a href=${data[i].html_url}>
<article>
<h4>${data[i].name}</h4>
<p>${data[i].description}</p>
</article>
</a>
`;
}
return repo;
};
var article = document.createElement('article');
article.className = 'github';
article.innerHTML = `
<h4>Github:</h4>
<main>
${repoList(data)}
</main>
`;
main.appendChild(article);
};
const dataOut = (data) => {
const paragraphs = (parags) => {
let paragraph = '';
for (let i in parags) {
paragraph += `<p>${parags[i]}</p>`;
}
return paragraph;
};
const listElems = (elements) => {
let listElems = '';
for (let i in elements) {
listElems += `<li>${elements[i]}</li>`;
}
return listElems;
};
const contactIcon = (data) => {
let contactIcon = '';
for (let i in data) {
contactIcon += `<a href=${data[i].url}><img class="icon" src=${data[i].icon} /></a>`;
}
return contactIcon;
};
const {
image,
name,
lastName,
birthday,
birthPlace,
livingPlace,
bio,
hobbies,
website,
skills,
} = data;
const { email } = data.contact;
var article = document.createElement('article');
article.className = 'info';
article.innerHTML = `
<h1>Profil card created fetching data from JSON file</h1>
<article class="card">
<img src=${image} class="card__img" />
<article class="card__info">
<h2>${name} ${lastName}</h2>
<p>${birthday} ${birthPlace}</p>
<p>${livingPlace}</p>
<p>${email.username}</p>
</article>
<article class="card__contact">
<a href=${website.url}><img class="icon" src=${website.icon} /></a>
${contactIcon(data.contact)}
</article>
<article class="card__skills">
<h4>Skills:</h4>
<ul>${listElems(skills)}</ul>
</article>
<article class="card__bio">
<h4>A bit about me:</h4>
<div>${paragraphs(bio)}</div>
</article>
<article class="card__hobbies">
<h4>Hobbies:</h4>
<ul>${listElems(hobbies)}</ul>
</article>
</article>
`;
main.appendChild(article);
};
getData(emsadData);
getGithub(githubApi);
// fetchMulti(emsadData, githubApi);