Skip to content

Commit

Permalink
remove vue-apollo from MyStarsThisYear
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenOutman committed Jun 29, 2018
1 parent c3da542 commit c511aaa
Showing 1 changed file with 0 additions and 140 deletions.
140 changes: 0 additions & 140 deletions src/components/MyStars.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,152 +38,12 @@
</template>

<script>
import gql from 'graphql-tag'
import EventBus from '../bus'
import { graphqlFetchRepoStarsThisYear, graphqlFetchViewerBestarredRepos } from '@/utils';
const YEAR = new Date().getFullYear()
export default {
name: 'MyStars',
apollo: {
repositories: {
query: gql`
query MyBestarredRepos($after: String) {
viewer {
login
repositories(first: 100, after: $after, orderBy: { field: STARGAZERS, direction: DESC }) {
nodes {
nameWithOwner
stargazers {
totalCount
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
`,
fetchPolicy: 'network-only',
variables() {
return {
after: this.afterPointer,
}
},
skip() {
return !this.useGraphQL || !this.requesting
},
// @see https://github.com/Akryum/vue-apollo/issues/48
manual: true,
result({ data, loading }) {
if (!loading) {
const { login, repositories: { nodes, pageInfo: { endCursor, hasNextPage } } } = data.viewer
this.viewer = login
this.reposWithStars = [...this.reposWithStars, ...nodes.filter(repository => repository.stargazers.totalCount > 0).map(repository => [...repository.nameWithOwner.split('/'), repository.stargazers.totalCount])]
if (hasNextPage && !nodes.find(repository => repository.stargazers.totalCount <= 0)) {
this.afterPointer = endCursor
} else if (this.reposWithStars.length) {
this.reposWithStars.sort(([owner1, repo1, stars1], [owner2, repo2, stars2]) => {
if (owner1 === this.viewer && owner2 !== this.viewer) {
return -1
}
if (owner2 === this.viewer && owner1 !== this.viewer) {
return 1
}
return stars2 - stars1
})
const repo = this.reposWithStars[0]
this.username = repo[0]
this.repo = repo[1]
}
}
},
error({ networkError }) {
this.requesting = false
if (+networkError.statusCode > 400) {
EventBus.$emit('require:accessToken', this.start)
}
},
},
repository: {
query: gql`
query RepoStars($owner: String!, $name: String!, $beforePointer: String) {
repository(owner: $owner, name: $name) {
stargazers(after: $beforePointer, first: 100, orderBy: { direction: DESC, field: STARRED_AT }) {
edges {
starredAt
},
pageInfo {
endCursor
hasPreviousPage
hasNextPage
}
}
}
}
`,
fetchPolicy: 'network-only',
variables() {
return {
owner: this.username,
name: this.repo,
beforePointer: this.beforePointer,
}
},
skip() {
return !this.useGraphQL || !this.requesting || !this.username || !this.repo
},
manual: true,
result({ data, loading }) {
if (!loading) {
const { stargazers: { edges, pageInfo: { endCursor, hasPreviousPage, hasNextPage } } } = data.repository
const starsFromPreviousYears = edges.filter(star => star.starredAt.substr(0, 4) !== `${YEAR}`).length
const indexOfRepo = this.reposWithStars.indexOf(this.reposWithStars.find(([owner, name]) => owner === this.username && name === this.repo))
if (starsFromPreviousYears < edges.length) {
if (!hasPreviousPage) {
this.chartData.push([this.repo, 0, this.username])
}
const lastChartData = this.chartData.pop()
lastChartData[1] += edges.length - starsFromPreviousYears
this.chartData.push(lastChartData)
// this.chartData[this.chartData.length - 1][1] += edges.length - starsFromPreviousYears
}
if (!hasNextPage || starsFromPreviousYears > 0) {
if (indexOfRepo < this.reposWithStars.length - 1) {
const repo = this.reposWithStars[indexOfRepo + 1]
this.username = repo[0]
this.repo = repo[1]
this.beforePointer = null
} else {
this.requesting = false
this.username = ''
this.repo = ''
this.afterPointer = null
this.beforePointer = null
}
} else {
this.beforePointer = endCursor
}
}
},
error({ networkError }) {
if (+networkError.statusCode > 400) {
this.requesting = false
EventBus.$emit('require:accessToken', this.start)
}
},
},
},
data() {
return {
viewer: '',
Expand Down

0 comments on commit c511aaa

Please sign in to comment.