mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-05 08:02:42 +00:00
remove owner functionality completely
This commit is contained in:
@@ -18,9 +18,8 @@ const request = require('../../utils/request-middleware.js');
|
|||||||
|
|
||||||
const VaultPage = (props) => {
|
const VaultPage = (props) => {
|
||||||
const [title, setTitle] = useState(props.query.title || '');
|
const [title, setTitle] = useState(props.query.title || '');
|
||||||
//state author and owner
|
//state author
|
||||||
const [author, setAuthor] = useState(props.query.author || '');
|
const [author, setAuthor] = useState(props.query.author || '');
|
||||||
const [owner, setOwner] = useState(props.query.owner ? props.query.owner !== 'false' : false);
|
|
||||||
const [legacy, setLegacy] = useState(props.query.legacy !== 'false');
|
const [legacy, setLegacy] = useState(props.query.legacy !== 'false');
|
||||||
const [v3, setV3] = useState(props.query.v3 !== 'false');
|
const [v3, setV3] = useState(props.query.v3 !== 'false');
|
||||||
const [count, setCount] = useState(props.query.count || 20);
|
const [count, setCount] = useState(props.query.count || 20);
|
||||||
@@ -32,7 +31,6 @@ const VaultPage = (props) => {
|
|||||||
|
|
||||||
const titleRef = useRef(null);
|
const titleRef = useRef(null);
|
||||||
const authorRef = useRef(null);
|
const authorRef = useRef(null);
|
||||||
const ownerRef = useRef(null);
|
|
||||||
const countRef = useRef(null);
|
const countRef = useRef(null);
|
||||||
const v3Ref = useRef(null);
|
const v3Ref = useRef(null);
|
||||||
const legacyRef = useRef(null);
|
const legacyRef = useRef(null);
|
||||||
@@ -51,14 +49,13 @@ const VaultPage = (props) => {
|
|||||||
setSearching(false);
|
setSearching(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateUrl = (title, author, owner, count, v3, legacy, page) => {
|
const updateUrl = (title, author, count, v3, legacy, page) => {
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
const urlParams = new URLSearchParams();
|
const urlParams = new URLSearchParams();
|
||||||
|
|
||||||
Object.entries({
|
Object.entries({
|
||||||
title,
|
title,
|
||||||
author,
|
author,
|
||||||
owner,
|
|
||||||
count,
|
count,
|
||||||
v3,
|
v3,
|
||||||
legacy,
|
legacy,
|
||||||
@@ -76,16 +73,15 @@ const VaultPage = (props) => {
|
|||||||
const performSearch = async ({
|
const performSearch = async ({
|
||||||
title,
|
title,
|
||||||
author,
|
author,
|
||||||
owner,
|
|
||||||
count,
|
count,
|
||||||
v3,
|
v3,
|
||||||
legacy,
|
legacy,
|
||||||
}) => {
|
}) => {
|
||||||
updateUrl(title, author, owner, count, v3, legacy, page);
|
updateUrl(title, author, count, v3, legacy, page);
|
||||||
if ((title || author) && (v3 || legacy)) {
|
if ((title || author) && (v3 || legacy)) {
|
||||||
try {
|
try {
|
||||||
const response = await request.get(
|
const response = await request.get(
|
||||||
`/api/vault?title=${title}&author=${author}&owner=${owner}&v3=${v3}&legacy=${legacy}&count=${count}&page=${page}`
|
`/api/vault?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}&count=${count}&page=${page}`
|
||||||
);
|
);
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
console.log(response.body.brews);
|
console.log(response.body.brews);
|
||||||
@@ -115,7 +111,7 @@ const VaultPage = (props) => {
|
|||||||
if ((title || author) && (v3 || legacy)) {
|
if ((title || author) && (v3 || legacy)) {
|
||||||
try {
|
try {
|
||||||
const response = await request.get(
|
const response = await request.get(
|
||||||
`/api/vault/total?title=${title}&author=${author}&owner=${owner}&v3=${v3}&legacy=${legacy}`
|
`/api/vault/total?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
@@ -135,7 +131,6 @@ const VaultPage = (props) => {
|
|||||||
|
|
||||||
const title = titleRef.current.value || '';
|
const title = titleRef.current.value || '';
|
||||||
const author = authorRef.current.value || '';
|
const author = authorRef.current.value || '';
|
||||||
const owner = ownerRef.current.checked != false;
|
|
||||||
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;
|
||||||
@@ -143,18 +138,17 @@ const VaultPage = (props) => {
|
|||||||
if (update) {
|
if (update) {
|
||||||
setTitle(title);
|
setTitle(title);
|
||||||
setAuthor(author);
|
setAuthor(author);
|
||||||
setOwner(owner);
|
|
||||||
setCount(count);
|
setCount(count);
|
||||||
setV3(v3);
|
setV3(v3);
|
||||||
setLegacy(legacy);
|
setLegacy(legacy);
|
||||||
|
|
||||||
performSearch({ title, author, owner, count, v3, legacy });
|
performSearch({ title, author, count, v3, legacy });
|
||||||
} else {
|
} else {
|
||||||
performSearch({ title, author, owner, count, v3, legacy });
|
performSearch({ title, author, count, v3, legacy });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (total) {
|
if (total) {
|
||||||
loadTotal({ title, author, owner, v3, legacy });
|
loadTotal({ title, author, v3, legacy });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -237,16 +231,6 @@ const VaultPage = (props) => {
|
|||||||
placeholder="Gazook89"
|
placeholder="Gazook89"
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<label style={{ visibility: 'hidden', position: 'absolute' }}>
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
name="owner"
|
|
||||||
ref={ownerRef}
|
|
||||||
defaultChecked={owner}
|
|
||||||
onChange={validateForm}
|
|
||||||
/>
|
|
||||||
Author is the owner
|
|
||||||
</label>
|
|
||||||
<label>
|
<label>
|
||||||
Results per page
|
Results per page
|
||||||
<select ref={countRef} name="count" defaultValue={count}>
|
<select ref={countRef} name="count" defaultValue={count}>
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ const buildTitleConditions = (title) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildAuthorConditions = (author, owner) => {
|
const buildAuthorConditions = (author) => {
|
||||||
if (!author) return {};
|
if (!author) return {};
|
||||||
return owner ? { 'authors.0': author } : { authors: author };
|
return { authors: author };
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleErrorResponse = (res, error, functionName) => {
|
const handleErrorResponse = (res, error, functionName) => {
|
||||||
@@ -53,7 +53,7 @@ const vault = {
|
|||||||
|
|
||||||
const title = req.query.title || '';
|
const title = req.query.title || '';
|
||||||
const author = req.query.author || '';
|
const author = req.query.author || '';
|
||||||
const owner = req.query.owner === 'true';
|
|
||||||
const page = Math.max(parseInt(req.query.page) || 1, 1);
|
const page = Math.max(parseInt(req.query.page) || 1, 1);
|
||||||
const mincount = 10;
|
const mincount = 10;
|
||||||
const count = Math.max(parseInt(req.query.count) || 20, mincount);
|
const count = Math.max(parseInt(req.query.count) || 20, mincount);
|
||||||
@@ -61,7 +61,7 @@ const vault = {
|
|||||||
|
|
||||||
const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3);
|
const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3);
|
||||||
const titleConditions = buildTitleConditions(title);
|
const titleConditions = buildTitleConditions(title);
|
||||||
const authorConditions = buildAuthorConditions(author, owner);
|
const authorConditions = buildAuthorConditions(author);
|
||||||
|
|
||||||
const combinedQuery = {
|
const combinedQuery = {
|
||||||
$and: [brewsQuery, titleConditions, authorConditions],
|
$and: [brewsQuery, titleConditions, authorConditions],
|
||||||
@@ -93,11 +93,10 @@ const vault = {
|
|||||||
try {
|
try {
|
||||||
const title = req.query.title || '';
|
const title = req.query.title || '';
|
||||||
const author = req.query.author || '';
|
const author = req.query.author || '';
|
||||||
const owner = req.query.owner === 'true';
|
|
||||||
|
|
||||||
const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3);
|
const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3);
|
||||||
const titleConditions = buildTitleConditions(title);
|
const titleConditions = buildTitleConditions(title);
|
||||||
const authorConditions = buildAuthorConditions(author, owner);
|
const authorConditions = buildAuthorConditions(author);
|
||||||
|
|
||||||
const combinedQuery = {
|
const combinedQuery = {
|
||||||
$and: [brewsQuery, titleConditions, authorConditions],
|
$and: [brewsQuery, titleConditions, authorConditions],
|
||||||
|
|||||||
Reference in New Issue
Block a user