mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-17 16:42:41 +00:00
fix sort and dir props
This commit is contained in:
@@ -37,10 +37,7 @@ const VaultPage = (props)=>{
|
|||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
disableSubmitIfFormInvalid();
|
disableSubmitIfFormInvalid();
|
||||||
const initialSort = props.query.sort || 'title';
|
loadPage(pageState, true, props.query.sort, props.query.dir);
|
||||||
const initialDir = props.query.dir || 'asc';
|
|
||||||
const initialSorting = `${initialSort}/${initialDir}`;
|
|
||||||
loadPage(pageState, true, initialSorting);
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const updateStateWithBrews = (brews, page)=>{
|
const updateStateWithBrews = (brews, page)=>{
|
||||||
@@ -98,7 +95,7 @@ const VaultPage = (props)=>{
|
|||||||
setTotalBrews(response.body.totalBrews);
|
setTotalBrews(response.body.totalBrews);
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadPage = async (page, updateTotal, sort)=>{
|
const loadPage = async (page, updateTotal, sort, dir)=>{
|
||||||
if(!validateForm()) return;
|
if(!validateForm()) return;
|
||||||
|
|
||||||
setSearching(true);
|
setSearching(true);
|
||||||
@@ -109,14 +106,14 @@ const VaultPage = (props)=>{
|
|||||||
const count = countRef.current.value || 10;
|
const count = countRef.current.value || 10;
|
||||||
const v3 = v3Ref.current.checked != false;
|
const v3 = v3Ref.current.checked != false;
|
||||||
const legacy = legacyRef.current.checked != false;
|
const legacy = legacyRef.current.checked != false;
|
||||||
const sortOption = sort && sort.split('/')[0] || 'title';
|
const sortOption = sort || 'title';
|
||||||
const dir = sort && sort.split('/')[1] || 'asc';
|
const dirOption = dir || 'asc';
|
||||||
const pageProp = page || 1;
|
const pageProp = page || 1;
|
||||||
|
|
||||||
setSort(sortOption);
|
setSort(sortOption);
|
||||||
setdir(dir);
|
setdir(dirOption);
|
||||||
|
|
||||||
performSearch(title, author, count, v3, legacy, pageProp, sortOption, dir);
|
performSearch(title, author, count, v3, legacy, pageProp, sortOption, dirOption);
|
||||||
|
|
||||||
if(updateTotal)
|
if(updateTotal)
|
||||||
loadTotal(title, author, v3, legacy);
|
loadTotal(title, author, v3, legacy);
|
||||||
@@ -273,16 +270,12 @@ const VaultPage = (props)=>{
|
|||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<button onClick={() => {
|
<button onClick={() => {
|
||||||
loadPage(1, false, `${optionValue}/${oppositeDir}`)
|
loadPage(1, false, optionValue, oppositeDir)
|
||||||
}}>
|
}}>
|
||||||
{optionTitle}
|
{optionTitle}
|
||||||
</button>
|
</button>
|
||||||
{sortState === optionValue && (
|
{sortState === optionValue && (
|
||||||
<i
|
<i className={`sortDir fas ${dirState === 'asc' ? 'fa-sort-up' : 'fa-sort-down'}`} />
|
||||||
className={`sortDir fas ${
|
|
||||||
dirState === 'asc' ? 'fa-sort-up' : 'fa-sort-down'
|
|
||||||
}`}
|
|
||||||
></i>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user