Skip to content

Commit e38c732

Browse files
committed
setting up pagination for respositories list
1 parent f7a78b9 commit e38c732

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/components/RepositoriesListComponent.vue

+14-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export default {
3737
},
3838
data () {
3939
return {
40-
loading: true
40+
loading: true,
41+
pageNumber: 1
4142
}
4243
},
4344
computed: {
@@ -50,6 +51,18 @@ export default {
5051
this.loading = false;
5152
})
5253
54+
let vm = this;
55+
$(window).scroll(function() {
56+
if (($(window).innerHeight() + $(window).scrollTop()) >= $("body").height()) {
57+
if (vm.loading === false) {
58+
vm.loading = true
59+
vm.pageNumber++
60+
vm.$store.dispatch('getRepositories', vm.pageNumber).then(() => {
61+
vm.loading = false
62+
})
63+
}
64+
}
65+
});
5366
}
5467
}
5568
</script>

src/store/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ export const store = new Vuex.Store({
2929
mutations: {
3030
getRepositories (state, payload) {
3131
this.state.repositories = this.state.repositories.concat(payload)
32-
return this.state.repositories
32+
return this.state.repositories.concat(payload)
3333
}
3434
},
3535
actions: {
36-
getRepositories (context) {
37-
return axios.get(`https://api.github.com/search/repositories?q=created:>2017-10-22&sort=stars&order=desc`)
36+
getRepositories (context, page) {
37+
return axios.get(`https://api.github.com/search/repositories?q=created:>2017-10-22&sort=stars&order=desc&page=${page}`)
3838
.then((res) => {
3939
context.commit('getRepositories', res.data.items)
4040
})

0 commit comments

Comments
 (0)