Skip to content

Commit

Permalink
Merge pull request #508 from Popret/query-format-fix
Browse files Browse the repository at this point in the history
Fixed inconsistent displaying of "legal:commander" being applied to queries by default when it wasn't
  • Loading branch information
ldeluigi committed Jun 11, 2024
2 parents 27727a6 + bf1dbb3 commit 45a2fd9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/pages/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ const AUTO_SORT_MAP: Record<string, "-"> = {
}

const PAGE_SIZE = 50

const doesQuerySpecifyFormat = (query: string) : boolean => {
return query.includes('legal:') || query.includes('banned:')|| query.includes('format:');
}

const Search: React.FC<Props> = ({combos, count, page, bannedCombos}: Props) => {

const router = useRouter();
Expand Down Expand Up @@ -89,7 +94,7 @@ const Search: React.FC<Props> = ({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 (
<>
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 45a2fd9

Please sign in to comment.