0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-14 19:22:52 +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:
Trevor Buckner
2024-09-04 00:35:27 -04:00
parent a7cb73b02e
commit 373a627c14

View File

@@ -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)=>{
console.log('error at loadPage: ', error);
setError(`${error.response
? error.response.status
: error.message}`
);
updateStateWithBrews([], 1);
});
if (response.ok) const response = await request.get(
updateStateWithBrews(response.body.brews, page); `/api/vault?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}&count=${count}&page=${page}`
} ).catch((error)=>{
console.log('error at loadPage: ', error);
setError(`${error.response
? error.response.status
: error.message}`
);
updateStateWithBrews([], 1);
});
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)=>{
console.log('error at loadTotal: ', error);
setError(`${error.response
? error.response.status
: error.message}`
);
updateStateWithBrews([], 1);
});
if (response.ok) const response = await request.get(
setTotalBrews(response.body.totalBrews); `/api/vault/total?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}`
} ).catch((error)=>{
console.log('error at loadTotal: ', error);
setError(`${error.response
? error.response.status
: error.message}`
);
updateStateWithBrews([], 1);
});
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 = () => (