diff --git a/package.json b/package.json index 2782b0d..4d5803b 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "vue-analytics": "^5.16.1", "vue-axios": "^2.1.4", "vue-clipboard2": "^0.2.1", + "vue-infinite-scroll": "^2.0.2", "vue-moment": "^4.0.0", "vue-router": "^3.0.2", "vuetify": "^1.3.11", diff --git a/src/services/gitlab/client.js b/src/services/gitlab/client.js index 67e640f..e2e4af0 100644 --- a/src/services/gitlab/client.js +++ b/src/services/gitlab/client.js @@ -135,8 +135,8 @@ export default class Client { .then(result => result.data); } - fetchTodos() { - return this.client.get("/api/v4/todos"); + fetchTodos(page = 1) { + return this.client.get(`/api/v4/todos?page=${page}`); } fetchIssues() { diff --git a/src/store/modules/todo.js b/src/store/modules/todo.js index 15e95f3..236eceb 100644 --- a/src/store/modules/todo.js +++ b/src/store/modules/todo.js @@ -4,10 +4,32 @@ import gitlab from "@/gitlab"; const state = { todos: {}, + lastLoadedPage: 1, + isDataLoading: false, todoSize: 0 }; const actions = { + loadNexPageTodos({ state, commit }){ + if(state.todos.length === 0){ + commit("setLastLoadedPage", 1); + } + commit("setIsDataLoading", true); + gitlab + .get() + .client.fetchTodos(state.lastLoadedPage + 1) + .then(nextPageTodos => { + if(nextPageTodos.data.length > 0){ + nextPageTodos.data.forEach(todo => { + commit("addTodo", todo); + }); + commit("setLastLoadedPage", state.lastLoadedPage + 1); + } + }).finally(() => { + commit("setIsDataLoading", false); + }); + }, + addTodo({ commit }, todo) { commit("addTodo", todo); }, @@ -58,6 +80,14 @@ const mutations = { setTodoSize(state, size) { state.todoSize = parseInt(size); + }, + + setIsDataLoading(state, value){ + state.isDataLoading = value; + }, + + setLastLoadedPage(state, value){ + state.lastLoadedPage = value; } }; diff --git a/src/views/Todos.vue b/src/views/Todos.vue index 3495696..1161558 100644 --- a/src/views/Todos.vue +++ b/src/views/Todos.vue @@ -6,7 +6,8 @@ done_all - +