-
Notifications
You must be signed in to change notification settings - Fork 2
Bug/Search: All Categories #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
cc45467
77b5404
99a5c61
edf9896
ce4466a
e979328
f3e15f3
886a3f3
cd750b6
207b9b2
2530c2b
0cac967
0e0184e
4ba7c92
a16f239
5f9cd81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ define('forum/search', [ | |
| let selectedTags = []; | ||
| let selectedCids = []; | ||
| let searchFilters = {}; | ||
| let lastAutoQueryUrl = null; | ||
|
|
||
| Search.init = function () { | ||
| const searchIn = $('#search-in'); | ||
| searchIn.on('change', function () { | ||
|
|
@@ -65,6 +67,17 @@ define('forum/search', [ | |
| updateSortFilter(); | ||
|
|
||
| searchFilters = getSearchDataFromDOM(); | ||
|
|
||
| const currentUrl = window.location.pathname + window.location.search; | ||
|
|
||
| // Only auto-query when arriving with a term AND the page doesn't already have results rendered | ||
| const hasRenderedResults = !!$('#results .search-results').length; | ||
| const term = (searchFilters.term || '').trim(); | ||
|
|
||
| if (term && !hasRenderedResults && lastAutoQueryUrl !== currentUrl) { | ||
| lastAutoQueryUrl = currentUrl; | ||
| searchModule.query(searchFilters); | ||
| } | ||
| }; | ||
|
|
||
| function updateTagFilter() { | ||
|
|
@@ -122,7 +135,8 @@ define('forum/search', [ | |
| if (['posts', 'titlesposts', 'titles', 'bookmarks'].includes(searchData.in)) { | ||
| searchData.matchWords = form.find('#match-words-filter').val(); | ||
| searchData.by = selectedUsers.length ? selectedUsers.map(u => u.username) : undefined; | ||
| searchData.categories = selectedCids.length ? selectedCids : undefined; | ||
| const cids = Array.isArray(selectedCids) ? selectedCids : []; | ||
| searchData.categories = cids.length ? cids : ['all']; | ||
| searchData.searchChildren = form.find('#search-children').is(':checked'); | ||
| searchData.hasTags = selectedTags.length ? selectedTags.map(t => t.value) : undefined; | ||
| searchData.replies = form.find('#reply-count').val(); | ||
|
|
@@ -252,44 +266,63 @@ define('forum/search', [ | |
|
|
||
| function categoryFilterDropdown(_selectedCids) { | ||
| ajaxify.data.allCategoriesUrl = ''; | ||
| selectedCids = _selectedCids || []; | ||
|
|
||
| // UI semantics: All = [] | ||
| let uiCids = Array.isArray(_selectedCids) ? _selectedCids.map(String) : []; | ||
|
|
||
| // sanitize any bad inputs | ||
| uiCids = uiCids.filter(Boolean); | ||
|
|
||
| // if upstream gave ['all'], convert to UI form [] | ||
| if (uiCids.length === 1 && uiCids[0] === 'all') { | ||
| uiCids = []; | ||
| } | ||
| // if upstream accidentally includes 'all' with others, drop it | ||
| if (uiCids.includes('all')) { | ||
| uiCids = uiCids.filter(cid => cid !== 'all'); | ||
| } | ||
|
|
||
| ajaxify.data.selectedCids = uiCids; | ||
| selectedCids = uiCids; | ||
|
|
||
| const dropdownEl = $('[component="category/filter"]'); | ||
| categoryFilter.init(dropdownEl, { | ||
| selectedCids: _selectedCids, | ||
| updateButton: false, // prevent categoryFilter module from updating the button | ||
| selectedCids: uiCids, // pass [] for All | ||
| updateButton: false, | ||
| onHidden: async function (data) { | ||
| const isActive = data.selectedCids.length > 0 && data.selectedCids[0] !== 'all'; | ||
| let cids = Array.isArray(data.selectedCids) ? data.selectedCids.map(String) : []; | ||
| cids = cids.filter(Boolean).filter(cid => cid !== 'all'); // keep UI form | ||
|
|
||
| ajaxify.data.selectedCids = cids; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should update the what is displayed on the screen to hopefully be the [] version (with the checkmark) if it is actually ['all'] because its display is coded up to show All Categories on [] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kk |
||
| selectedCids = cids; | ||
|
|
||
| const isActive = cids.length > 0; | ||
|
|
||
| let labelText = '[[search:categories]]'; | ||
| ajaxify.data.selectedCids = data.selectedCids; | ||
| selectedCids = data.selectedCids; | ||
| if (data.selectedCids.length === 1 && data.selectedCids[0] === 'watched') { | ||
| if (cids.length === 1 && cids[0] === 'watched') { | ||
| ajaxify.data.selectedCategory = { cid: 'watched' }; | ||
| labelText = `[[search:categories-watched-categories]]`; | ||
| } else if (data.selectedCids.length === 1 && data.selectedCids[0] === 'all') { | ||
| ajaxify.data.selectedCategory = null; | ||
| } else if (data.selectedCids.length > 0) { | ||
| const categoryData = await api.get(`/categories/${data.selectedCids[0]}`); | ||
| labelText = '[[search:categories-watched-categories]]'; | ||
| } else if (cids.length > 1) { | ||
| labelText = `[[search:categories-x, ${cids.length}]]`; | ||
| } else if (cids.length === 1) { | ||
| const categoryData = await api.get(`/categories/${cids[0]}`); | ||
| ajaxify.data.selectedCategory = categoryData; | ||
| labelText = `[[search:categories-x, ${categoryData.name}]]`; | ||
| } | ||
| if (data.selectedCids.length > 1) { | ||
| labelText = `[[search:categories-x, ${data.selectedCids.length}]]`; | ||
| } else { | ||
| ajaxify.data.selectedCategory = { cid: 'all' }; | ||
| } | ||
|
|
||
| $('[component="category/filter/button"]').toggleClass( | ||
| 'active-filter', isActive | ||
| ).find('.filter-label').translateText(labelText); | ||
| $('[component="category/filter/button"]') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought I fixed that. Good to know. |
||
| .toggleClass('active-filter', isActive) | ||
| .find('.filter-label') | ||
| .translateText(labelText); | ||
| }, | ||
| localCategories: [ | ||
| { | ||
| cid: 'watched', | ||
| name: '[[category:watched-categories]]', | ||
| icon: '', | ||
| }, | ||
| ], | ||
| localCategories: [{ cid: 'watched', name: '[[category:watched-categories]]', icon: '' }], | ||
| }); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| function userFilterDropdown(el, _selectedUsers) { | ||
| selectedUsers = _selectedUsers || []; | ||
| userFilter.init(el, { | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to do a double-fetch on any subsequent query (eg. try changing the search text)
was the intention to run search once on load?
(prod version:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it was.