Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import './assets/scss/app.scss';
- import $ from 'cash-dom';
- export class App {
- initializeApp() {
- $('.load-username').on('click', e => {
- let userName = $('.username.input').val();
- const regex = /[a-z0-9-_]/
- const re = /[A-Z]/
- if(userName === '' || !regex.test(userName) || re.test(userName))
- {
- $('.username').addClass('.input is-danger')
- }else {
- $('.username').removeClass('.input is-danger')
- $('#spinner').removeClass('.loader is-hidden')
- fetch(`https://api.github.com/users/${userName}`)
- .then((response)=>
- {
- $('#spinner').addClass('.loader is-hidden')
- if(response.ok)
- {
- response.json(body => {
- this.profile = body;
- this.update_profile();
- fetch(`https://api.github.com/users/${userName}/events/public`)
- .then(res =>
- res.json()
- )
- .then(data => {
- this.events = data.map(el => {
- if(el.type === 'PullRequestEvent' || el.type === 'PullRequestReviewCommentEvent') {
- return el;
- }
- }).filter(el => typeof el !== 'undefined')
- if(this.events.length > 0)
- {
- this.upadate_history()
- }
- else {
- alert(`User don't have pull requests`)
- }
- })
- })
- }
- }
- )
- .catch(err => console.log(err))
- }
- })
- }
- update_profile() {
- $('#profile-name').text($('.username.input').val())
- $('#profile-image').attr('src', this.profile.avatar_url)
- $('#profile-url').attr('href', this.profile.html_url).text(this.profile.login)
- $('#profile-bio').text(this.profile.bio || '(no information)')
- }
- upadate_history() {
- {
- $('#avatar-is-1').attr('src', this.profile.avatar_url)
- $('#name-is-1').attr('href', this.profile.html_url).text(this.profile.login)
- $('#heading-is-1').text(this.events[0].created_at)
- $('#event-is-1').attr('href',this.events[0].payload.pull_request.url)
- $('#text-content-1-1').text(this.events[0].payload.action)
- $('#repo-is-1').attr('href',this.events[0].repo.url ).text(this.events[0].repo.name)
- if(this.events[0].type === 'PullRequestReviewCommentEvent')
- {
- $('#text-content-1-2').text('to')
- $('#comment-is-1').attr('href', this.events[0].payload.comment.url).text('comment')
- }
- $('#avatar-is-primary').attr('src', this.profile.avatar_url)
- $('#name-is-primary').attr('href', this.profile.html_url).text(this.profile.login)
- $('#heading-is-primary').text(this.events[1].created_at)
- $('#text-content-2-1').text(this.events[1].payload.action)
- $('#text-content-2-2').hide()
- $('#action-is-primary').hide()
- $('repo-is-primary').attr('href',this.events[1].repo.url ).text(this.events[1].repo.name)
- $('#event-is-primary').attr('href',this.events[1].payload.pull_request.url)
- if(this.events[1].type === 'PullRequestReviewCommentEvent')
- {
- $('#text-content-2-2').text('to').show()
- $('#action-is-primary').attr('href', this.events[0].payload.comment.url).text('comment').show()
- }
- $('#avatar-is-3').attr('src', this.profile.avatar_url)
- $('#name-is-3').attr('href', this.profile.html_url).text(this.profile.login)
- $('#heading-is-3').text(this.events[2].created_at)
- $('#text-content-3-1').text(this.events[2].payload.action)
- $('#repo-is-3').attr('href',this.events[2].repo.url).text(this.events[2].repo.name)
- $('event-is-3').attr('href',this.events[2].payload.pull_request.url)
- if(this.events[2].type === 'PullRequestReviewCommentEvent')
- {
- $('#text-content-3-2').text('to')
- $('#comment-is-3').attr('href', this.events[2].payload.comment.url).text('comment')
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement