TelegramPWA/src/modules/actions/ui/localSearch.ts
Alexander Zinchuk c3201cf632 Revert "Better browser history support (#1125)"
This reverts commit 3c19438f1a9f6db9a06dc3b48bd06d062befe0b8.
2021-06-14 22:12:34 +03:00

60 lines
1.8 KiB
TypeScript

import { addReducer } from '../../../lib/teact/teactn';
import {
updateLocalTextSearch,
replaceLocalTextSearchResults,
updateLocalMediaSearchType,
} from '../../reducers';
import { MEMO_EMPTY_ARRAY } from '../../../util/memo';
import { selectCurrentMessageList } from '../../selectors';
import { buildChatThreadKey } from '../../helpers';
addReducer('openLocalTextSearch', (global) => {
const { chatId, threadId } = selectCurrentMessageList(global) || {};
if (!chatId || !threadId) {
return undefined;
}
return updateLocalTextSearch(global, chatId, threadId, true);
});
addReducer('closeLocalTextSearch', (global) => {
const { chatId, threadId } = selectCurrentMessageList(global) || {};
if (!chatId || !threadId) {
return undefined;
}
global = updateLocalTextSearch(global, chatId, threadId, false);
global = replaceLocalTextSearchResults(global, chatId, threadId, undefined);
return global;
});
addReducer('setLocalTextSearchQuery', (global, actions, payload) => {
const { chatId, threadId } = selectCurrentMessageList(global) || {};
if (!chatId || !threadId) {
return undefined;
}
const { query } = payload!;
const chatThreadKey = buildChatThreadKey(chatId, threadId);
const { query: currentQuery } = global.localTextSearch.byChatThreadKey[chatThreadKey] || {};
if (query !== currentQuery) {
global = replaceLocalTextSearchResults(global, chatId, threadId, MEMO_EMPTY_ARRAY);
}
global = updateLocalTextSearch(global, chatId, threadId, true, query);
return global;
});
addReducer('setLocalMediaSearchType', (global, actions, payload) => {
const { chatId } = selectCurrentMessageList(global) || {};
if (!chatId) {
return undefined;
}
const { mediaType } = payload!;
return updateLocalMediaSearchType(global, chatId, mediaType);
});