Skip to content

Commit

Permalink
Added dynamic legacy path redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Apr 22, 2024
1 parent 890dd90 commit f986187
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
27 changes: 27 additions & 0 deletions app/books/title/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {BooksQuery} from "@lib/gql/__generated__/drupal";
import {graphqlClient} from "@lib/gql/gql-client";
import {notFound, redirect} from "next/navigation";

const LegacyBookPage = async ({searchParams}: { searchParams?: { [_key: string]: string } }) => {
// Fetch all the books, sort by authors, and then build pagination and side alpha selection.
let fetchMore = true;
let query: BooksQuery;
let afterCursor = null;
let destinationUrl: string | undefined;

if (!searchParams || !searchParams.id) notFound();
const workId = parseInt(searchParams.id);

while (fetchMore) {
query = await graphqlClient({next: {tags: ["views:sup_books"]}}).Books({after: afterCursor})

destinationUrl = query.nodeSupBooks.nodes.find(node => node.supBookWorkIdNumber && node.supBookWorkIdNumber === workId)?.path;

fetchMore = query.nodeSupBooks.pageInfo.hasNextPage && !destinationUrl
afterCursor = query.nodeSupBooks.pageInfo.endCursor;
}
if (destinationUrl) redirect(destinationUrl);
notFound();
}

export default LegacyBookPage;
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const PreBuiltAuthorList = async ({...props}: Props) => {
let books: NodeSupBook[] = [];

while (fetchMore) {
query = await graphqlClient({next: {tags: ["paths"]}}).Books({after: afterCursor})
query = await graphqlClient({next: {tags: ["views:sup_books"]}}).Books({after: afterCursor})
fetchMore = query.nodeSupBooks.pageInfo.hasNextPage
afterCursor = query.nodeSupBooks.pageInfo.endCursor;
books = [...books, ...query.nodeSupBooks.nodes as NodeSupBook[]];
Expand Down
10 changes: 5 additions & 5 deletions src/lib/gql/__generated__/drupal.d.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/lib/gql/__generated__/queries.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/lib/gql/fragments-node.drupal.gql
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ fragment FragmentNodeSupBookTeaser on NodeSupBook {
supBookAuthors {
...FragmentNameType
}
supBookWorkIdNumber
}

fragment FragmentNodeStanfordCourseTeaser on NodeStanfordCourse {
Expand Down

0 comments on commit f986187

Please sign in to comment.