diff --git a/src/TTX.Web/routes/creators/index.tsx b/src/TTX.Web/routes/creators/index.tsx index 5d03d3e..e3663de 100644 --- a/src/TTX.Web/routes/creators/index.tsx +++ b/src/TTX.Web/routes/creators/index.tsx @@ -15,7 +15,11 @@ const TAKE = 20; export const handler = define.handlers({ async GET(ctx) { const client = getApiClient(ctx.state.token); - const index = Number(ctx.url.searchParams.get("page") ?? "1"); + + const rawPage = Number(ctx.url.searchParams.get("page") ?? "1"); + // Default to first page if we go to index 0 or invalid value + const index = rawPage >= 1 ? rawPage : 1; + const orderDir = ctx.url.searchParams.get("orderDir") == OrderDirection.Ascending ? OrderDirection.Ascending @@ -43,6 +47,17 @@ export const handler = define.handlers({ orderDir, ); + // Make sure we are in bounds, if not redirect to the last page + const totalPages = Math.max(1, Math.ceil(page.total / TAKE)); + if (index > totalPages) { + const url = new URL(ctx.url); + url.searchParams.set("page", totalPages.toString()); + return new Response(null, { + status: 302, + headers: { Location: url.toString() }, + }); + } + return { data: { page, orderBy, orderDir, index } }; }, }); @@ -320,9 +335,14 @@ function CreatorTable(props: {
1 + ? nav({ index: props.index - 1 }) + : undefined} aria-label="Previous page" - class="join-item btn rounded-l-2xl border-gray-200 max-md:px-2 max-md:text-sm dark:border-gray-700" + aria-disabled={props.index <= 1} + class={`join-item btn rounded-l-2xl border-gray-200 max-md:px-2 max-md:text-sm dark:border-gray-700 ${ + props.index <= 1 ? "pointer-events-none opacity-50" : "" + }`} > « @@ -340,8 +360,15 @@ function CreatorTable(props: { ))} = totalPages} + class={`join-item btn rounded-r-2xl border-gray-200 max-md:px-2 max-md:text-sm dark:border-gray-700 ${ + props.index >= totalPages + ? "pointer-events-none opacity-50" + : "" + }`} > »