From 3cde52d4ad2a7f1049a20835252f6379f4adac19 Mon Sep 17 00:00:00 2001 From: Janosh Date: Mon, 10 Jun 2024 19:57:19 +0200 Subject: [PATCH 1/3] legalityMessage now consistent with query sent to server. --- src/pages/search.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/pages/search.tsx b/src/pages/search.tsx index 61f29ae9ae..e39ffeebe5 100644 --- a/src/pages/search.tsx +++ b/src/pages/search.tsx @@ -58,6 +58,11 @@ const AUTO_SORT_MAP: Record = { } const PAGE_SIZE = 50 + +const doesQuerySpecifyFormat: boolean = (query: string) => { + return query.includes('legal:') || query.includes('banned:') || query.includes('restricted:') || query.includes('format:') || query.includes('f:'); +} + const Search: React.FC = ({combos, count, page, bannedCombos}: Props) => { const router = useRouter(); @@ -89,7 +94,7 @@ const Search: React.FC = ({combos, count, page, bannedCombos}: Props) => router.push({ pathname: "/search/", query: { ...router.query, order: value, page: "1" } }); }; - const legalityMessage = (parsedSearchQuery.includes("legal:")) ? "" : " (legal:commander has been applied by default)" + const legalityMessage = doesQuerySpecifyFormat(parsedSearchQuery) ? "" : " (legal:commander has been applied by default)" return ( <> @@ -180,8 +185,8 @@ export default Search; export const getServerSideProps: GetServerSideProps = async (context) => { let query = `${context.query.q}`; - const queryDoesntSpecifyFormat = !query.includes('legal:') && !query.includes('banned:') && !query.includes('format:'); - if (queryDoesntSpecifyFormat) query = `${query} legal:commander`; + let isQueryMissingFormat = !doesQuerySpecifyFormat(query); + if (isQueryMissingFormat) query = `${query} legal:commander`; query = encodeURIComponent(query) const requestService = new RequestService(context) const order = context.query.order || DEFAULT_ORDER @@ -192,7 +197,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => { const backendCombos = results ? results.results : []; - if (backendCombos.length === 0 && queryDoesntSpecifyFormat) { + if (backendCombos.length === 0 && isQueryMissingFormat) { // Try searching in banned combos let query = `${context.query.q} banned:commander`; query = encodeURIComponent(query) From 2fd4727d4c206bef561375f75bb334d253611968 Mon Sep 17 00:00:00 2001 From: Janosh Date: Mon, 10 Jun 2024 20:04:50 +0200 Subject: [PATCH 2/3] fixed typo in type specification --- src/pages/search.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/search.tsx b/src/pages/search.tsx index e39ffeebe5..019d7fb80c 100644 --- a/src/pages/search.tsx +++ b/src/pages/search.tsx @@ -59,7 +59,7 @@ const AUTO_SORT_MAP: Record = { const PAGE_SIZE = 50 -const doesQuerySpecifyFormat: boolean = (query: string) => { +const doesQuerySpecifyFormat = (query: string) : boolean => { return query.includes('legal:') || query.includes('banned:') || query.includes('restricted:') || query.includes('format:') || query.includes('f:'); } From bf1dbb31380e3a33a124e3c8e1d342aec3a2e34f Mon Sep 17 00:00:00 2001 From: Janosh Date: Tue, 11 Jun 2024 00:47:07 +0200 Subject: [PATCH 3/3] updated Query check to be inline with Commander Spellbook backend syntax instead of Scryfall syntax --- src/pages/search.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/search.tsx b/src/pages/search.tsx index 019d7fb80c..7b369f2456 100644 --- a/src/pages/search.tsx +++ b/src/pages/search.tsx @@ -60,7 +60,7 @@ const AUTO_SORT_MAP: Record = { const PAGE_SIZE = 50 const doesQuerySpecifyFormat = (query: string) : boolean => { - return query.includes('legal:') || query.includes('banned:') || query.includes('restricted:') || query.includes('format:') || query.includes('f:'); + return query.includes('legal:') || query.includes('banned:')|| query.includes('format:'); } const Search: React.FC = ({combos, count, page, bannedCombos}: Props) => {