Skip to content

Commit

Permalink
feat: use searchParams in the ui
Browse files Browse the repository at this point in the history
  • Loading branch information
djpiper28 committed Nov 26, 2023
1 parent a97f4c9 commit fd55ca7
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 216 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ mse_langs.c

mse_langs.h
/cmake-build-debug/

frontend/pnpm-lock.yaml
4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"@types/react-dom": "18.2.7",
"autoprefixer": "10.4.14",
"eslint": "8.45.0",
"eslint-config-next": "13.4.12",
"eslint-config-next": "14.0.3",
"font-awesome": "^4.7.0",
"next": "13.4.12",
"next": "14.0.3",
"postcss": "8.4.27",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function RootLayout({
<FontAwesomeIcon icon={faGithub} />
</Link>
</div>
<div className='bg-slate-100'>
<div className="bg-slate-100">
<div className="p-5 justify-center">{children}</div>
</div>
</body>
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ export default function Home() {
<h3 className="text-xl font-bold">Query Composition</h3>
<p>The syntax is designed to mimic that of Scryfall.</p>
<p>You can use brackets as normal with negation.</p>
<p>The below query gets all mutally exclusive cards in m20 and m19.</p>
<p>
The below query gets all mutally exclusive cards in m20 and m19.
</p>
<blockquote>
(set:m19 or set:m20) and !(set:m20 and set:m19)
(set:m19 or set:m20) and !(set:m20 and set:m19)
</blockquote>
</div>
<div>
<h3 className="text-xl font-bold">Operations</h3>
<p>Used in this form <blockquote>{'<query> <operator> <query>'}</blockquote></p>
<p>
Used in this form{" "}
<blockquote>{"<query> <operator> <query>"}</blockquote>
</p>
<ul>
<li>and</li>
<li>or</li>
Expand Down
61 changes: 0 additions & 61 deletions frontend/src/app/q/[...query]/card.tsx

This file was deleted.

46 changes: 0 additions & 46 deletions frontend/src/app/q/[...query]/page.tsx

This file was deleted.

9 changes: 0 additions & 9 deletions frontend/src/app/q/[...query]/pageChanger.tsx

This file was deleted.

33 changes: 0 additions & 33 deletions frontend/src/app/q/[query]/[page]/colour.tsx

This file was deleted.

21 changes: 0 additions & 21 deletions frontend/src/app/q/[query]/[page]/manamoji.tsx

This file was deleted.

22 changes: 0 additions & 22 deletions frontend/src/app/q/[query]/[page]/oracle.tsx

This file was deleted.

9 changes: 0 additions & 9 deletions frontend/src/app/q/[query]/[page]/pageChanger.tsx

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import Card from "./card";
import PageChanger from "./pageChanger";

export default async function SearchResultPage({
params,
searchParams,
}: {
params: {
searchParams: {
query: string;
page: number;
page?: string;
};
}) {
const query = decodeURIComponent(params.query);
const query = decodeURIComponent(searchParams.query);
const resp = await fetch("http://127.0.0.1:4365/api", {
method: "POST",
body: query,
headers: {
page: (params.page - 1).toString(),
page: (parseInt(searchParams.page ?? "1") - 1).toString(),
},
});
const data = await resp.json();
Expand All @@ -38,7 +38,12 @@ export default async function SearchResultPage({
.fill(0)
.slice(Math.max(0, page - 5), page + 1 + 50)
.map((_, i) => (
<PageChanger base_url={"/q/" + params.query} page={i + 1} key={i} />
<PageChanger
base_url={"/q/?query=" + searchParams.query}
page={i + 1}
key={i}
currentPage={(i + 1).toString() == searchParams.page}
/>
))}
</div>
</div>
Expand Down
21 changes: 21 additions & 0 deletions frontend/src/app/q/pageChanger.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Link from "next/link";

interface Props {
base_url: string;
page: number;
currentPage: boolean;
}

export default function PageChanger({ base_url, page, currentPage }) {
return (
<Link href={base_url + "&page=" + page.toString()}>
<h1
className={`p-3 ${
currentPage ? "bg-red-700" : "bg-blue-500"
} text-white rounded`}
>
{page}
</h1>
</Link>
);
}
9 changes: 6 additions & 3 deletions frontend/src/app/searchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { useSearchParams } from "next/navigation";

export default function SearchBar(props: { query?: string }) {
const [name, setName] = useState(props.query || "");
export default function SearchBar() {
const searchParams = useSearchParams();
const query = searchParams.get("query");
const [name, setName] = useState(query);
const router = useRouter();

return (
Expand All @@ -12,7 +15,7 @@ export default function SearchBar(props: { query?: string }) {
<form
className="flex flex-row w-full justify-between gap-3"
onSubmit={(e) => {
router.push("/q/" + encodeURIComponent(name) + "/1");
router.push("/q/?query=" + encodeURIComponent(name) + "&page=1");
e.preventDefault();
}}
>
Expand Down

0 comments on commit fd55ca7

Please sign in to comment.