-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
137 lines (111 loc) · 5.21 KB
/
script.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
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
let userData;
let currentUser = 1;
let announcementData;
fetch('/users.json')
.then(response => response.json())
.then(data => {
userData = data;
displayUserProjects();
})
.catch(error => console.error('Error fetching data:', error));
// Function to manipulate the data
function displayUserProjects() {
if (!userData) {
console.error('Data has not been fetched yet.');
return;
}
// const currentUserName = userData.users[currentUser].name;
const currentUserName = document.getElementById("user-name");
currentUserName.textContent = userData.users[currentUser].name;
const currentUserHandle = document.getElementById("user-handle")
currentUserHandle.textContent = `${currentUserName.textContent} (@${userData.users[currentUser].handle})`
// Create cards for each project
const projectCardContainer = document.getElementById("project-card-container");
for (const project of userData.users[currentUser].projects) {
let card = document.createElement("div");
card.setAttribute('class', 'projects--card primary');
let cardSide = document.createElement("div");
cardSide.setAttribute("class", "projects--card-side accent")
card.appendChild(cardSide)
let cardUpper = document.createElement("div");
cardUpper.setAttribute("class", "projects--card-upper");
let title = document.createElement("h3");
title.setAttribute('class', 'projects--card-title');
title.textContent = project.title;
cardUpper.appendChild(title);
let description = document.createElement("p");
description.setAttribute('class', 'projects--card-description');
description.textContent = project.description;
cardUpper.appendChild(description);
card.appendChild(cardUpper);
let cardLower = document.createElement("div");
cardLower.setAttribute('class', 'projects--card-lower');
const iconPaths = {
"star": "Images/star-plus-outline.svg",
"eye": "Images/eye-plus-outline.svg",
"fork": "Images/source-fork.svg"
}
for (let key in iconPaths) {
fetch(iconPaths[key])
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.text();
})
.then(svgData => {
const svgWrapper = document.createElement('div');
svgWrapper.innerHTML = svgData;
const svgElement = svgWrapper.firstElementChild;
svgElement.setAttribute("class", "projects--icons")
cardLower.appendChild(svgElement);
})
.catch(error => console.error('Error fetching SVG:', error));
}
card.appendChild(cardLower);
projectCardContainer.appendChild(card);
}
}
fetch('/announcements.json')
.then(response => response.json())
.then(data => {
announcementData = data;
displayLastAnnouncements();
})
.catch(error => console.error('Error fetching data:', error));
function displayLastAnnouncements() {
if (!announcementData) {
console.error('Data has not been fetched yet.');
return;
}
const announcementsContainer = document.getElementById("announcements-container");
//grab last 3 announcements
for (i = 0; i < 3; i++) {
// console.log(announcementData.announcements.pop()) //Keep to test less than 3 announcements
let currentAnnouncement = announcementData.announcements.pop();
let announcementsLink = document.createElement("a");
announcementsLink.setAttribute("class", "announcements--link"); //TODO set href in if statements
announcementsLink.setAttribute("href", "#"); //TODO set href in if statements
let announcementsSection = document.createElement("div");
announcementsSection.setAttribute("class", "announcements--card-section");
announcementsLink.appendChild(announcementsSection)
if (currentAnnouncement !== undefined) {
// Add empty div to announcementsContainer
announcementsContainer.appendChild(announcementsLink)
let announcementTitle = document.createElement("h3")
announcementTitle.setAttribute("class", "announcements--title")
announcementTitle.textContent = currentAnnouncement.title;
let announcementBody = document.createElement("p");
announcementBody.setAttribute("class", "announcements--body")
announcementBody.textContent = currentAnnouncement.body;
announcementsSection.appendChild(announcementTitle);
announcementsSection.appendChild(announcementBody);
announcementsContainer.appendChild(announcementsLink);
let lineBreak = document.createElement("hr")
lineBreak.setAttribute("class", "announcements--linebreak");
announcementsContainer.appendChild(lineBreak)
}
}
//Remove extra line break
announcementsContainer.removeChild(announcementsContainer.lastElementChild)
}