Advertisement
Guest User

Untitled

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