Skip to content

Commit

Permalink
fix: Pagination bug in chat list (#6899)
Browse files Browse the repository at this point in the history
* fix: Pagination bug in chat list

* chore: Review fixes

* Improves variable namings

---------

Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com>
  • Loading branch information
iamsivin and nithindavid committed Apr 25, 2023
1 parent c071f66 commit b529baa
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions app/javascript/dashboard/components/ChatList.vue
Expand Up @@ -250,6 +250,9 @@ export default {
...filter,
attributeName: this.$t(`FILTER.ATTRIBUTES.${filter.attributeI18nKey}`),
})),
// chatsOnView is to store the chats that are currently visible on the screen,
// which mirrors the conversationList.
chatsOnView: [],
foldersQuery: {},
showAddFoldersModal: false,
showDeleteFoldersModal: false,
Expand Down Expand Up @@ -349,18 +352,39 @@ export default {
this.currentPageFilterKey
);
},
activeAssigneeTabCount() {
const { activeAssigneeTab } = this;
const count = this.assigneeTabItems.find(
item => item.key === activeAssigneeTab
).count;
return count;
},
conversationFilters() {
return {
inboxId: this.conversationInbox ? this.conversationInbox : undefined,
assigneeType: this.activeAssigneeTab,
status: this.activeStatus,
page: this.currentPage + 1,
page: this.conversationListPagination,
labels: this.label ? [this.label] : undefined,
teamId: this.teamId || undefined,
conversationType: this.conversationType || undefined,
folders: this.hasActiveFolders ? this.savedFoldersValue : undefined,
};
},
conversationListPagination() {
const conversationsPerPage = 25;
const isNoFiltersOrFoldersAndChatListNotEmpty =
!this.hasAppliedFiltersOrActiveFolders && this.chatsOnView !== [];
const isUnderPerPage =
this.chatsOnView.length < conversationsPerPage &&
this.activeAssigneeTabCount < conversationsPerPage &&
this.activeAssigneeTabCount > this.chatsOnView.length;
if (isNoFiltersOrFoldersAndChatListNotEmpty && isUnderPerPage) {
return 1;
}
return this.currentPage + 1;
},
pageTitle() {
if (this.hasAppliedFilters) {
return this.$t('CHAT_LIST.TAB_HEADING');
Expand Down Expand Up @@ -402,7 +426,6 @@ export default {
} else {
conversationList = [...this.chatLists];
}
return conversationList;
},
activeFolder() {
Expand Down Expand Up @@ -451,6 +474,9 @@ export default {
this.resetAndFetchData();
}
},
chatLists() {
this.chatsOnView = this.conversationList;
},
},
mounted() {
this.$store.dispatch('setChatFilter', this.activeStatus);
Expand Down

0 comments on commit b529baa

Please sign in to comment.