chore: Search improvements (#10801)

- Adds pagination support for search.
- Use composition API on all search related component.
- Minor UI improvements.
- Adds missing specs

Loom video
https://www.loom.com/share/5b01afa5c9204e7d97ff81b215621dde?sid=82ca6d22-ca8c-4d5e-8740-ba06ca4051ba
This commit is contained in:
Sivin Varghese
2025-02-03 19:34:50 +05:30
committed by GitHub
parent 3fb77fe806
commit bd94e5062d
20 changed files with 898 additions and 646 deletions

View File

@@ -75,11 +75,10 @@ export const actions = {
});
}
},
async contactSearch({ commit }, { q }) {
commit(types.CONTACT_SEARCH_SET, []);
async contactSearch({ commit }, { q, page = 1 }) {
commit(types.CONTACT_SEARCH_SET_UI_FLAG, { isFetching: true });
try {
const { data } = await SearchAPI.contacts({ q });
const { data } = await SearchAPI.contacts({ q, page });
commit(types.CONTACT_SEARCH_SET, data.payload.contacts);
} catch (error) {
// Ignore error
@@ -87,11 +86,10 @@ export const actions = {
commit(types.CONTACT_SEARCH_SET_UI_FLAG, { isFetching: false });
}
},
async conversationSearch({ commit }, { q }) {
commit(types.CONVERSATION_SEARCH_SET, []);
async conversationSearch({ commit }, { q, page = 1 }) {
commit(types.CONVERSATION_SEARCH_SET_UI_FLAG, { isFetching: true });
try {
const { data } = await SearchAPI.conversations({ q });
const { data } = await SearchAPI.conversations({ q, page });
commit(types.CONVERSATION_SEARCH_SET, data.payload.conversations);
} catch (error) {
// Ignore error
@@ -99,11 +97,10 @@ export const actions = {
commit(types.CONVERSATION_SEARCH_SET_UI_FLAG, { isFetching: false });
}
},
async messageSearch({ commit }, { q }) {
commit(types.MESSAGE_SEARCH_SET, []);
async messageSearch({ commit }, { q, page = 1 }) {
commit(types.MESSAGE_SEARCH_SET_UI_FLAG, { isFetching: true });
try {
const { data } = await SearchAPI.messages({ q });
const { data } = await SearchAPI.messages({ q, page });
commit(types.MESSAGE_SEARCH_SET, data.payload.messages);
} catch (error) {
// Ignore error
@@ -112,9 +109,7 @@ export const actions = {
}
},
async clearSearchResults({ commit }) {
commit(types.MESSAGE_SEARCH_SET, []);
commit(types.CONVERSATION_SEARCH_SET, []);
commit(types.CONTACT_SEARCH_SET, []);
commit(types.CLEAR_SEARCH_RESULTS);
},
};
@@ -123,13 +118,13 @@ export const mutations = {
state.records = records;
},
[types.CONTACT_SEARCH_SET](state, records) {
state.contactRecords = records;
state.contactRecords = [...state.contactRecords, ...records];
},
[types.CONVERSATION_SEARCH_SET](state, records) {
state.conversationRecords = records;
state.conversationRecords = [...state.conversationRecords, ...records];
},
[types.MESSAGE_SEARCH_SET](state, records) {
state.messageRecords = records;
state.messageRecords = [...state.messageRecords, ...records];
},
[types.SEARCH_CONVERSATIONS_SET_UI_FLAG](state, uiFlags) {
state.uiFlags = { ...state.uiFlags, ...uiFlags };
@@ -146,6 +141,11 @@ export const mutations = {
[types.MESSAGE_SEARCH_SET_UI_FLAG](state, uiFlags) {
state.uiFlags.message = { ...state.uiFlags.message, ...uiFlags };
},
[types.CLEAR_SEARCH_RESULTS](state) {
state.contactRecords = [];
state.conversationRecords = [];
state.messageRecords = [];
},
};
export default {