feat: use allConversations for filtered view

This commit is contained in:
Shivam Mishra
2025-09-19 15:01:45 +05:30
parent d06b66319e
commit bf400fb02e
3 changed files with 40 additions and 17 deletions
@@ -74,9 +74,14 @@ const getters = {
},
getMineChats: (_state, _, __, rootGetters) => activeFilters => {
const currentUserID = rootGetters.getCurrentUser?.id;
const tabConversations = _state.conversationsByTab.me || [];
return tabConversations.filter(conversation => {
// Use allConversations if there are applied filters, otherwise use tab cache
const hasAppliedFilters = _state.appliedFilters?.length > 0;
const conversations = hasAppliedFilters
? _state.allConversations
: _state.conversationsByTab.me || [];
return conversations.filter(conversation => {
const { assignee } = conversation.meta;
const isAssignedToMe = assignee && assignee.id === currentUserID;
const shouldFilter = applyPageFilters(conversation, activeFilters);
@@ -97,8 +102,13 @@ const getters = {
return hasAppliedFilters ? filterQueryGenerator(_state.appliedFilters) : [];
},
getUnAssignedChats: _state => activeFilters => {
const tabConversations = _state.conversationsByTab.unassigned || [];
return tabConversations.filter(conversation => {
// Use allConversations if there are applied filters, otherwise use tab cache
const hasAppliedFilters = _state.appliedFilters?.length > 0;
const conversations = hasAppliedFilters
? _state.allConversations
: _state.conversationsByTab.unassigned || [];
return conversations.filter(conversation => {
const isUnAssigned = !conversation.meta.assignee;
const shouldFilter = applyPageFilters(conversation, activeFilters);
return isUnAssigned && shouldFilter;
@@ -108,12 +118,17 @@ const getters = {
const currentUser = rootGetters.getCurrentUser;
const currentUserId = rootGetters.getCurrentUser.id;
const currentAccountId = rootGetters.getCurrentAccountId;
const tabConversations = _state.conversationsByTab.all || [];
// Use allConversations if there are applied filters, otherwise use tab cache
const hasAppliedFilters = _state.appliedFilters?.length > 0;
const conversations = hasAppliedFilters
? _state.allConversations
: _state.conversationsByTab.all || [];
const permissions = getUserPermissions(currentUser, currentAccountId);
const userRole = getUserRole(currentUser, currentAccountId);
return tabConversations.filter(conversation => {
return conversations.filter(conversation => {
const shouldFilter = applyPageFilters(conversation, activeFilters);
const allowedForRole = applyRoleFilter(
conversation,
@@ -42,8 +42,8 @@ const getTabFromFilterType = filterType => {
if (filterType === 'me') return 'me';
if (filterType === 'unassigned') return 'unassigned';
if (filterType === 'all') return 'all';
// For appliedFilters and other cases, default to 'all'
return 'all';
// For appliedFilters and other cases, return null to use allConversations
return null;
};
export const buildConversationList = (
@@ -55,15 +55,17 @@ export const buildConversationList = (
const { payload: conversationList, meta: metaData } = responseData;
const tab = getTabFromFilterType(filterType);
// Use tab-scoped mutation
context.commit(types.SET_TAB_CONVERSATION, {
conversations: conversationList,
tab,
});
context.commit(types.SET_ACTIVE_TAB, tab);
// Keep legacy mutation for backward compatibility during migration
context.commit(types.SET_ALL_CONVERSATION, conversationList);
if (tab) {
// Use tab-scoped mutation for basic assignee tabs
context.commit(types.SET_TAB_CONVERSATION, {
conversations: conversationList,
tab,
});
context.commit(types.SET_ACTIVE_TAB, tab);
} else {
// Use allConversations for filtered views (appliedFilters, folders, etc.)
context.commit(types.SET_ALL_CONVERSATION, conversationList);
}
context.dispatch('conversationStats/set', metaData);
context.dispatch(
@@ -92,6 +92,12 @@ export const mutations = {
[types.EMPTY_ALL_CONVERSATION](_state) {
_state.allConversations = [];
_state.selectedChatId = null;
// Also clear all tab caches so UI renders empty state immediately
_state.conversationsByTab = {
me: [],
unassigned: [],
all: [],
};
},
[types.EMPTY_TAB_CONVERSATION](_state, tab) {
if (_state.conversationsByTab[tab]) {