diff --git a/codewars-badge.js b/codewars-badge.js index 7c26060..5a312ab 100644 --- a/codewars-badge.js +++ b/codewars-badge.js @@ -1,12 +1,186 @@ -// 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 +// // 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 = "BaselAdoum"; +// this.userData = []; +// } + +// connectedCallback() { +// this.fetchActivity() +// .then(() => { +// this.render(); +// }) +// .catch((error) => { +// console.error(error); +// }); +// } + +// // fetch the data from the Codewars API +// async fetchActivity() { +// const response = await fetch( +// `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 +// } + +// render() { +// this.shadowRoot.innerHTML = ` +// +// +// ${this.userData.ranks.overall.name} +// `; +// } + + +// } + +// customElements.define("codewars-badge", CodeWarsBadge); + + + +// //console.log("testing") + +// this is a nice full display of all info from api. be careful. there is only one render. +// no more than one render in the file with the same name. you add add a div. **check code below. +// // render() { +// // this.shadowRoot.innerHTML = ` +// // + +// //
+// // +// //
${this.userData.username}
+ +// // +// //
${this.userData.ranks.overall.name}
+// //
Score: ${this.userData.ranks.overall.score}
+ +// // +// //
+// //
+// //
${this.userData.honor}
+// //
Honor
+// //
+ +// //
+// //
${this.userData.codeChallenges.totalCompleted}
+// //
Completed
+// //
+// //
+ +// // +// //
+// //
Top Language:
+// //
+// // JavaScript +// // ${this.userData.ranks.languages.javascript.name} +// //
+// //
+// //
`; +// // } class CodeWarsBadge extends HTMLElement { + constructor() { super(); this.attachShadow({ mode: "open" }); - this.userName = "CodeYourFuture"; + this.userName = "BaselAdoum"; // ← PUT YOUR USERNAME HERE this will be added to the url this.userData = []; } @@ -20,32 +194,44 @@ class CodeWarsBadge extends HTMLElement { }); } - // fetch the data from the Codewars API async fetchActivity() { const response = await fetch( - `https://www.codewars.com/api/v1/users/${this.userName}` + `https://www.codewars.com/api/v1/users/${this.userName}` // this is an object created by json ); const data = await response.json(); - this.userData = data; // set the userData property with the fetched data + this.userData = data; } + // ONLY ONE render() method: render() { this.shadowRoot.innerHTML = ` - - ${this.userData.ranks.overall.name} - `; + +
+
${this.userData.username}
+
Challenges: ${this.userData.codeChallenges.totalCompleted}
+
JavaScript Score: ${this.userData.ranks.languages.javascript.score}
+
`; } } customElements.define("codewars-badge", CodeWarsBadge); +console.log("testing"); + + + + +// this is the api info of my account +//https://www.codewars.com/api/v1/users/BaselAdoum +//code tested. i finished a kata after i rendered the code. it moved from 19 completed challenges +// to 20 completed challenges. YAAAAAAAAAAAAAAAAAAY \ No newline at end of file