TT#23958 Implement infinite scroll

Change-Id: Iae794486adfefea685799802ab036ee4c1957542
changes/37/16837/4
raxelsen 8 years ago
parent ddabf7c1a0
commit 93ea8818ea

@ -1,11 +1,18 @@
import Vue from 'vue'; import Vue from 'vue';
import _ from 'lodash';
import { getJsonBody } from './utils' import { getJsonBody } from './utils'
export function getConversations(id) { export function getConversations(id, page, rows) {
let params = { subscriber_id: id, page: page, rows: rows };
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
Vue.http.get('/api/conversations/?subscriber_id=' + id).then((result)=>{ Vue.http.get('/api/conversations/', { params: params }).then((result)=>{
resolve(getJsonBody(result.body)._embedded['ngcp:conversations']); let jsonBody = getJsonBody(result.body);
if (_.has(jsonBody, "_embedded.ngcp:conversations")) {
resolve(jsonBody._embedded['ngcp:conversations']);
} else {
reject(new Error('No items returned for this page.'))
};
}).catch((err)=>{ }).catch((err)=>{
reject(err); reject(err);
}); });

@ -1,5 +1,6 @@
<template> <template>
<csc-page :title="$t('pages.conversations.title')"> <csc-page :title="$t('pages.conversations.title')">
<q-infinite-scroll :handler="loadMore" :offset=1 ref="infinite">
<q-card v-for="conversation in conversations" :key="conversation.caller" <q-card v-for="conversation in conversations" :key="conversation.caller"
class="conversation-card"> class="conversation-card">
<csc-collapsible :icon="getCollapsibleIcons(conversation)" <csc-collapsible :icon="getCollapsibleIcons(conversation)"
@ -13,6 +14,10 @@
</q-card-actions> </q-card-actions>
</div> </div>
</q-card> </q-card>
<div slot="message" class="row justify-center">
<q-spinner-dots :size="40"></q-spinner-dots>
</div>
</q-infinite-scroll>
</csc-page> </csc-page>
</template> </template>
@ -20,30 +25,36 @@
import CscPage from '../CscPage' import CscPage from '../CscPage'
import CscCollapsible from '../card/CscCollapsible' import CscCollapsible from '../card/CscCollapsible'
import { QBtn, QCardActions, QCard, import { QBtn, QCardActions, QCard,
QCardSeparator } from 'quasar-framework' QCardSeparator, QInfiniteScroll, QSpinnerDots } from 'quasar-framework'
export default { export default {
data () { data () {
return { return {
conversations: []
} }
}, },
mounted() {
this.$store.dispatch('conversations/loadConversations').then(() => {
this.conversations = this.$store.state.conversations.
conversations;
}).catch((err) => {
console.log(err);
});
},
components: { components: {
CscPage, CscPage,
QBtn, QBtn,
QCard, QCard,
QCardActions, QCardActions,
QCardSeparator, QCardSeparator,
CscCollapsible CscCollapsible,
QInfiniteScroll,
QSpinnerDots
},
computed: {
conversations() {
return this.$store.state.conversations.conversations;
}
}, },
methods: { methods: {
loadMore(index, done) {
this.$store.dispatch('conversations/loadConversations').then(() => {
done();
}).catch((err) => {
done();
this.$refs.infinite.stop();
});
},
hasCallOption(type) { hasCallOption(type) {
return (['call', 'call forward', 'sms', 'voicemail'] return (['call', 'call forward', 'sms', 'voicemail']
.indexOf(type) > -1); .indexOf(type) > -1);
@ -85,4 +96,6 @@
padding 15px padding 15px
.q-btn .q-btn
margin-bottom -10px margin-bottom -10px
.q-infinite-scroll-message
margin-bottom 50px
</style> </style>

@ -7,6 +7,8 @@ import { getConversations } from '../api/conversations';
export default { export default {
namespaced: true, namespaced: true,
state: { state: {
page: 1,
rows: 10,
conversations: [ conversations: [
] ]
}, },
@ -21,13 +23,14 @@ export default {
}; };
list.push(item); list.push(item);
}) })
state.conversations = list; state.conversations = state.conversations.concat(list);
state.page++;
} }
}, },
actions: { actions: {
loadConversations(context) { loadConversations(context) {
return new Promise((resolve, reject)=>{ return new Promise((resolve, reject)=>{
getConversations(localStorage.getItem('subscriberId')) getConversations(localStorage.getItem('subscriberId'), context.state.page, context.state.rows)
.then((result)=>{ .then((result)=>{
context.commit('loadConversations', result); context.commit('loadConversations', result);
resolve(); resolve();

Loading…
Cancel
Save