mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-22 16:06:19 -05:00
Modifying Dashboard search clear button to clear all search params.
This commit is contained in:
parent
bd8411bcd7
commit
dd13534a39
7 changed files with 43 additions and 11 deletions
|
|
@ -400,7 +400,7 @@ export function scrollToTopOfElement(element, smooth = true) {
|
|||
});
|
||||
}
|
||||
|
||||
const useClearableInput = (searchStr, onChange, onClear, onSubmit, size = 'small', placeholder = 'Search...', icon = 'search') => {
|
||||
const useClearableInput = (searchStr, onChange, onClear, onSubmit, size = 'small', placeholder = 'Search...', icon = 'search', clearDisabled = null) => {
|
||||
const [value, setValue] = useState(searchStr || '');
|
||||
const [submitted, setSubmitted] = useState(false);
|
||||
|
||||
|
|
@ -459,7 +459,9 @@ const useClearableInput = (searchStr, onChange, onClear, onSubmit, size = 'small
|
|||
size={size}
|
||||
onClick={handleClearSearch}
|
||||
type='button'
|
||||
disabled={!!!value}
|
||||
// If `clearDisabled` is provided, use it to disable the clear button. Fallback to disabling if there is no
|
||||
// search value.
|
||||
disabled={clearDisabled !== null ? clearDisabled : !!!value}
|
||||
className='search-clear'
|
||||
/>;
|
||||
|
||||
|
|
@ -508,6 +510,7 @@ export function SearchResultsInput({
|
|||
action,
|
||||
actionIcon,
|
||||
clearable = false,
|
||||
clearDisabled = null,
|
||||
autoFocus = false,
|
||||
results = undefined,
|
||||
handleResultSelect = null,
|
||||
|
|
@ -521,7 +524,7 @@ export function SearchResultsInput({
|
|||
clearButton,
|
||||
localOnSubmit,
|
||||
handleChange,
|
||||
} = useClearableInput(searchStr, onChange, onClear, onSubmit, size, placeholder);
|
||||
} = useClearableInput(searchStr, onChange, onClear, onSubmit, size, placeholder, icon, clearDisabled);
|
||||
|
||||
// Show a "Loading" message rather than "No results" while results are pending.
|
||||
const loadingResults = {'loading': {name: 'Loading', results: [{title: 'Results are pending...'}]}};
|
||||
|
|
|
|||
|
|
@ -170,6 +170,17 @@ export function DateSelectorButton({
|
|||
}
|
||||
}, [JSON.stringify(dateRange), JSON.stringify(monthsSelected)]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!defaultMonthsSelected || (defaultMonthsSelected && defaultMonthsSelected.length === 0)) {
|
||||
setMonthsSelected([]);
|
||||
}
|
||||
console.log(defaultDateRange);
|
||||
if (!defaultDateRange || (defaultDateRange && defaultDateRange.length === 2
|
||||
&& defaultDateRange[0] == null && defaultDateRange[1] === null)) {
|
||||
setDateRange(emptyDateRange);
|
||||
}
|
||||
}, [JSON.stringify(defaultMonthsSelected), JSON.stringify(defaultDateRange)]);
|
||||
|
||||
const handleOpen = (e) => {
|
||||
if (e) e.preventDefault();
|
||||
setOpen(true);
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ const SUGGESTED_APPS = [
|
|||
export const useSearch = (defaultLimit = 48, totalPages = 0, emptySearch = false, model) => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const {dateRange, setDateRange, months, setDates} = useSearchDate();
|
||||
const {dateRange, setDateRange, months, setDates, isEmpty: datesIsEmpty} = useSearchDate();
|
||||
const {searchParams, updateQuery, getLocationStr} = React.useContext(QueryContext);
|
||||
// `searchStr` means actually fetch the files/zims.
|
||||
const searchStr = searchParams.get('q');
|
||||
|
|
@ -50,6 +50,9 @@ export const useSearch = (defaultLimit = 48, totalPages = 0, emptySearch = false
|
|||
// archive/video/ebook/etc.
|
||||
const model_ = searchParams.get('model') || model;
|
||||
|
||||
const anySearch = (!datesIsEmpty) || searchStr || (activeTags && activeTags.length > 0) || filter || model;
|
||||
const isEmpty = !anySearch;
|
||||
|
||||
const setSearchStr = (value) => {
|
||||
const searchQuery = {q: value, o: 0};
|
||||
if (filter) {
|
||||
|
|
@ -90,6 +93,7 @@ export const useSearch = (defaultLimit = 48, totalPages = 0, emptySearch = false
|
|||
clearSearch,
|
||||
setTags,
|
||||
months, dateRange, setDateRange, setDates,
|
||||
anySearch, isEmpty,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue