Skip to content

Commit c237530

Browse files
authored
Merge pull request #129 from hathitrust/ETT-787-collection-search
ETT-787: fix bug -- collection search unreachable from www search bar unless at homepage
2 parents 3180f9f + 25ddc88 commit c237530

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/js/components/SearchBar/index.svelte

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
const ALL_ITEMS = 'all items';
1313
let accessScope = $state(ACCESSIBLE_ITEMS);
1414
let isFullView = $state(true);
15+
let dropdownSelected = $state(false);
1516
1617
//updates UI when 'Collection' or 'Website' is selected in search options
18+
// sets a boolean for whether or not the dropdown for collection/website was selected
1719
let _updateSelect = function (event) {
18-
_root.dataset.index = event.target.value;
1920
index = event.target.value;
21+
_root.dataset.index = event.target.value;
22+
dropdownSelected = true;
2023
};
2124
2225
function isSiteBabel() {
@@ -50,12 +53,13 @@
5053
5154
//updates search hint message when use selects search type
5255
function _updateSearchType() {
53-
let value = _searchtype.value;
54-
_root.dataset.field = value;
55-
let menuItem = _searchtype.options[_searchtype.selectedIndex];
56-
// window._s1 = _searchtype;
57-
console.log('-- updateSearchType', value, _searchtype, menuItem);
58-
fieldValue = menuItem.text;
56+
if (_searchtype) {
57+
let value = _searchtype.value;
58+
_root.dataset.field = value;
59+
let menuItem = _searchtype.options[_searchtype.selectedIndex];
60+
console.log('-- updateSearchType', value, _searchtype, menuItem);
61+
fieldValue = menuItem.text;
62+
}
5963
}
6064
6165
let SERVICE_DOMAIN = $state('babel.hathitrust.org');
@@ -111,6 +115,9 @@
111115
if (isSiteBabel() || isWebsiteHome()) {
112116
_searchtypeValue = 'everything';
113117
_selectValue = 'library';
118+
if (dropdownSelected) {
119+
_selectValue = index;
120+
}
114121
// set _inputValue to q1 IF this is ls AND it's not a mondo collection
115122
if (location.pathname.match('/cgi/ls') && !searchParams.has('c')) {
116123
_inputValue = searchParams.get('q1');
@@ -120,6 +127,9 @@
120127
_searchtypeValue = searchParams.get('searchtype') || 'all';
121128
_selectValue = 'library';
122129
_inputValue = searchParams.get('lookfor') || searchParams.get('lookfor[]') || '';
130+
if (dropdownSelected) {
131+
_selectValue = index;
132+
}
123133
if (location.pathname == '/Record' && searchParams.has('ft')) {
124134
// default to isFullView=true if /Record does not have an ft parameter
125135
isFullView = searchParams.get('ft') == 'ft';
@@ -128,12 +138,16 @@
128138
}
129139
} else {
130140
_searchtypeValue = 'everything';
131-
if (location.pathname.startsWith('/search/')) {
141+
if (dropdownSelected == false && location.pathname.startsWith('/search/')) {
132142
_selectValue = 'website';
133143
index = 'website';
134144
let tmp = location.pathname.split('/').slice(2);
135145
tmp = tmp.pop();
136146
_inputValue = decodeURI(tmp);
147+
} else if (dropdownSelected == true && index == 'library') {
148+
_selectValue = 'library';
149+
index = 'library';
150+
_inputValue = '';
137151
} else {
138152
_selectValue = 'website';
139153
index = 'website';
@@ -147,7 +161,7 @@
147161
}
148162
}
149163
150-
_searchtype.value = _searchtypeValue;
164+
if (_searchtype) _searchtype.value = _searchtypeValue;
151165
_select.value = _selectValue;
152166
_input.value = _inputValue;
153167
accessScope = isFullView ? ACCESSIBLE_ITEMS : ALL_ITEMS;

0 commit comments

Comments
 (0)