Skip to content

Commit

Permalink
Merge pull request #1658 from KhalisFoundation/dev
Browse files Browse the repository at this point in the history
Release PR 1.15.0 (Gurbani Chat Bot and few other fixes)
  • Loading branch information
saintsoldierx authored Aug 8, 2023
2 parents 011a031 + 82ea445 commit 7cdc25c
Show file tree
Hide file tree
Showing 22 changed files with 224 additions and 117 deletions.
3 changes: 2 additions & 1 deletion common/api-urls-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ module.exports = {
},
CEREMONIES: '//api.sikhitothemax.org/ceremonies/',
DOODLE: '//api.sikhitothemax.org/doodle/',
WRITERS: '//api.banidb.com/v2/writers/'
WRITERS: '//api.banidb.com/v2/writers/',
GURBANIBOT: '//fastersemanticsearchapi.sevaa.win/'
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sttm/web",
"version": "1.14.3",
"version": "1.15.0",
"description": "Sevadaars are currently working hard to build a newer version of SikhiToTheMax website using modern web technologies.",
"main": "index.js",
"engines": {
Expand Down
9 changes: 5 additions & 4 deletions server/routes/favouriteShabadsRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ const getFavouriteShabadsCallback = async (_req, res, data, connection) => {

const addFavouriteShabadCallback = async (_req, res, data, connection) => {
try {
const {email, shabadId, comment} = data;
const {email, shabadId, comment, verseId} = data;
const row = await connection.query("SELECT id FROM users where email = ?", [email]);
const user = row[0];
const favShabad = await connection.query('SELECT * FROM favourite_shabads WHERE shabad_id = ? AND user_id = ?', [shabadId, user.id])
let rows = [];
let q = "INSERT INTO favourite_shabads (comment, shabad_id, user_id) VALUES (?,?,?)";
let q = "INSERT INTO favourite_shabads (comment, shabad_id, user_id, verse_id) VALUES (?,?,?,?)";
if(favShabad[0]) {
q = "UPDATE favourite_shabads SET comment = ? WHERE (shabad_id = ? AND user_id = ?)"
}
rows = await connection.query(q, [ comment, shabadId, user.id])
rows = await connection.query(q, [ comment, shabadId, user.id, verseId])
const result = await connection.query("SELECT * from favourite_shabads WHERE id = ?", [rows.insertId])
res.status(200).json(result[0]);
}catch(err) {
Expand Down Expand Up @@ -60,14 +60,15 @@ const getFavouriteShabads = async (req, res) => {
const addFavouriteShabad = (req, res) => {
const shabadId = req.body.shabadId;
const comment = req.body.comment;
const verseId = req.body.verseId;
const bearerToken = req.headers.authorization;
const token = bearerToken.substr(7);
const {email} = jwtVerify(token)

pool.runQuery(
req,
res,
{email, shabadId, comment},
{email, shabadId, comment, verseId},
addFavouriteShabadCallback
)
}
Expand Down
19 changes: 10 additions & 9 deletions src/js/components/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { setMultipleShabads, setMultiViewPanel } from '@/features/actions';
import Larivaar from '../components/Larivaar';
import { toSearchURL } from '@/util';
import { ShabadButtonWrapper } from "./ShabadButtonWrapper";
import { SEARCH_TYPES } from "@/constants";

class Autocomplete extends Component {
static propTypes = {
Expand Down Expand Up @@ -77,10 +78,10 @@ class Autocomplete extends Component {
// Closing suggestions on mouse down
onMouseDown = e => {
e.stopPropagation();
(this.state.showSuggestions && !this.wrapperRef.current.contains(e.target)) &&
this.setState({
showSuggestions: false,
});
(this.state.showSuggestions && !this.wrapperRef.current.contains(e.target)) &&
this.setState({
showSuggestions: false,
});
}

componentDidMount() {
Expand Down Expand Up @@ -117,7 +118,6 @@ class Autocomplete extends Component {

getSuggestions(userInput, searchOptions)
.then(suggestions => {

// if any suggestion exists, only then add this as final result item
if (isShowFullResults && suggestions.length) {
suggestions.push({
Expand Down Expand Up @@ -168,6 +168,7 @@ class Autocomplete extends Component {
} = this;

let suggestionsListComponent;
const isChatBot = searchOptions.type === SEARCH_TYPES.ASK_A_QUESTION;

if (showSuggestions && value) {
if (filteredSuggestions.length) {
Expand Down Expand Up @@ -218,14 +219,14 @@ class Autocomplete extends Component {
{searchOptions.type === 3 ? suggestion.translation : suggestion.pankti}
</Larivaar>
{searchOptions.type === 3 && (<p className="gurbani-font">{suggestion.pankti}</p>)}
</a>
</a>
{
<div className="add-shabad-wrapper">
<ShabadButtonWrapper shabad={suggestion} />
</div>
}
}
</>
}
}
</li>
);
})}
Expand All @@ -242,7 +243,7 @@ class Autocomplete extends Component {

return (
<Fragment>
{suggestionsListComponent}
{!isChatBot && suggestionsListComponent}
</Fragment>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const FloatingActions = (props: Props) => {
{isShowFullScreen &&
<div
style={lastIconStyles}
className="floatingActionsControl hide-tablet">
className="floatingActionsControl">
<FullScreen />
</div>}
{isShowScrollToTop &&
Expand Down
23 changes: 12 additions & 11 deletions src/js/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ class Header extends React.PureComponent {

onFormSubmit =
({ handleSubmit, ...data }) =>
(e) => {
e.preventDefault();
e.stopPropagation();
handleSubmit();
this.handleFormSubmit(data);
};
(e) => {
e.preventDefault();
e.stopPropagation();
handleSubmit();
this.handleFormSubmit(data);
};

handleFormSubmit = (data) => {
this.props.history.push(toSearchURL(data));
Expand Down Expand Up @@ -386,18 +386,19 @@ class Header extends React.PureComponent {
value={writer}
onChange={handleSearchWriterChange}
className={[isWriterChanged ? 'selected' : null]}
disabled={type === SEARCH_TYPES.ASK_A_QUESTION}
>
{writers
?.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) => (
<option
Expand Down Expand Up @@ -429,7 +430,7 @@ class Header extends React.PureComponent {
}
}

const mapStateToProps = ({}) => ({});
const mapStateToProps = ({ }) => ({});

const mapDispatchToProps = {
toggleSettingsPanel,
Expand Down
41 changes: 24 additions & 17 deletions src/js/components/Modals/AddFavouriteShabadModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@ const AddFavouriteShabadModal = () => {
const dispatch = useDispatch();
const isModalOpen = useSelector(state => state.isModalOpen)
const gurbaniVerses = useSelector(state => state.gurbaniVerses);
// const verses = gurbaniVerses.map(gurbani => gurbani.verse.unicode);
const options = gurbaniVerses.map(gurbani => {
return (
{
label: gurbani.verse.gurmukhi,
value: gurbani.verseId,
}
)
});

const shabadId = getShabadId(gurbaniVerses[0]);
// const [pankti, setPankti] = useState<string>(verses[0]);
const [pankti, setPankti] = useState<string>(options[0].value);
const [comment, setComment] = useState<string>('');
const create = useCreateFavouriteShabad()
const create = useCreateFavouriteShabad();

const onSave = (e) => {
e.preventDefault();
create.mutate({ shabadId, comment });
create.mutate({ shabadId, comment, verseId: pankti });
dispatch(setIsModalOpen(false))
}

Expand All @@ -29,18 +38,16 @@ const AddFavouriteShabadModal = () => {
</div>
<div className='content'>
<form method="dialog" onSubmit={onSave}>
{/*
Release in version..
<label className="title">Select a line to save as the title:
<select value={pankti} onChange={(e) => setPankti(e.target.value)}>
{verses.map((value, idx) =>
<option key={`${idx}-${value}`}>
{value}
</option>)
}
</select>
</label>
*/}
<label className="title">Select a line to save as the title:
<select className="dropdown" value={pankti} onChange={(e) => setPankti(e.target.value)}>
{options.map((option) =>
<option key={option.value} value={option.value}>
{option.label}
</option>)
}
</select>
</label>

<label className='title'>Notes:
<textarea
name="comment"
Expand All @@ -50,7 +57,7 @@ const AddFavouriteShabadModal = () => {
value={comment}
onChange={(e) => setComment(e.target.value)}
className="textarea"
autoFocus
autoFocus
/>
</label>
<div className="save-btn">
Expand Down
38 changes: 19 additions & 19 deletions src/js/components/SearchForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class SearchForm extends React.PureComponent {
localStorage.getItem(LOCAL_STORAGE_KEY_FOR_SEARCH_SOURCE) ||
DEFAULT_SEARCH_SOURCE,
writer:
this.props.defaultWriter ||
this.props.defaultWriter ||
localStorage.getItem(LOCAL_STORAGE_KEY_FOR_SEARCH_WRITER) ||
DEFAULT_SEARCH_WRITER,
writers: DEFAULT_SEARCH_WRITERS,
Expand Down Expand Up @@ -155,7 +155,7 @@ export default class SearchForm extends React.PureComponent {
getWriterList()
.then(writersData => {
this._setState({ writers: writersData })
})
})
}

selectHighlight = () => {
Expand Down Expand Up @@ -345,7 +345,7 @@ export default class SearchForm extends React.PureComponent {
}
};

handleSearchSourceChange = ({target}) => {
handleSearchSourceChange = ({ target }) => {
const source = target.value
this.setState(
{
Expand All @@ -363,7 +363,7 @@ export default class SearchForm extends React.PureComponent {
localStorage.setItem(
LOCAL_STORAGE_KEY_FOR_SEARCH_SOURCE,
this.state.source
);
);
}
);
}
Expand Down Expand Up @@ -412,7 +412,7 @@ export default class SearchForm extends React.PureComponent {
);
}

handleSearchWriterChange = ({target}) => {
handleSearchWriterChange = ({ target }) => {
const writer = target.value
this.setState({
writer,
Expand All @@ -421,16 +421,16 @@ export default class SearchForm extends React.PureComponent {
this.state.query !== '',
isWriterChanged: writer !== DEFAULT_SEARCH_WRITER
},
() => {
clickEvent({
action: ACTIONS.SEARCH_WRITER,
label: this.state.writer,
});
localStorage.setItem(
LOCAL_STORAGE_KEY_FOR_SEARCH_WRITER,
this.state.writer
);
})
() => {
clickEvent({
action: ACTIONS.SEARCH_WRITER,
label: this.state.writer,
});
localStorage.setItem(
LOCAL_STORAGE_KEY_FOR_SEARCH_WRITER,
this.state.writer
);
})
}

handleReset = (e) => {
Expand All @@ -446,10 +446,10 @@ export default class SearchForm extends React.PureComponent {
this.props.submitOnChangeOf.includes('writer') &&
this.state.query !== ''
},
() => {
localStorage.setItem(LOCAL_STORAGE_KEY_FOR_SEARCH_SOURCE, this.state.source);
localStorage.removeItem(LOCAL_STORAGE_KEY_FOR_SEARCH_WRITER);
})
() => {
localStorage.setItem(LOCAL_STORAGE_KEY_FOR_SEARCH_SOURCE, this.state.source);
localStorage.removeItem(LOCAL_STORAGE_KEY_FOR_SEARCH_WRITER);
})
}

handleSubmit = () => {
Expand Down
39 changes: 26 additions & 13 deletions src/js/components/SearchResults/SearchResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,33 @@ export default class SearchResults extends React.PureComponent {
'main-letter-search': type === SEARCH_TYPES.MAIN_LETTERS
});


const warning = type === SEARCH_TYPES['ASK_A_QUESTION'] && (
<div className='warning-box'>
<h4>⚠ This is an experimental feature.</h4>
<p>Please <a href="https://support.khalisfoundation.org/support/tickets/new" target="blank">
<u>get in touch</u></a> with us if you have any concerns or feedback.
</p>
</div>
);

return (
<ul className={searchResultsClassName}>
{
shabads.map(shabad => {
return (
<SearchResult
key={getVerseId(shabad)}
type={type}
shabad={shabad}
{...props} />
);
})
}
</ul>
<>
{warning}
<ul className={searchResultsClassName}>
{
shabads.map(shabad => {
return (
<SearchResult
key={getVerseId(shabad)}
type={type}
shabad={shabad}
{...props} />
);
})
}
</ul>
</>
);
}
}
3 changes: 3 additions & 0 deletions src/js/constants/misc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { SOURCES, SOURCES_WITH_ANG, TYPES as _TYPES } from '@sttm/banidb';
import { SEARCH_TYPES } from './search-types';

// TODO: Need to move this to @sttm/banidb module
_TYPES.push('Ask a Question (English)');

export { SOURCES, SOURCES_WITH_ANG };

export const BANI_LENGTH_COLS = {
Expand Down
Loading

0 comments on commit 7cdc25c

Please sign in to comment.