mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-14 17:12:40 +00:00
With unneeded state gone, can rename back to title, author, etc.
No longer naming conflict with state and function parameters. We can go back to the shorter names
This commit is contained in:
@@ -58,62 +58,63 @@ const VaultPage = (props) => {
|
|||||||
window.history.replaceState(null, '', url.toString());
|
window.history.replaceState(null, '', url.toString());
|
||||||
};
|
};
|
||||||
|
|
||||||
const performSearch = async ({ titleValue, authorValue, countValue, v3Value, legacyValue, page }) => {
|
const performSearch = async (title, author, count, v3, legacy, page) => {
|
||||||
updateUrl(titleValue, authorValue, countValue, v3Value, legacyValue, page);
|
updateUrl(title, author, count, v3, legacy, page);
|
||||||
if ((titleValue || authorValue) && (v3Value || legacyValue)) {
|
if (!((title || author) && (v3 || legacy)))
|
||||||
const response = await request.get(
|
return;
|
||||||
`/api/vault?title=${titleValue}&author=${authorValue}&v3=${v3Value}&legacy=${legacyValue}&count=${countValue}&page=${page}`
|
|
||||||
).catch((error)=>{
|
const response = await request.get(
|
||||||
console.log('error at loadPage: ', error);
|
`/api/vault?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}&count=${count}&page=${page}`
|
||||||
setError(`${error.response
|
).catch((error)=>{
|
||||||
? error.response.status
|
console.log('error at loadPage: ', error);
|
||||||
: error.message}`
|
setError(`${error.response
|
||||||
);
|
? error.response.status
|
||||||
updateStateWithBrews([], 1);
|
: error.message}`
|
||||||
});
|
);
|
||||||
|
updateStateWithBrews([], 1);
|
||||||
if (response.ok)
|
});
|
||||||
updateStateWithBrews(response.body.brews, page);
|
|
||||||
}
|
if (response.ok)
|
||||||
|
updateStateWithBrews(response.body.brews, page);
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadTotal = async ({ titleValue, authorValue, v3Value, legacyValue }) => {
|
const loadTotal = async (title, author, v3, legacy) => {
|
||||||
setTotalBrews(null);
|
setTotalBrews(null);
|
||||||
if ((titleValue || authorValue) && (v3Value || legacyValue)) {
|
if (!((title || author) && (v3 || legacy)))
|
||||||
const response = await request.get(
|
return;
|
||||||
`/api/vault/total?title=${titleValue}&author=${authorValue}&v3=${v3Value}&legacy=${legacyValue}`
|
|
||||||
).catch((error)=>{
|
const response = await request.get(
|
||||||
console.log('error at loadTotal: ', error);
|
`/api/vault/total?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}`
|
||||||
setError(`${error.response
|
).catch((error)=>{
|
||||||
? error.response.status
|
console.log('error at loadTotal: ', error);
|
||||||
: error.message}`
|
setError(`${error.response
|
||||||
);
|
? error.response.status
|
||||||
updateStateWithBrews([], 1);
|
: error.message}`
|
||||||
});
|
);
|
||||||
|
updateStateWithBrews([], 1);
|
||||||
if (response.ok)
|
});
|
||||||
setTotalBrews(response.body.totalBrews);
|
|
||||||
}
|
if (response.ok)
|
||||||
|
setTotalBrews(response.body.totalBrews);
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadPage = async (page, updateTotal) => {
|
const loadPage = async (page, updateTotal) => {
|
||||||
if (!validateForm()) {
|
if (!validateForm())
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
setSearching(true);
|
setSearching(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
const titleValue = titleRef.current.value || '';
|
const title = titleRef.current.value || '';
|
||||||
const authorValue = authorRef.current.value || '';
|
const author = authorRef.current.value || '';
|
||||||
const countValue = countRef.current.value || 10;
|
const count = countRef.current.value || 10;
|
||||||
const v3Value = v3Ref.current.checked != false;
|
const v3 = v3Ref.current.checked != false;
|
||||||
const legacyValue = legacyRef.current.checked != false;
|
const legacy = legacyRef.current.checked != false;
|
||||||
|
|
||||||
// Perform search with the latest input values, because state is not fast enough
|
performSearch(title, author, count, v3, legacy, page);
|
||||||
performSearch({ titleValue, authorValue, countValue, v3Value, legacyValue, page });
|
|
||||||
|
|
||||||
if (updateTotal)
|
if (updateTotal)
|
||||||
loadTotal({ titleValue, authorValue, v3Value, legacyValue });
|
loadTotal(title, author, v3, legacy);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderNavItems = () => (
|
const renderNavItems = () => (
|
||||||
|
|||||||
Reference in New Issue
Block a user