Skip to content

Commit 910da28

Browse files
Merge pull request #1814 from Gauravjeetsingh/use-claude-endpoint
Add verse in the AI response
2 parents de30538 + 03bbc08 commit 910da28

File tree

3 files changed

+129
-63
lines changed

3 files changed

+129
-63
lines changed

src/js/components/Layout.js

Lines changed: 83 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import Footer from './Footer';
44
import Banner from './Banner/Banner';
55
import GenericError, { SachKaur, BalpreetSingh } from './GenericError';
66
import PropTypes from 'prop-types';
7-
import { DEFAULT_PAGE_TITLE, LOCAL_STORAGE_KEY_FOR_SESSION_TOKEN, TEXTS } from '../constants';
7+
import {
8+
DEFAULT_PAGE_TITLE,
9+
LOCAL_STORAGE_KEY_FOR_SESSION_TOKEN,
10+
TEXTS,
11+
} from '../constants';
812
import { connect } from 'react-redux';
913
import throttle from 'lodash.throttle';
1014
import {
@@ -13,18 +17,29 @@ import {
1317
OFFLINE_COLOR,
1418
} from '../../../common/constants';
1519
import { ACTIONS, errorEvent } from '../util/analytics';
16-
import { setOnlineMode, closeSettingsPanel, toggleDarkMode } from '../features/actions';
20+
import {
21+
setOnlineMode,
22+
closeSettingsPanel,
23+
toggleDarkMode,
24+
} from '../features/actions';
1725
import { FloatingActions } from './FloatingActions';
1826
import MultipleShabadsDisplay from './MultipleShabadsDisplay';
1927

20-
import { addVisraamClass, isShowFullscreenRoute, isShowAutoScrollRoute, isShowSettingsRoute, getQueryParams, isFalsy } from '../util';
28+
import {
29+
addVisraamClass,
30+
isShowFullscreenRoute,
31+
isShowAutoScrollRoute,
32+
isShowSettingsRoute,
33+
getQueryParams,
34+
isFalsy,
35+
} from '../util';
2136
import { AddFavouriteShabadModal } from './Modals';
2237
import { SEARCH_TYPES } from '../constants';
2338

2439
class Layout extends React.PureComponent {
2540
static defaultProps = {
2641
isHome: false,
27-
title: DEFAULT_PAGE_TITLE
42+
title: DEFAULT_PAGE_TITLE,
2843
};
2944

3045
static propTypes = {
@@ -46,7 +61,7 @@ class Layout extends React.PureComponent {
4661
setOnlineMode: PropTypes.func.isRequired,
4762
toggleDarkMode: PropTypes.func.isRequired,
4863
closeSettingsPanel: PropTypes.func,
49-
history: PropTypes.object
64+
history: PropTypes.object,
5065
};
5166

5267
state = {
@@ -99,7 +114,10 @@ class Layout extends React.PureComponent {
99114
} = this.props;
100115

101116
const queryParams = getQueryParams(this.props.location.search);
102-
const isShowAI = queryParams.type && parseInt(queryParams.type, 10) === SEARCH_TYPES.ASK_A_QUESTION && pathname.includes('/shabad');
117+
const isShowAI =
118+
queryParams.type &&
119+
parseInt(queryParams.type, 10) === SEARCH_TYPES.ASK_A_QUESTION &&
120+
pathname.includes('/shabad');
103121

104122
const isShowFullScreen = isShowFullscreenRoute(pathname);
105123
const isShowAutoScroll = isShowAutoScrollRoute(pathname) && autoScrollMode;
@@ -116,21 +134,29 @@ class Layout extends React.PureComponent {
116134
}
117135
}
118136

119-
const isAddFavoriteShabadModalOpen = props.modalOpened === 'addFavoriteShabad';
137+
const isAddFavoriteShabadModalOpen =
138+
props.modalOpened === 'addFavoriteShabad';
120139

121140
return online || pathname !== '/' ? (
122141
<div className="layout">
123142
<Banner
124143
banner={{
125-
message: 'Help Us Build the Future of SikhiToTheMax! Every donation doubled - dvnetwork.org/sikhitothemax',
126-
link: "dvnetwork.org/sikhitothemax",
127-
label: "Donate now",
128-
type: "3",
144+
message:
145+
'Help Us Build the Future of SikhiToTheMax! Every donation doubled - dvnetwork.org/sikhitothemax',
146+
link: 'dvnetwork.org/sikhitothemax',
147+
label: 'Donate now',
148+
type: '3',
129149
disabled: true,
130150
}}
131151
/>
132-
{isAddFavoriteShabadModalOpen && <AddFavouriteShabadModal open={isAddFavoriteShabadModalOpen} />}
133-
<div className={`pusher ${showMultiViewPanel ? 'enable' : ''} pin-settings ${showPinSettings ? 'active' : ''}`}>
152+
{isAddFavoriteShabadModalOpen && (
153+
<AddFavouriteShabadModal open={isAddFavoriteShabadModalOpen} />
154+
)}
155+
<div
156+
className={`pusher ${
157+
showMultiViewPanel ? 'enable' : ''
158+
} pin-settings ${showPinSettings ? 'active' : ''}`}
159+
>
134160
<Header
135161
defaultQuery={this.props.defaultQuery}
136162
isHome={isHome}
@@ -155,15 +181,16 @@ class Layout extends React.PureComponent {
155181
isShowSettings={isShowSettings}
156182
isShowAI={isShowAI}
157183
onAIClick={this.handleAIClick}
158-
isAIActive={this.state.isAIActive} />
184+
isAIActive={this.state.isAIActive}
185+
/>
159186

160187
{/* AI Dialog */}
161188
{this.state.isAIActive && (
162189
<div className="floating-dialog-container">
163190
<div className="floating-dialog open">
164191
<div className="floating-dialog-header">
165-
<h4>AI Response</h4>
166-
<button
192+
<h4>Gurbani Assistant</h4>
193+
<button
167194
className="floating-dialog-toggle"
168195
onClick={this.handleAIClick}
169196
>
@@ -172,8 +199,16 @@ class Layout extends React.PureComponent {
172199
</div>
173200
{this.state.rephrasedTranslation && (
174201
<div className="floating-dialog-content">
175-
<p className="question">{this.state.rephrasedTranslation.question}</p>
176-
<p className="answer">{this.state.rephrasedTranslation.answer}</p>
202+
<p className="question">
203+
{this.state.rephrasedTranslation.question}
204+
</p>
205+
<p className="answer">
206+
<p className="gurmukhi gurbani-font">
207+
{this.state.rephrasedTranslation.verse.gurmukhi}
208+
</p>
209+
{this.state.rephrasedTranslation.answer}
210+
</p>
211+
<p className="footer">Response generated by GurbaniBot AI.</p>
177212
</div>
178213
)}
179214
</div>
@@ -188,11 +223,12 @@ class Layout extends React.PureComponent {
188223
<GenericError
189224
title={TEXTS.OFFLINE}
190225
description={TEXTS.OFFLINE_DESCRIPTION}
191-
image={SachKaur} />
226+
image={SachKaur}
227+
/>
192228
</div>
193229
<Footer showPinSettings={showPinSettings} />
194230
</>
195-
)
231+
);
196232
}
197233

198234
updateTheme() {
@@ -202,25 +238,27 @@ class Layout extends React.PureComponent {
202238
}
203239

204240
processAuth() {
205-
const { location, history } = this.props
206-
const {
207-
token, logout
208-
} = getQueryParams(location.search);
241+
const { location, history } = this.props;
242+
const { token, logout } = getQueryParams(location.search);
209243
// @TODO: use redux to control state of session user
210244
if (!isFalsy(token)) {
211-
window.localStorage.setItem(LOCAL_STORAGE_KEY_FOR_SESSION_TOKEN, token)
212-
history.push('/')
245+
window.localStorage.setItem(LOCAL_STORAGE_KEY_FOR_SESSION_TOKEN, token);
246+
history.push('/');
213247
}
214248
// @TODO: use redux to remove user sesssion
215249
if (logout === 'success') {
216-
window.localStorage.removeItem(LOCAL_STORAGE_KEY_FOR_SESSION_TOKEN)
217-
history.push('/')
250+
window.localStorage.removeItem(LOCAL_STORAGE_KEY_FOR_SESSION_TOKEN);
251+
history.push('/');
218252
}
219253
return;
220254
}
221255

222256
componentDidMount() {
223-
if (location.pathname !== "/hukamnama" && location.pathname !== "/shabad" && location.pathname !== "/search") {
257+
if (
258+
location.pathname !== '/hukamnama' &&
259+
location.pathname !== '/shabad' &&
260+
location.pathname !== '/search'
261+
) {
224262
this.props.closeSettingsPanel();
225263
}
226264
this.processAuth();
@@ -231,7 +269,7 @@ class Layout extends React.PureComponent {
231269
document.title = this.props.title;
232270
this.updateTheme();
233271
addVisraamClass();
234-
272+
235273
// Expose setRephrasedTranslation globally for Shabad component
236274
window.setRephrasedTranslation = this.setRephrasedTranslation;
237275
}
@@ -272,15 +310,12 @@ class Layout extends React.PureComponent {
272310
}
273311

274312
handleAIClick = () => {
275-
console.log('handleAIClick');
276313
this.setState((prevState) => ({
277314
isAIActive: !prevState.isAIActive,
278315
}));
279316
};
280317

281318
setRephrasedTranslation = (translation) => {
282-
console.log("setRephrasedTranslation", translation);
283-
console.log("this.state.isAIActive", this.state.isAIActive);
284319
this.setState({
285320
rephrasedTranslation: translation,
286321
isAIActive: true, // Auto-open when translation is set
@@ -289,7 +324,21 @@ class Layout extends React.PureComponent {
289324
}
290325

291326
export default connect(
292-
({ online, darkMode, autoScrollMode, showMultiViewPanel, showPinSettings, modalOpened }) => ({ online, darkMode, autoScrollMode, showMultiViewPanel, showPinSettings, modalOpened }),
327+
({
328+
online,
329+
darkMode,
330+
autoScrollMode,
331+
showMultiViewPanel,
332+
showPinSettings,
333+
modalOpened,
334+
}) => ({
335+
online,
336+
darkMode,
337+
autoScrollMode,
338+
showMultiViewPanel,
339+
showPinSettings,
340+
modalOpened,
341+
}),
293342
{
294343
toggleDarkMode,
295344
setOnlineMode,

src/js/pages/Shabad/index.tsx

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ import BreadCrumb from '../../components/Breadcrumb';
1313
import { TEXTS, SEARCH_TYPES } from '../../constants';
1414
const Spinner = () => <div className="spinner" />;
1515

16-
1716
interface Props {
1817
random: boolean;
1918
highlight: string | number;
20-
id: string,
19+
id: string;
2120
isVisraam: boolean;
2221
isLarivaarAssist: boolean;
2322
q?: string;
@@ -31,7 +30,8 @@ interface StoreSliceState {
3130

3231
const Shabad = (props: Props) => {
3332
const state = useSelector<StoreSliceState>((state: any) => ({
34-
isVisraam: state.visraams, isLarivaarAssist: state.larivaarAssist
33+
isVisraam: state.visraams,
34+
isLarivaarAssist: state.larivaarAssist,
3535
}));
3636

3737
const [isHideBanner, setIsHideBanner] = useState<boolean>(false);
@@ -40,38 +40,39 @@ const Shabad = (props: Props) => {
4040
if (props.random) {
4141
pageView('/shabad?random');
4242
} else {
43-
pageView(toShabadURL({
44-
shabad: { shabadId: `${props.id}`, verseId: props.highlight.toString() },
45-
q: props.q || '',
46-
type: props.type,
47-
source: undefined
48-
}));
43+
pageView(
44+
toShabadURL({
45+
shabad: {
46+
shabadId: `${props.id}`,
47+
verseId: props?.highlight?.toString(),
48+
},
49+
q: props.q || '',
50+
type: props.type,
51+
source: undefined,
52+
})
53+
);
4954
}
50-
}, [props.random])
55+
}, [props.random]);
5156

5257
useEffect(() => {
53-
const isFromAskQuestion = props.type && parseInt(props.type, 10) === SEARCH_TYPES.ASK_A_QUESTION;
58+
const isFromAskQuestion =
59+
props.type && parseInt(props.type, 10) === SEARCH_TYPES.ASK_A_QUESTION;
5460
const hasQuery = props.q && props.q.trim() !== '';
5561

56-
console.log('Shabad useEffect - isFromAskQuestion:', isFromAskQuestion, 'hasQuery:', hasQuery, 'type:', props.type, 'q:', props.q);
57-
5862
if (isFromAskQuestion && hasQuery) {
5963
const processedQuery = (props.q as string).replace(/[^a-zA-Z0-9 ]/g, '');
60-
const semanticApi = `${GURBANIBOT_URL}rephrase/?query=${processedQuery}&shabad_id=${props.id}`;
61-
62-
console.log('Making API call to:', semanticApi);
63-
64+
const semanticApi = `${GURBANIBOT_URL}rephrase/?query=${processedQuery}&shabad_id=${props.id}&verse_id=${props.highlight}`;
65+
6466
fetch(semanticApi)
6567
.then((response) => response.json())
6668
.then((semanticData: any) => {
67-
console.log('API response:', semanticData);
6869
// Get the answer from the first result
6970
const answer = semanticData.rephrased_translation || '';
7071
if (answer && (window as any).setRephrasedTranslation) {
71-
console.log('Calling setRephrasedTranslation with:', { question: props.q as string, answer: answer });
7272
(window as any).setRephrasedTranslation({
7373
question: props.q as string,
74-
answer: answer
74+
answer: answer,
75+
verse: semanticData.verse,
7576
});
7677
}
7778
})
@@ -83,7 +84,9 @@ const Shabad = (props: Props) => {
8384
}, [props.type, props.q, props.id]);
8485

8586
const url = buildApiUrl(
86-
props.random ? { random: props.random, API_URL } : { random: props.random, id: props.id as unknown as number, API_URL }
87+
props.random
88+
? { random: props.random, API_URL }
89+
: { random: props.random, id: props.id as unknown as number, API_URL }
8790
);
8891

8992
return (
@@ -99,9 +102,9 @@ const Shabad = (props: Props) => {
99102
classes: {
100103
notification: 'notification-shabad',
101104
},
102-
type: "2",
105+
type: '2',
103106
message: `Larivaar Assist & Vishraams: Larivaar Assist will be displayed using different colors for words and the vishraams will be
104-
shown by orange and red flashing icons between words to guide you when to pause.`
107+
shown by orange and red flashing icons between words to guide you when to pause.`,
105108
}}
106109
onCrossIconClick={() => setIsHideBanner(true)}
107110
/>
@@ -128,8 +131,7 @@ const Shabad = (props: Props) => {
128131
)
129132
}
130133
</PageLoader>
131-
)
132-
}
134+
);
135+
};
133136

134137
export default Shabad;
135-

0 commit comments

Comments
 (0)