Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions frontends/api/src/ssr/prefetch.ts

This file was deleted.

76 changes: 0 additions & 76 deletions frontends/api/src/ssr/serverQueryClient.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useQuery } from "@tanstack/react-query"
import { userEnrollmentsToDashboardCourses } from "./transform"
import { DashboardCard } from "./DashboardCard"
import { DashboardCourse, EnrollmentStatus } from "./types"
import { MaybeHasStatusAndDetail } from "@/app/getQueryClient"
import type { AxiosError } from "axios"

const Wrapper = styled.div(({ theme }) => ({
marginTop: "32px",
Expand Down Expand Up @@ -183,7 +183,7 @@ const EnrollmentDisplay = () => {
...enrollmentQueries.courseRunEnrollmentsList(),
select: userEnrollmentsToDashboardCourses,
throwOnError: (error) => {
const err = error as MaybeHasStatusAndDetail
const err = error as AxiosError<{ detail?: string }>
const status = err?.response?.status
if (
status === 403 &&
Expand Down
20 changes: 12 additions & 8 deletions frontends/main/src/app/(products)/courses/[readable_id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import React from "react"
import { HydrationBoundary } from "@tanstack/react-query"
import { HydrationBoundary, dehydrate } from "@tanstack/react-query"
import { safeGenerateMetadata, standardizeMetadata } from "@/common/metadata"
import { prefetch } from "api/ssr/prefetch"
import CoursePage from "@/app-pages/ProductPages/CoursePage"
import { notFound } from "next/navigation"
import { pagesQueries } from "api/mitxonline-hooks/pages"
import { coursesQueries } from "api/mitxonline-hooks/courses"
import { DEFAULT_RESOURCE_IMG } from "ol-utilities"
import { getServerQueryClient } from "api/ssr/serverQueryClient"
import { getQueryClient } from "@/app/getQueryClient"

export const generateMetadata = async (
props: PageProps<"/courses/[readable_id]">,
) => {
const params = await props.params

return safeGenerateMetadata(async () => {
const queryClient = getServerQueryClient()
const queryClient = getQueryClient()

const data = await queryClient.fetchQuery(
pagesQueries.coursePages(decodeURIComponent(params.readable_id)),
Expand Down Expand Up @@ -44,12 +43,17 @@ const Page: React.FC<PageProps<"/courses/[readable_id]">> = async (props) => {
* fetching via client, and calling notFound() if data missing.
* This approach blocked by wagtail api requiring auth.
*/
const { dehydratedState } = await prefetch([
pagesQueries.coursePages(readableId),
coursesQueries.coursesList({ readable_id: readableId }),
const queryClient = getQueryClient()

await Promise.all([
queryClient.prefetchQuery(pagesQueries.coursePages(readableId)),
queryClient.prefetchQuery(
coursesQueries.coursesList({ readable_id: readableId }),
),
])

return (
<HydrationBoundary state={dehydratedState}>
<HydrationBoundary state={dehydrate(queryClient)}>
<CoursePage readableId={readableId} />
</HydrationBoundary>
)
Expand Down
20 changes: 12 additions & 8 deletions frontends/main/src/app/(products)/programs/[readable_id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import React from "react"
import { HydrationBoundary } from "@tanstack/react-query"
import { HydrationBoundary, dehydrate } from "@tanstack/react-query"
import { safeGenerateMetadata, standardizeMetadata } from "@/common/metadata"
import { prefetch } from "api/ssr/prefetch"
import ProgramPage from "@/app-pages/ProductPages/ProgramPage"
import { notFound } from "next/navigation"
import { pagesQueries } from "api/mitxonline-hooks/pages"
import { programsQueries } from "api/mitxonline-hooks/programs"
import { DEFAULT_RESOURCE_IMG } from "ol-utilities"
import { getServerQueryClient } from "api/ssr/serverQueryClient"
import { getQueryClient } from "@/app/getQueryClient"

export const generateMetadata = async (
props: PageProps<"/programs/[readable_id]">,
) => {
const params = await props.params

return safeGenerateMetadata(async () => {
const queryClient = getServerQueryClient()
const queryClient = getQueryClient()

const data = await queryClient.fetchQuery(
pagesQueries.programPages(decodeURIComponent(params.readable_id)),
Expand Down Expand Up @@ -46,12 +45,17 @@ const Page: React.FC<PageProps<"/programs/[readable_id]">> = async (props) => {
* fetching via client, and calling notFound() if data missing.
* This approach blocked by wagtail api requiring auth.
*/
const { dehydratedState } = await prefetch([
pagesQueries.programPages(readableId),
programsQueries.programsList({ readable_id: readableId }),
const queryClient = getQueryClient()

await Promise.all([
queryClient.prefetchQuery(pagesQueries.programPages(readableId)),
queryClient.prefetchQuery(
programsQueries.programsList({ readable_id: readableId }),
),
])

return (
<HydrationBoundary state={dehydratedState}>
<HydrationBoundary state={dehydrate(queryClient)}>
<ProgramPage readableId={readableId} />
</HydrationBoundary>
)
Expand Down
34 changes: 18 additions & 16 deletions frontends/main/src/app/c/[channelType]/[name]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react"
import ChannelPage from "@/app-pages/ChannelPage/ChannelPage"
import { getServerQueryClient } from "api/ssr/serverQueryClient"
import { ChannelTypeEnum, UnitChannel } from "api/v0"
import {
FeaturedListOfferedByEnum,
Expand All @@ -9,8 +8,7 @@ import {
LearningResourceOfferorDetail,
} from "api"
import { getMetadataAsync, safeGenerateMetadata } from "@/common/metadata"
import { HydrationBoundary } from "@tanstack/react-query"
import { prefetch } from "api/ssr/prefetch"
import { HydrationBoundary, dehydrate } from "@tanstack/react-query"
import {
learningResourceQueries,
offerorQueries,
Expand All @@ -25,6 +23,7 @@ import {
} from "@/app-pages/ChannelPage/searchRequests"
import { isInEnum } from "@/common/utils"
import { notFound } from "next/navigation"
import { getQueryClient } from "@/app/getQueryClient"

export async function generateMetadata({
searchParams,
Expand All @@ -33,7 +32,7 @@ export async function generateMetadata({
const { channelType, name } = await params

return safeGenerateMetadata(async () => {
const queryClient = getServerQueryClient()
const queryClient = getQueryClient()

const data = await queryClient.fetchQuery(
channelQueries.detailByType(channelType, name),
Expand All @@ -58,16 +57,20 @@ const Page: React.FC<PageProps<"/c/[channelType]/[name]">> = async ({

const search = await searchParams

const { queryClient } = await prefetch([
offerorQueries.list({}),
const queryClient = getQueryClient()

await Promise.all([
queryClient.prefetchQuery(offerorQueries.list({})),
channelType === ChannelTypeEnum.Unit &&
learningResourceQueries.featured({
limit: 12,
offered_by: [name as FeaturedListOfferedByEnum],
}),
queryClient.prefetchQuery(
learningResourceQueries.featured({
limit: 12,
offered_by: [name as FeaturedListOfferedByEnum],
}),
),
channelType === ChannelTypeEnum.Unit &&
testimonialsQueries.list({ offerors: [name] }),
channelQueries.detailByType(channelType, name),
queryClient.prefetchQuery(testimonialsQueries.list({ offerors: [name] })),
queryClient.prefetchQuery(channelQueries.detailByType(channelType, name)),
])

const channel = queryClient.getQueryData<UnitChannel>(
Expand Down Expand Up @@ -102,13 +105,12 @@ const Page: React.FC<PageProps<"/c/[channelType]/[name]">> = async ({
page: Number(search.page ?? 1),
})

const { dehydratedState } = await prefetch(
[learningResourceQueries.search(searchRequest as LRSearchRequest)],
queryClient,
await queryClient.prefetchQuery(
learningResourceQueries.search(searchRequest as LRSearchRequest),
)

return (
<HydrationBoundary state={dehydratedState}>
<HydrationBoundary state={dehydrate(queryClient)}>
<ChannelPage />
</HydrationBoundary>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React from "react"
import { Metadata } from "next"
import CertificatePage from "@/app-pages/CertificatePage/CertificatePage"
import { prefetch } from "api/ssr/prefetch"
import { certificateQueries } from "api/mitxonline-hooks/certificates"
import { HydrationBoundary } from "@tanstack/react-query"
import { HydrationBoundary, dehydrate } from "@tanstack/react-query"
import { isInEnum } from "@/common/utils"
import { notFound } from "next/navigation"
import { safeGenerateMetadata, standardizeMetadata } from "@/common/metadata"
import { getServerQueryClient } from "api/ssr/serverQueryClient"
import { getQueryClient } from "@/app/getQueryClient"

const { NEXT_PUBLIC_ORIGIN } = process.env

Expand All @@ -24,7 +23,7 @@ export async function generateMetadata({
return safeGenerateMetadata(async () => {
let title, displayType, userName

const queryClient = getServerQueryClient()
const queryClient = getQueryClient()

if (certificateType === CertificateType.Course) {
const data = await queryClient.fetchQuery(
Expand Down Expand Up @@ -68,18 +67,24 @@ const Page: React.FC<
notFound()
}

const { dehydratedState } = await prefetch([
certificateType === CertificateType.Course
? certificateQueries.courseCertificatesRetrieve({
cert_uuid: uuid,
})
: certificateQueries.programCertificatesRetrieve({
cert_uuid: uuid,
}),
])
const queryClient = getQueryClient()

if (certificateType === CertificateType.Course) {
await queryClient.prefetchQuery(
certificateQueries.courseCertificatesRetrieve({
cert_uuid: uuid,
}),
)
} else {
await queryClient.prefetchQuery(
certificateQueries.programCertificatesRetrieve({
cert_uuid: uuid,
}),
)
}

return (
<HydrationBoundary state={dehydratedState}>
<HydrationBoundary state={dehydrate(queryClient)}>
<CertificatePage
certificateType={certificateType}
uuid={uuid}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { AxiosError } from "axios"
import type { NextRequest } from "next/server"
import * as Sentry from "@sentry/nextjs"
import moment from "moment"
import { getServerQueryClient } from "api/ssr/serverQueryClient"
import { getQueryClient } from "@/app/getQueryClient"
import { certificateQueries } from "api/mitxonline-hooks/certificates"
import {
V2CourseRunCertificate,
Expand Down Expand Up @@ -562,7 +562,7 @@ type RouteContext = {
export async function GET(req: NextRequest, ctx: RouteContext) {
const { certificateType, uuid } = await ctx.params

const queryClient = getServerQueryClient()
const queryClient = getQueryClient()

let pdfDoc

Expand Down
Loading
Loading