mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-17 05:39:46 +00:00
basic tag search
This commit is contained in:
@@ -45,6 +45,7 @@ const VaultPage = (props)=>{
|
|||||||
const v3Ref = useRef(null);
|
const v3Ref = useRef(null);
|
||||||
const legacyRef = useRef(null);
|
const legacyRef = useRef(null);
|
||||||
const submitButtonRef = useRef(null);
|
const submitButtonRef = useRef(null);
|
||||||
|
const [tagsList, setTagList] = useState([]);
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
disableSubmitIfFormInvalid();
|
disableSubmitIfFormInvalid();
|
||||||
@@ -64,7 +65,7 @@ const VaultPage = (props)=>{
|
|||||||
setSearching(false);
|
setSearching(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateUrl = (titleValue, authorValue, countValue, v3Value, legacyValue, page, sort, dir)=>{
|
const updateUrl = (titleValue, authorValue, countValue, v3Value, legacyValue, tagsValue, page, sort, dir)=>{
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
const urlParams = new URLSearchParams(url.search);
|
const urlParams = new URLSearchParams(url.search);
|
||||||
|
|
||||||
@@ -73,19 +74,22 @@ const VaultPage = (props)=>{
|
|||||||
urlParams.set('count', countValue);
|
urlParams.set('count', countValue);
|
||||||
urlParams.set('v3', v3Value);
|
urlParams.set('v3', v3Value);
|
||||||
urlParams.set('legacy', legacyValue);
|
urlParams.set('legacy', legacyValue);
|
||||||
|
urlParams.set('tags', tagsValue);
|
||||||
urlParams.set('page', page);
|
urlParams.set('page', page);
|
||||||
urlParams.set('sort', sort);
|
urlParams.set('sort', sort);
|
||||||
urlParams.set('dir', dir);
|
urlParams.set('dir', dir);
|
||||||
|
|
||||||
|
|
||||||
|
console.log(urlParams.toString());
|
||||||
url.search = urlParams.toString();
|
url.search = urlParams.toString();
|
||||||
window.history.replaceState(null, '', url.toString());
|
window.history.replaceState(null, '', url.toString());
|
||||||
};
|
};
|
||||||
|
|
||||||
const performSearch = async (title, author, count, v3, legacy, page, sort, dir)=>{
|
const performSearch = async (title, author, count, v3, legacy, tags, page, sort, dir)=>{
|
||||||
updateUrl(title, author, count, v3, legacy, page, sort, dir);
|
updateUrl(title, author, count, v3, legacy, tags, page, sort, dir);
|
||||||
|
|
||||||
const response = await request
|
const response = await request
|
||||||
.get(`/api/vault?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}&count=${count}&page=${page}&sort=${sort}&dir=${dir}`)
|
.get(`/api/vault?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}&tags=${tags}&count=${count}&page=${page}&sort=${sort}&dir=${dir}`)
|
||||||
.catch((error)=>{
|
.catch((error)=>{
|
||||||
console.log('error at loadPage: ', error);
|
console.log('error at loadPage: ', error);
|
||||||
setError(error);
|
setError(error);
|
||||||
@@ -96,10 +100,10 @@ const VaultPage = (props)=>{
|
|||||||
updateStateWithBrews(response.body.brews, page);
|
updateStateWithBrews(response.body.brews, page);
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadTotal = async (title, author, v3, legacy)=>{
|
const loadTotal = async (title, author, v3, legacy, tags)=>{
|
||||||
setTotalBrews(null);
|
setTotalBrews(null);
|
||||||
|
|
||||||
const response = await request.get(`/api/vault/total?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}`)
|
const response = await request.get(`/api/vault/total?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}&tags=${tags}`)
|
||||||
.catch((error)=>{
|
.catch((error)=>{
|
||||||
console.log('error at loadTotal: ');
|
console.log('error at loadTotal: ');
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -122,6 +126,7 @@ const VaultPage = (props)=>{
|
|||||||
const count = countRef.current.value || 20;
|
const count = countRef.current.value || 20;
|
||||||
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 tags = tagsList;
|
||||||
const sortOption = sort || 'title';
|
const sortOption = sort || 'title';
|
||||||
const dirOption = dir || 'asc';
|
const dirOption = dir || 'asc';
|
||||||
const pageProp = page || 1;
|
const pageProp = page || 1;
|
||||||
@@ -129,10 +134,10 @@ const VaultPage = (props)=>{
|
|||||||
setSort(sortOption);
|
setSort(sortOption);
|
||||||
setdir(dirOption);
|
setdir(dirOption);
|
||||||
|
|
||||||
performSearch(title, author, count, v3, legacy, pageProp, sortOption, dirOption);
|
performSearch(title, author, count, v3, legacy, tags, pageProp, sortOption, dirOption);
|
||||||
|
|
||||||
if(updateTotal)
|
if(updateTotal)
|
||||||
loadTotal(title, author, v3, legacy);
|
loadTotal(title, author, v3, legacy, tags);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderNavItems = ()=>(
|
const renderNavItems = ()=>(
|
||||||
@@ -208,11 +213,14 @@ const VaultPage = (props)=>{
|
|||||||
<label>
|
<label>
|
||||||
Tags
|
Tags
|
||||||
<TagInput
|
<TagInput
|
||||||
|
id='combobox-tags'
|
||||||
label='tags'
|
label='tags'
|
||||||
valuePatterns={[/^(?:(?:group|meta|system|type):)?[A-Za-z0-9][A-Za-z0-9 \/.\-]{0,40}$/]}
|
valuePatterns={/^\s*(?:(?:group|meta|system|type)\s*:\s*)?[A-Za-z0-9][A-Za-z0-9 \/\\.&_\-]{0,40}\s*$/}
|
||||||
placeholder='add tag' unique={true}
|
placeholder='add tag'
|
||||||
values={props.metadata.tags}
|
unique={true}
|
||||||
onChange={(e)=>this.handleFieldChange('tags', e)}
|
values={tagsList}
|
||||||
|
onChange={(e)=>setTagList(e.target.value)}
|
||||||
|
tooltip='You may start tags with "type", "system", "group" or "meta" followed by a colon ":", these will be colored in your userpage.'
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
|||||||
+11
-8
@@ -29,12 +29,15 @@ const rendererConditions = (legacy, v3)=>{
|
|||||||
return {}; // If all renderers selected, renderer field not needed in query for speed
|
return {}; // If all renderers selected, renderer field not needed in query for speed
|
||||||
};
|
};
|
||||||
|
|
||||||
const tagConditions = (tags) =>{
|
const tagConditions = (tags) => {
|
||||||
if(!tags) return {};
|
if (!tags || tags.length === 0) return {};
|
||||||
return {
|
|
||||||
$or: tags.map(tag => ({ tags: tag })),
|
return {
|
||||||
}
|
$or: tags.map(tag => ({
|
||||||
}
|
tags: tag.trim()
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const sortConditions = (sort, dir) => {
|
const sortConditions = (sort, dir) => {
|
||||||
return {
|
return {
|
||||||
@@ -48,7 +51,7 @@ const findBrews = async (req, res)=>{
|
|||||||
const page = Math.max(parseInt(req.query.page) || 1, 1);
|
const page = Math.max(parseInt(req.query.page) || 1, 1);
|
||||||
const count = Math.max(parseInt(req.query.count) || 20, 10);
|
const count = Math.max(parseInt(req.query.count) || 20, 10);
|
||||||
const skip = (page - 1) * count;
|
const skip = (page - 1) * count;
|
||||||
const tags = req.query.tags || [];
|
const tags = req.query.tags.split(',') || [];
|
||||||
const sort = req.query.sort || 'title';
|
const sort = req.query.sort || 'title';
|
||||||
const dir = req.query.dir || 'asc';
|
const dir = req.query.dir || 'asc';
|
||||||
|
|
||||||
@@ -94,7 +97,7 @@ const findBrews = async (req, res)=>{
|
|||||||
const findTotal = async (req, res)=>{
|
const findTotal = async (req, res)=>{
|
||||||
const title = req.query.title || '';
|
const title = req.query.title || '';
|
||||||
const author = req.query.author || '';
|
const author = req.query.author || '';
|
||||||
const tags = req.query.tags || [];
|
const tags = req.query.tags.split(',') || [];
|
||||||
|
|
||||||
const combinedQuery = {
|
const combinedQuery = {
|
||||||
$and : [
|
$and : [
|
||||||
|
|||||||
Reference in New Issue
Block a user