Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions reader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,20 @@ def search(request):
Search or Search Results page.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add docstring to explain what is happening now, it is non-trivial!

"""
search_params = get_search_params(request.GET)
if request.active_module == VOICES_MODULE and search_params["query"]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any unit tests for this feature? It feels like we should have been able to catch this.. (Although I'm still not 100% sure what the problem is)

try:
if Ref.is_ref(search_params["query"]):
tref = Ref(search_params["query"]).normal()
params = request.GET.copy()
if "q" in params:
del params["q"]
query_string = params.urlencode()
target = f"/sheets-with-ref/{urllib.parse.quote(tref)}"
if query_string:
target = f"{target}?{query_string}"
return redirect(target, permanent=False)
except Exception:
pass

props={
"initialMenu": "search",
Expand Down
8 changes: 8 additions & 0 deletions static/js/ReaderApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,14 @@ toggleSignUpModal(modalContentKind = SignUpModalKind.Default) {
}
}
showSearch(searchQuery) {
if (Sefaria.activeModule === Sefaria.VOICES_MODULE && searchQuery) {
const parsedRef = Sefaria.parseRef(searchQuery);
if (!parsedRef?.error) {
const ref = parsedRef.ref || searchQuery;
window.location = `/sheets-with-ref/${encodeURIComponent(ref)}`;
return;
}
}
const hasSearchState = !!this.state.panels && this.state.panels.length && !!this.state.panels[0].searchState;
const searchState = hasSearchState ? this.state.panels[0].searchState.update({ filtersValid: false })
: new SearchState({ type: SearchState.moduleToSearchType(Sefaria.activeModule)});
Expand Down
2 changes: 1 addition & 1 deletion static/js/SearchPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,4 @@ SearchPage.propTypes = {
};


export default SearchPage;
export default SearchPage;
2 changes: 1 addition & 1 deletion static/js/sheets/SheetsWithRefPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,4 @@ const SheetsWithRefPage = ({srefs, searchState, updateSearchState, updateApplied
aiBadgeText={aiBadgeText}
/>
}
export default SheetsWithRefPage;
export default SheetsWithRefPage;
Loading