From 52bade1b3949265aaa33bd88d863993ab25abcfb Mon Sep 17 00:00:00 2001 From: Shiv Charan Sharma Date: Wed, 25 Feb 2026 14:56:32 +0530 Subject: [PATCH 1/8] feat: add source selection to AskGurbaniBot search --- .../Modals/AskGurbaniBotQuestionModal.tsx | 55 +++++++++++++------ .../SearchResults/AskGurbaniBotSearch.tsx | 35 ++++++++++-- .../components/SearchResults/SearchResults.js | 2 +- 3 files changed, 71 insertions(+), 21 deletions(-) diff --git a/src/js/components/Modals/AskGurbaniBotQuestionModal.tsx b/src/js/components/Modals/AskGurbaniBotQuestionModal.tsx index cac229c5..5923ad37 100644 --- a/src/js/components/Modals/AskGurbaniBotQuestionModal.tsx +++ b/src/js/components/Modals/AskGurbaniBotQuestionModal.tsx @@ -8,7 +8,7 @@ import SearchIcon from '@/components/Icons/Search'; import { toSearchURL } from '@/util'; import Dialog from './Dialog'; -import { SEARCH_TYPES } from '@/constants'; +import { SEARCH_TYPES, SOURCES } from '@/constants'; interface Props { isModalOpen: boolean; @@ -22,24 +22,26 @@ const AskGurbaniBotQuestionModal = (props: Props) => { ({ handleFormSubmit, query, + source, }: { handleFormSubmit: FormEventHandler; query: string; + source: string; }) => - (e: FormEvent) => { - e.preventDefault(); - typeof handleFormSubmit === 'function' && handleFormSubmit(); - history.push( - toSearchURL({ - query, - type: SEARCH_TYPES.ASK_A_QUESTION, - writer: 'all', - source: 'all', - offset: '', - }) - ); - dispatch(setModalOpen('')); - }; + (e: FormEvent) => { + e.preventDefault(); + typeof handleFormSubmit === 'function' && handleFormSubmit(); + history.push( + toSearchURL({ + query, + type: SEARCH_TYPES.ASK_A_QUESTION, + writer: 'all', + source, + offset: '', + }) + ); + dispatch(setModalOpen('')); + }; return ( { handleKeyDown, handleSearchChange, handleSubmit: handleFormSubmit, + source, + handleSearchSourceChange, + isSourceChanged, }) => (
{ onSubmit={handleSubmit({ handleFormSubmit: handleFormSubmit, query, + source, })} >
@@ -102,8 +108,25 @@ const AskGurbaniBotQuestionModal = (props: Props) => {
+
+
+ +
+
- )} + ) + }
diff --git a/src/js/components/SearchResults/AskGurbaniBotSearch.tsx b/src/js/components/SearchResults/AskGurbaniBotSearch.tsx index 2937760a..00c1563d 100644 --- a/src/js/components/SearchResults/AskGurbaniBotSearch.tsx +++ b/src/js/components/SearchResults/AskGurbaniBotSearch.tsx @@ -3,28 +3,39 @@ import SearchForm from "@/components/SearchForm" import SearchIcon from '@/components/Icons/Search'; import { useHistory } from 'react-router-dom'; import { toSearchURL } from '@/util'; -import { SEARCH_TYPES } from '@/constants'; +import { SEARCH_TYPES, SOURCES } from '@/constants'; interface Props { query: string; + source: string; } function AskGurbaniBotSearch(props: Props) { - const { query } = props; + const { query, source } = props; const history = useHistory(); - const handleSubmit = ({ handleFormSubmit, query }: { handleFormSubmit: FormEventHandler, query: string }) => (e: FormEvent) => { + const handleSubmit = ({ handleFormSubmit, query, source }: { handleFormSubmit: FormEventHandler, query: string, source: string }) => (e: FormEvent) => { e.preventDefault(); typeof handleFormSubmit === 'function' && handleFormSubmit(); history.push(toSearchURL({ query, type: SEARCH_TYPES.ASK_A_QUESTION, writer: 'all', - source: 'all', + source, offset: '' })); } + const handleSourceChange = (e: React.ChangeEvent) => { + history.push(toSearchURL({ + query, + type: SEARCH_TYPES.ASK_A_QUESTION, + writer: 'all', + source: e.target.value, + offset: '', + })); + }; + return (
@@ -48,6 +59,7 @@ function AskGurbaniBotSearch(props: Props) { onSubmit={handleSubmit({ handleFormSubmit: handleFormSubmit, query, + source, })} >
@@ -75,6 +87,21 @@ function AskGurbaniBotSearch(props: Props) {
+
+
+ +
+
)} diff --git a/src/js/components/SearchResults/SearchResults.js b/src/js/components/SearchResults/SearchResults.js index 1ee69f35..81405505 100644 --- a/src/js/components/SearchResults/SearchResults.js +++ b/src/js/components/SearchResults/SearchResults.js @@ -51,7 +51,7 @@ export default class SearchResults extends React.PureComponent { return ( <> {askGurbaniBotSearchType && ( - + )} {warning}
    From 19c488ca87fae53656ad3cc330ba740dafcb621d Mon Sep 17 00:00:00 2001 From: Shiv Charan Sharma Date: Wed, 25 Feb 2026 15:03:44 +0530 Subject: [PATCH 2/8] feat: isolate bot search state from main/normal search state - Isolate SearchForm state from local storage by introducing an `isolateFromLocalStorage` prop and using it for the Gurbani Bot search. --- src/js/components/Header.js | 59 +++++++++--------- .../Modals/AskGurbaniBotQuestionModal.tsx | 6 +- src/js/components/SearchForm.js | 60 ++++++++++++------- 3 files changed, 71 insertions(+), 54 deletions(-) diff --git a/src/js/components/Header.js b/src/js/components/Header.js index b291b204..328695c7 100644 --- a/src/js/components/Header.js +++ b/src/js/components/Header.js @@ -93,23 +93,23 @@ class Header extends React.PureComponent { onFormSubmit = ({ handleSubmit, autoDetectGurmukhi, ...data }) => - (e) => { - e.preventDefault(); - e.stopPropagation(); - handleSubmit(); - // Remove the last space in from the searched query. - const isNotAngSearch = SEARCH_TYPES[data.type] !== SEARCH_TYPES.ANG; - if (isNotAngSearch) { - data.query = data.query.trim(); - } + (e) => { + e.preventDefault(); + e.stopPropagation(); + handleSubmit(); + // Remove the last space in from the searched query. + const isNotAngSearch = SEARCH_TYPES[data.type] !== SEARCH_TYPES.ANG; + if (isNotAngSearch) { + data.query = data.query.trim(); + } - const searchParams = { ...data, autoDetectGurmukhi }; - if (data.type === SEARCH_TYPES.AUTO_DETECT && autoDetectGurmukhi) { - searchParams.isGurmukhi = true; - } + const searchParams = { ...data, autoDetectGurmukhi }; + if (data.type === SEARCH_TYPES.AUTO_DETECT && autoDetectGurmukhi) { + searchParams.isGurmukhi = true; + } - this.handleFormSubmit(searchParams); - }; + this.handleFormSubmit(searchParams); + }; handleFormSubmit = (data) => { this.props.history.push(toSearchURL(data)); @@ -146,10 +146,10 @@ class Header extends React.PureComponent { type: defaultType = isAng ? SEARCH_TYPES.ANG.toString() : null, writer: defaultWriter = DEFAULT_SEARCH_WRITER, autoDetectGurmukhi: - defaultAutoDetectGurmukhi = getBooleanFromLocalStorage( - LOCAL_STORAGE_KEY_FOR_AUTO_DETECT_GURMUKHI, - false - ), + defaultAutoDetectGurmukhi = getBooleanFromLocalStorage( + LOCAL_STORAGE_KEY_FOR_AUTO_DETECT_GURMUKHI, + false + ), } = getQueryParams(location.search); const isAskGurbaniBotSearchType = @@ -195,22 +195,21 @@ class Header extends React.PureComponent { } defaultSource={ isAskGurbaniBotSearchType - ? localStorage.getItem(LOCAL_STORAGE_KEY_FOR_SEARCH_SOURCE) || - DEFAULT_SEARCH_SOURCE + ? DEFAULT_SEARCH_SOURCE : defaultSource } defaultType={ isAskGurbaniBotSearchType ? getNumberFromLocalStorage( - LOCAL_STORAGE_KEY_FOR_SEARCH_TYPE, - DEFAULT_SEARCH_TYPE - ) + LOCAL_STORAGE_KEY_FOR_SEARCH_TYPE, + DEFAULT_SEARCH_TYPE + ) : Number(defaultType) } defaultWriter={ isAskGurbaniBotSearchType ? localStorage.getItem(LOCAL_STORAGE_KEY_FOR_SEARCH_WRITER) || - DEFAULT_SEARCH_WRITER + DEFAULT_SEARCH_WRITER : Number(defaultWriter) } defaultAutoDetectGurmukhi={defaultAutoDetectGurmukhi} @@ -457,7 +456,7 @@ class Header extends React.PureComponent { writer, isGurmukhi: parseInt(type) === - SEARCH_TYPES.AUTO_DETECT && + SEARCH_TYPES.AUTO_DETECT && autoDetectGurmukhi, }} value={query} @@ -536,13 +535,13 @@ class Header extends React.PureComponent { ?.filter((e) => source === 'G' || source === 'A' ? !SOURCE_WRITER_FILTER[source].includes( - e.writerID - ) + e.writerID + ) : source !== 'all' - ? SOURCE_WRITER_FILTER[source].includes( + ? SOURCE_WRITER_FILTER[source].includes( e.writerID ) - : true + : true ) .map((writer) => (