mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-04 22:38:43 +00:00
recheck validity on tag change
This commit is contained in:
@@ -64,13 +64,14 @@ const VaultPage = (props)=>{
|
|||||||
loadPage(pageState, true, props.query.sort, props.query.dir);
|
loadPage(pageState, true, props.query.sort, props.query.dir);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(()=>{disableSubmitIfFormInvalid()},[tagsListAnd, tagsListOr, tagsListNot])
|
||||||
|
|
||||||
const updateStateWithBrews = (brews, page)=>{
|
const updateStateWithBrews = (brews, page)=>{
|
||||||
setBrewCollection(brews || null);
|
setBrewCollection(brews || null);
|
||||||
setPageState(parseInt(page) || 1);
|
setPageState(parseInt(page) || 1);
|
||||||
setSearching(false);
|
setSearching(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const buildQueryParams = (entries)=>{
|
const buildQueryParams = (entries)=>{
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
@@ -84,20 +85,9 @@ const VaultPage = (props)=>{
|
|||||||
return params.toString();
|
return params.toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const updateUrl = (params)=>{
|
|
||||||
const url = new URL(window.location.href);
|
|
||||||
|
|
||||||
url.search = params;
|
|
||||||
|
|
||||||
window.history.replaceState(null, '', url.toString());
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const performSearch = async (formContents, page, sort, dir)=>{
|
const performSearch = async (formContents, page, sort, dir)=>{
|
||||||
const { title, author, count, v3, legacy, tagsAnd, tagsOr, tagsNot } = formContents;
|
const { title, author, count, v3, legacy, tagsAnd, tagsOr, tagsNot } = formContents;
|
||||||
|
|
||||||
|
|
||||||
const params = buildQueryParams([
|
const params = buildQueryParams([
|
||||||
['title', title],
|
['title', title],
|
||||||
['author', author],
|
['author', author],
|
||||||
@@ -112,7 +102,9 @@ const VaultPage = (props)=>{
|
|||||||
['dir', dir]
|
['dir', dir]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
updateUrl(params);
|
const url = new URL(window.location.href);
|
||||||
|
url.search = params;
|
||||||
|
window.history.replaceState(null, '', url.toString());
|
||||||
|
|
||||||
const response = await request.get(`/api/vault?${params}`)
|
const response = await request.get(`/api/vault?${params}`)
|
||||||
.catch((error)=>{
|
.catch((error)=>{
|
||||||
@@ -127,7 +119,7 @@ const VaultPage = (props)=>{
|
|||||||
};
|
};
|
||||||
|
|
||||||
const loadTotal = async (formContents)=>{
|
const loadTotal = async (formContents)=>{
|
||||||
const { title, author, count, v3, legacy, tagsAnd, tagsOr, tagsNot } = formContents;
|
const { title, author, v3, legacy, tagsAnd, tagsOr, tagsNot } = formContents;
|
||||||
|
|
||||||
setTotalBrews(null);
|
setTotalBrews(null);
|
||||||
|
|
||||||
@@ -208,6 +200,7 @@ const VaultPage = (props)=>{
|
|||||||
const isAuthorValid = authorRef.current.validity.valid && authorRef.current.value;
|
const isAuthorValid = authorRef.current.validity.valid && authorRef.current.value;
|
||||||
const isCheckboxChecked = legacyRef.current.checked || v3Ref.current.checked;
|
const isCheckboxChecked = legacyRef.current.checked || v3Ref.current.checked;
|
||||||
const isTagsValid = tagsListAnd.length >= 1 || tagsListOr.length >= 1;
|
const isTagsValid = tagsListAnd.length >= 1 || tagsListOr.length >= 1;
|
||||||
|
//if a search is done with only negative tags, the planner crashes
|
||||||
|
|
||||||
const isFormValid = (isTitleValid || isAuthorValid || isTagsValid) && isCheckboxChecked;
|
const isFormValid = (isTitleValid || isAuthorValid || isTagsValid) && isCheckboxChecked;
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -32,8 +32,6 @@ const rendererConditions = (legacy, v3)=>{
|
|||||||
const tagConditions = (tagsAnd, tagsOr, tagsNot) => {
|
const tagConditions = (tagsAnd, tagsOr, tagsNot) => {
|
||||||
const conditions = {};
|
const conditions = {};
|
||||||
|
|
||||||
console.log(tagsAnd.length, tagsOr.length, tagsNot.length);
|
|
||||||
|
|
||||||
if (tagsAnd.length > 0) {
|
if (tagsAnd.length > 0) {
|
||||||
conditions.$and = tagsAnd.map(tag => ({
|
conditions.$and = tagsAnd.map(tag => ({
|
||||||
tags: tag.trim()
|
tags: tag.trim()
|
||||||
@@ -73,7 +71,7 @@ const findBrews = async (req, res)=>{
|
|||||||
const sort = req.query.sort || 'title';
|
const sort = req.query.sort || 'title';
|
||||||
const dir = req.query.dir || 'asc';
|
const dir = req.query.dir || 'asc';
|
||||||
|
|
||||||
console.log(`Title: ${title}, Author: ${author}, page: ${page}, count: ${count}, tagsAnd: ${tagsAnd}, tagsOr: ${tagsOr} tagsNot: ${tagsNot}`);
|
//console.log(`Title: ${title}, Author: ${author}, page: ${page}, count: ${count}, tagsAnd: ${tagsAnd}, tagsOr: ${tagsOr} tagsNot: ${tagsNot}`);
|
||||||
|
|
||||||
const combinedQuery = {
|
const combinedQuery = {
|
||||||
$and : [
|
$and : [
|
||||||
|
|||||||
Reference in New Issue
Block a user