feat: Revamps search to use new search API's (#6582)

* feat: Revamps search to use new search API's

* Fixes search result spacing

* Fixes message result

* Fixes issue with empty search results

* Remove console errors

* Remove console errors

* Fix console errors, canned responses

* Fixes message rendering on results

* Highlights search term

* Fixes html rendering for emails

* FIxes email rendering issues

* Removes extra spaces and line breaks

---------

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
Nithin David Thomas
2023-03-03 20:58:21 +05:30
committed by GitHub
parent 2a385f377c
commit 88ed028a06
24 changed files with 896 additions and 142 deletions

View File

@@ -1,7 +1,8 @@
import ConversationAPI from '../../api/inbox/conversation';
import SearchAPI from '../../api/search';
import types from '../mutation-types';
export const initialState = {
records: [],
fullSearchRecords: {},
uiFlags: {
isFetching: false,
},
@@ -11,6 +12,9 @@ export const getters = {
getConversations(state) {
return state.records;
},
getFullSearchRecords(state) {
return state.fullSearchRecords;
},
getUIFlags(state) {
return state.uiFlags;
},
@@ -26,12 +30,29 @@ export const actions = {
try {
const {
data: { payload },
} = await ConversationAPI.search({ q });
} = await SearchAPI.get({ q });
commit(types.SEARCH_CONVERSATIONS_SET, payload);
} catch (error) {
// Ignore error
} finally {
commit(types.SEARCH_CONVERSATIONS_SET_UI_FLAG, { isFetching: false });
commit(types.SEARCH_CONVERSATIONS_SET_UI_FLAG, {
isFetching: false,
});
}
},
async fullSearch({ commit }, { q }) {
commit(types.FULL_SEARCH_SET, []);
if (!q) {
return;
}
commit(types.FULL_SEARCH_SET_UI_FLAG, { isFetching: true });
try {
const { data } = await SearchAPI.get({ q });
commit(types.FULL_SEARCH_SET, data.payload);
} catch (error) {
// Ignore error
} finally {
commit(types.FULL_SEARCH_SET_UI_FLAG, { isFetching: false });
}
},
};
@@ -40,9 +61,15 @@ export const mutations = {
[types.SEARCH_CONVERSATIONS_SET](state, records) {
state.records = records;
},
[types.FULL_SEARCH_SET](state, records) {
state.fullSearchRecords = records;
},
[types.SEARCH_CONVERSATIONS_SET_UI_FLAG](state, uiFlags) {
state.uiFlags = { ...state.uiFlags, ...uiFlags };
},
[types.FULL_SEARCH_SET_UI_FLAG](state, uiFlags) {
state.uiFlags = { ...state.uiFlags, ...uiFlags };
},
};
export default {