Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. import "./assets/scss/app.scss";
  2. import $ from "cash-dom";
  3.  
  4. export class App {
  5. initializeApp() {
  6. $(".load-username").on("click", e => {
  7. let userName = $(".username.input").val();
  8. const regex = /[a-z0-9-_]/;
  9. const re = /[A-Z]/;
  10.  
  11. if (userName === "" || !regex.test(userName) || re.test(userName)) {
  12. $(".username").addClass(".input is-danger");
  13. } else {
  14. $(".username").removeClass(".input is-danger");
  15. console.log("pokazuje loader");
  16. $("#spinner").removeClass("is-hidden");
  17. fetch(`https://api.github.com/users/${userName}`)
  18. .then(response => {
  19. if (response.ok) {
  20. response.json().then(body => {
  21. this.profile = body;
  22. this.update_profile();
  23. $("#spinner").addClass("is-hidden");
  24.  
  25. fetch(`https://api.github.com/users/${userName}/events/public`)
  26. .then(res => res.json())
  27. .then(data => {
  28. this.events = data
  29. .map(el => {
  30. if (
  31. el.type === "PullRequestEvent" ||
  32. el.type === "PullRequestReviewCommentEvent"
  33. ) {
  34. return el;
  35. }
  36. })
  37. .filter(el => typeof el !== "undefined");
  38.  
  39. console.log(this.events);
  40.  
  41. this.upadate_history();
  42. })
  43. .catch(err => console.log(err));
  44. });
  45. }
  46. })
  47. .catch(err => console.log(err));
  48. }
  49. });
  50. }
  51.  
  52. update_profile() {
  53. $("#profile-name").text($(".username.input").val());
  54. $("#profile-image").attr("src", this.profile.avatar_url);
  55. $("#profile-url")
  56. .attr("href", this.profile.html_url)
  57. .text(this.profile.login);
  58. $("#profile-bio").text(this.profile.bio || "(no information)");
  59. }
  60. upadate_history() {
  61. if (this.events.legth > 0) {
  62. $("#avatar-is-1").attr("src", this.profile.avatar_url);
  63. $("#name-is-1")
  64. .attr("href", this.profile.html_url)
  65. .text(this.profile.login);
  66.  
  67. $("#heading-is-1").text(this.events[0].created_at);
  68. $("#event-is-1").attr("href", this.events[0].payload.pull_request.url);
  69. $("#text-content-1-1").text(this.events[0].payload.action);
  70.  
  71. $("#repo-is-1")
  72. .attr("href", this.events[0].repo.url)
  73. .text(this.events[0].repo.name);
  74. if (this.events[0].type === "PullRequestReviewCommentEvent") {
  75. $("#text-content-1-2").text("to");
  76. $("#comment-is-1")
  77. .attr("href", this.events[0].payload.comment.url)
  78. .text("comment");
  79. }
  80.  
  81. $("#avatar-is-primary").attr("src", this.profile.avatar_url);
  82. $("#name-is-primary")
  83. .attr("href", this.profile.html_url)
  84. .text(this.profile.login);
  85. $("#heading-is-primary").text(this.events[1].created_at);
  86. $("#text-content-2-1").text(this.events[1].payload.action);
  87. $("#text-content-2-2").hide();
  88. $("#action-is-primary").hide();
  89. $("repo-is-primary")
  90. .attr("href", this.events[1].repo.url)
  91. .text(this.events[1].repo.name);
  92. $("#event-is-primary").attr(
  93. "href",
  94. this.events[1].payload.pull_request.url
  95. );
  96. if (this.events[1].type === "PullRequestReviewCommentEvent") {
  97. $("#text-content-2-2")
  98. .text("to")
  99. .show();
  100. $("#action-is-primary")
  101. .attr("href", this.events[0].payload.comment.url)
  102. .text("comment")
  103. .show();
  104. }
  105.  
  106. $("#avatar-is-3").attr("src", this.profile.avatar_url);
  107. $("#name-is-3")
  108. .attr("href", this.profile.html_url)
  109. .text(this.profile.login);
  110. $("#heading-is-3").text(this.events[2].created_at);
  111. $("#text-content-3-1").text(this.events[2].payload.action);
  112. $("#repo-is-3")
  113. .attr("href", this.events[2].repo.url)
  114. .text(this.events[2].repo.name);
  115. $("event-is-3").attr("href", this.events[2].payload.pull_request.url);
  116.  
  117. if (this.events[2].type === "PullRequestReviewCommentEvent") {
  118. $("#text-content-3-2").text("to");
  119. $("#comment-is-3")
  120. .attr("href", this.events[2].payload.comment.url)
  121. .text("comment");
  122. }
  123. } else {
  124. alert(`User don't have any pull request events!`);
  125. }
  126. }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement