|
@@ -26,15 +26,15 @@ function handleCategoryChange(router, cat, value) {
|
|
|
router.navigate('browser', {...params, [cat]:(value || null)});
|
|
router.navigate('browser', {...params, [cat]:(value || null)});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function handleFilterChange(router, timeout, value) {
|
|
|
|
|
|
|
+function handleFilterChange(dispatch, router, timeout, value) {
|
|
|
if (timeout.current) clearInterval(timeout.current);
|
|
if (timeout.current) clearInterval(timeout.current);
|
|
|
timeout.current = setTimeout(() => handleCategoryChange(router, 'filter', value), 500);
|
|
timeout.current = setTimeout(() => handleCategoryChange(router, 'filter', value), 500);
|
|
|
|
|
+ dispatch({type: 'SET_FILTER', payload: value});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export default function Filters() {
|
|
|
|
|
|
|
+export default function Filters({dispatch, filters, filter}) {
|
|
|
const timeout = useRef();
|
|
const timeout = useRef();
|
|
|
const { router } = useRoute();
|
|
const { router } = useRoute();
|
|
|
- const { params } = router.getState();
|
|
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div className="Filters">
|
|
<div className="Filters">
|
|
@@ -44,7 +44,7 @@ export default function Filters() {
|
|
|
<AsyncSelect
|
|
<AsyncSelect
|
|
|
isClearable
|
|
isClearable
|
|
|
cacheOptions
|
|
cacheOptions
|
|
|
- defaultValue={params[cat] && {item: params[cat]}}
|
|
|
|
|
|
|
+ defaultValue={filters[cat] && {item: filters[cat]}}
|
|
|
defaultOptions
|
|
defaultOptions
|
|
|
loadOptions={(q) => handleLoadOptions(cat, q)}
|
|
loadOptions={(q) => handleLoadOptions(cat, q)}
|
|
|
getOptionLabel={(i)=>i.count ? `${i.item} (${i.count})` : i.item}
|
|
getOptionLabel={(i)=>i.count ? `${i.item} (${i.count})` : i.item}
|
|
@@ -57,7 +57,7 @@ export default function Filters() {
|
|
|
<h3>Latest</h3>
|
|
<h3>Latest</h3>
|
|
|
<input className="Latest"
|
|
<input className="Latest"
|
|
|
type="checkbox"
|
|
type="checkbox"
|
|
|
- checked={ !params.alpha }
|
|
|
|
|
|
|
+ checked={ !filters.alpha }
|
|
|
onChange={(e) => handleCategoryChange(router, 'alpha', !e.target.checked)} />
|
|
onChange={(e) => handleCategoryChange(router, 'alpha', !e.target.checked)} />
|
|
|
</div>
|
|
</div>
|
|
|
<div>
|
|
<div>
|
|
@@ -65,8 +65,8 @@ export default function Filters() {
|
|
|
<input className="Filter"
|
|
<input className="Filter"
|
|
|
type="text"
|
|
type="text"
|
|
|
placeholder="Search albums"
|
|
placeholder="Search albums"
|
|
|
- defaultValue={params.filter}
|
|
|
|
|
- onChange={(e)=>handleFilterChange(router, timeout, e.target.value)} />
|
|
|
|
|
|
|
+ value={filter}
|
|
|
|
|
+ onChange={(e)=>handleFilterChange(dispatch, router, timeout, e.target.value)} />
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|