Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions codewars-badge.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
// This native web component fetches data from the Codewars API and renders it as a badge
// Here is some information about web component https://developer.mozilla.org/en-US/docs/Web/Web_Components
// Here is the link to the Codewars API Docs: https://dev.codewars.com/#get-user

class CodeWarsBadge extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
this.userName = "CodeYourFuture";
this.userData = [];
this.userName = "fhkahin";
this.userData = {};
}

connectedCallback() {
Expand All @@ -26,26 +22,33 @@ class CodeWarsBadge extends HTMLElement {
`https://www.codewars.com/api/v1/users/${this.userName}`
);
const data = await response.json();
this.userData = data; // set the userData property with the fetched data
this.userData = data;
return data;
}

render() {
this.shadowRoot.innerHTML = `
<style>
:host {
--rank: ${this.userData.ranks.overall.color};
font: 600 100%/1 system-ui, sans-serif;
}
data {
color: var(--rank);
border: 3px solid;
padding: .25em .5em;
}
</style>
<data value="${this.userData.ranks.overall.score}">
${this.userData.ranks.overall.name}
</data>`;
<data>
<table>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this table valid? When you validated your HTML what did you find was missing?

<tr>
<td>Overall Rank</td>
<td>${this.userData.ranks.overall.name}</td>
<td>${this.userData.ranks.overall.score}</td>
</tr>
<tr>
<td>JavaScript Rank</td>
<td>${this.userData.ranks.languages.javascript.name}</td>
<td>${this.userData.ranks.languages.javascript.score}</td>
</tr>
<tr>
<td>Total Challenges Completed</td>
<td colspan="2">${this.userData.codeChallenges.totalCompleted}</td>
</tr>
</table>
</data>`;
}
}

customElements.define("codewars-badge", CodeWarsBadge);


8 changes: 7 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
content="Extending HTML to create a new component"
/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" href="./styles.css" />
</head>
<body>
<codewars-badge></codewars-badge>
<h1> Fathi's Codewars Data: </h1> <br>
<table>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a table? Is this tabular data?

<tr>
<td><codewars-badge></codewars-badge></td>
</tr>
</table>
<script async defer type="module" src="./codewars-badge.js"></script>
</body>
</html>
42 changes: 42 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
body {
background-color: #1D1D1B;
color: #7C9521;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}

.container {
text-align: center;
}

h1 {
margin: 0 auto;
}

table {
border-collapse: collapse;
width: 60%;
margin: 0 auto;
}

td {
border: 1px solid #7C9521;
padding: 10px;
}

codewars-badge {
--overall-rank: var(--badge-color, #f7941d);
--javascript-rank: var(--badge-color, #f7941d);
font: 600 100%/1 system-ui, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
}

data {
margin-top: 20px;
}