forked from pulak-tandon19/Share-Your-Bookmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
84 lines (77 loc) · 2.67 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
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
const showData = document.getElementById("showData");
const showDetails = document.getElementById("showDetails");
const linksData = document.getElementById("linksData");
const socialLinks = document.getElementById("socialLinks");
const showNames = () => {
if (data != "") {
for (let i = 0; i < data.length; i++) {
showData.innerHTML += `
<div class="singlePerson" >
<a href="./details.html"><button id="${i}" onclick="getElement(this.id)">${data[i].username}</button></a>
</div>
`;
}
}
};
let personName;
const getElement = (clicked_id) => {
personName = document.getElementById(`${clicked_id}`).innerText;
const storePersonName = personName;
localStorage.setItem("personNameKey", storePersonName);
// console.log(personName);
};
const userDetails = async () => {
// console.log("hello yrrr");
const storePersonName = localStorage.getItem("personNameKey");
// console.log(storePersonName);
const alldata = await fetch(`./data.json`);
data = await alldata.json();
// console.log(data);
let i;
for (i = 0; i < data.length; i++) {
// console.log("in loop");
// console.log(storePersonName);
// console.log(data[i].username);
const string1 = data[i].username;
const string2 = storePersonName;
const result = string1.localeCompare(string2);
// const result = data[i].username === abhay;
if (result == 0) {
// console.log("in if");
// console.log(storePersonName);
// console.log(data[i].username);
showDetails.innerHTML = `<div class="userHead">
<div class="userName">
${data[i].name}
<span>(${data[i].username})</span>
</div>
<div class="userBio"><i class="fa fa-briefcase"></i>${data[i].bio}</div>
</div>`;
// console.log(data[i].links.length);
for (let j = 0; j < data[i].links.length; j++) {
// console.log("in loop");
linksData.innerHTML += `
<li class="link"><i class="fa fa-bookmark"></i><a href=${data[i].links[j]} target="_blank">${data[i].links[j]}</a></li>`;
// console.log(data[i].links[j]);
}
// console.log("loop chal gaya");
socialLinks.innerHTML = `
<a href=${data[i].social[0].twitter} target="_blank"><button>Twitter</button></a>
<a href=${data[i].social[1].linkedin} target="_blank"><button>Linkedin</button></a>`;
// console.log("social");
// console.log(data[i].social[0].twitter);
break;
}
}
};
const fetchData = async () => {
try {
const alldata = await fetch(`./data.json`);
data = await alldata.json();
await showNames();
// console.log(data);
} catch (e) {
throw new Error(e);
}
};
fetchData();