Skip to content

Commit 5951883

Browse files
authored
Image and video optimizations (#1769)
* Use Next.js Image component in the resource drawer * Differentiate NavItem props from config type * Replace about page image * Next.js images for channel page logos. Unit image config in Logo component * Remove NavDrawer image paths (not used). Fix Storybook page * Upgrade to Next.js v15. Page params are now async * Upgrade @mui/material-nextjs for Next.js v15 * Utility for CSS background image-set() strings. Apply to homepage personalize section * Pass background static import src to banner * Use Logo component for unit cards * Suspense boundaries needed around carousels (useSearchParams() should be wrapped error) * Type fix * Display YouTube videos with simple iframe * 16:9 aspect ratio for videos * Revert "Suspense boundaries needed around carousels (useSearchParams() should be wrapped error)" This reverts commit b96fb61. * Revert "Upgrade @mui/material-nextjs for Next.js v15" This reverts commit 18fee78. * Revert "Upgrade to Next.js v15. Page params are now async" This reverts commit 20f0f05. * Update test for unit logo * Add Nextjs dependency in ol-utilities * Remove comments * Remove unnecessary truthy check * Separate Unit/Platform Logo * Move to peer dependency * Bckground src set for topic banner * Background src set on other banner backgrounds * Remove redundant display breakpoints * Apply changes to LearningResourceExpandedV2 * Update test
1 parent 53411ea commit 5951883

36 files changed

+397
-255
lines changed

frontends/main/src/app-pages/AboutPage/AboutPage.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import * as urls from "@/common/urls"
1111
import React from "react"
1212
import domeImage from "@/public/mit-dome-2.jpg"
13+
import Image from "next/image"
1314

1415
const WHAT_IS_MIT_OPEN_FRAGMENT_IDENTIFIER = "what-is-mit-learn"
1516
const NON_DEGREE_LEARNING_FRAGMENT_IDENTIFIER = "non-degree-learning"
@@ -81,13 +82,15 @@ const SubHeaderTextContainer = styled.div({
8182
alignSelf: "flex-start",
8283
})
8384

84-
const SubHeaderImage = styled.img({
85+
const SubHeaderImageContainer = styled.div({
8586
flexGrow: 1,
8687
alignSelf: "stretch",
88+
position: "relative",
89+
})
90+
91+
const SubHeaderImage = styled(Image)({
8792
borderRadius: "8px",
88-
backgroundSize: "cover",
89-
backgroundPosition: "center",
90-
backgroundImage: `url(${domeImage.src})`,
93+
objectFit: "cover",
9194
[theme.breakpoints.down("md")]: {
9295
height: "300px",
9396
},
@@ -165,7 +168,13 @@ const AboutPage: React.FC = () => {
165168
<li>Continue your education at your own pace</li>
166169
</List>
167170
</SubHeaderTextContainer>
168-
<SubHeaderImage />
171+
<SubHeaderImageContainer>
172+
<SubHeaderImage
173+
src={domeImage}
174+
alt="A view of the entablature of MIT's Great Dome"
175+
fill
176+
/>
177+
</SubHeaderImageContainer>
169178
</SubHeaderContainer>
170179
<BodySection>
171180
<HighlightContainer>

frontends/main/src/app-pages/ChannelPage/ChannelPage.test.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ describe("Channel Pages, Topic only", () => {
379379
})
380380

381381
describe("Channel Pages, Unit only", () => {
382-
it("Displays the channel title, banner, and avatar", async () => {
382+
it("Displays the channel title, banner", async () => {
383383
const { channel } = setupApis({
384384
search_filter: "offered_by=ocw",
385385
channel_type: "unit",
@@ -388,9 +388,24 @@ describe("Channel Pages, Unit only", () => {
388388
url: `/c/${channel.channel_type}/${channel.name}`,
389389
})
390390

391-
const title = await screen.findByRole("heading", { name: channel.title })
392-
getByImageSrc(title, `${window.origin}${channel.configuration.logo}`)
391+
await screen.findByRole("heading", { name: channel.title })
393392
})
393+
394+
it("Displays the channel logo", async () => {
395+
const { channel } = setupApis({
396+
name: "ocw",
397+
channel_type: "unit",
398+
})
399+
renderWithProviders(<ChannelPage />, {
400+
url: `/c/${channel.channel_type}/${channel.name}`,
401+
})
402+
403+
const images = await screen.findAllByRole("img", {
404+
name: "MIT OpenCourseWare",
405+
})
406+
expect(images[0]).toHaveAttribute("src", "/images/unit_logos/ocw.svg")
407+
})
408+
394409
it("Displays a featured carousel if the channel type is 'unit'", async () => {
395410
const { channel } = setupApis({
396411
search_filter: "offered_by=ocw",

frontends/main/src/app-pages/ChannelPage/DefaultChannelTemplate.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from "react"
22
import { styled, Breadcrumbs, Banner } from "ol-components"
3+
import { backgroundSrcSetCSS } from "ol-utilities"
34
import { SearchSubscriptionToggle } from "@/page-components/SearchSubscriptionToggle/SearchSubscriptionToggle"
45
import { useChannelDetail } from "api/hooks/channels"
56
import ChannelMenu from "@/components/ChannelMenu/ChannelMenu"
@@ -10,6 +11,7 @@ import {
1011
CHANNEL_TYPE_BREADCRUMB_TARGETS,
1112
ChannelControls,
1213
} from "./ChannelPageTemplate"
14+
import backgroundSteps from "@/public/images/backgrounds/background_steps.jpg"
1315

1416
const ChildrenContainer = styled.div(({ theme }) => ({
1517
paddingTop: "40px",
@@ -57,6 +59,7 @@ const DefaultChannelTemplate: React.FC<DefaultChannelTemplateProps> = ({
5759
const channel = useChannelDetail(String(channelType), String(name))
5860
const urlParams = new URLSearchParams(channel.data?.search_filter)
5961
const displayConfiguration = channel.data?.configuration
62+
6063
return (
6164
<>
6265
<Banner
@@ -87,7 +90,10 @@ const DefaultChannelTemplate: React.FC<DefaultChannelTemplateProps> = ({
8790
title={channel.data?.title}
8891
header={displayConfiguration?.heading}
8992
subHeader={displayConfiguration?.sub_heading}
90-
backgroundUrl={displayConfiguration?.banner_background}
93+
backgroundUrl={
94+
displayConfiguration?.banner_background ??
95+
backgroundSrcSetCSS(backgroundSteps)
96+
}
9197
extraActions={
9298
<ChannelControlsContainer>
9399
<ChannelControls>

frontends/main/src/app-pages/ChannelPage/TopicChannelTemplate.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ import {
2323
useLearningResourceTopic,
2424
useLearningResourceTopics,
2525
} from "api/hooks/learningResources"
26-
import { propsNotNil } from "ol-utilities"
26+
import { propsNotNil, backgroundSrcSetCSS } from "ol-utilities"
2727
import invariant from "tiny-invariant"
28+
import backgroundSteps from "@/public/images/backgrounds/background_steps.jpg"
2829

2930
const ChildrenContainer = styled.div(({ theme }) => ({
3031
paddingTop: "40px",
@@ -222,6 +223,7 @@ const TopicChannelTemplateInternal: React.FC<
222223
) : (
223224
<BreadcrumbsInternal current={channel.title} />
224225
)
226+
225227
return (
226228
<>
227229
<Banner
@@ -249,7 +251,7 @@ const TopicChannelTemplateInternal: React.FC<
249251
extraHeader={<TopicChips topic={topic} />}
250252
backgroundUrl={
251253
displayConfiguration?.banner_background ??
252-
"/images/backgrounds/background_steps.jpg"
254+
backgroundSrcSetCSS(backgroundSteps)
253255
}
254256
extraActions={
255257
<ChannelControlsContainer>

frontends/main/src/app-pages/ChannelPage/UnitChannelTemplate.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ import {
88
BannerBackground,
99
Typography,
1010
VisuallyHidden,
11+
UnitLogo,
1112
} from "ol-components"
13+
import { OfferedByEnum, SourceTypeEnum } from "api"
1214
import { SearchSubscriptionToggle } from "@/page-components/SearchSubscriptionToggle/SearchSubscriptionToggle"
1315
import { ChannelDetails } from "@/page-components/ChannelDetails/ChannelDetails"
1416
import { useChannelDetail } from "api/hooks/channels"
1517
import ChannelMenu from "@/components/ChannelMenu/ChannelMenu"
1618
import ResourceCarousel, {
1719
ResourceCarouselProps,
1820
} from "@/page-components/ResourceCarousel/ResourceCarousel"
19-
import { SourceTypeEnum } from "api"
2021
import { getSearchParamMap } from "@/common/utils"
2122
import { HOME as HOME_URL, UNITS as UNITS_URL } from "../../common/urls"
2223
import { ChannelTypeEnum } from "api/v0"
@@ -38,13 +39,13 @@ const FeaturedCoursesCarousel = styled(ResourceCarousel)(({ theme }) => ({
3839
},
3940
}))
4041

41-
const UnitLogo = styled.img(({ theme }) => ({
42+
const UnitLogoInverted = styled(UnitLogo)(({ theme }) => ({
4243
filter: "saturate(0%) invert(100%)",
44+
height: 50,
4345
maxWidth: "100%",
44-
width: "auto",
45-
height: "50px",
4646
[theme.breakpoints.down("md")]: {
47-
height: "40px",
47+
height: 40,
48+
width: "auto",
4849
},
4950
}))
5051

@@ -126,7 +127,10 @@ const UnitChannelTemplate: React.FC<UnitChannelTemplateProps> = ({
126127
<ChannelHeader>
127128
<VisuallyHidden>{channel.data?.title}</VisuallyHidden>
128129
{channel.data ? (
129-
<UnitLogo alt="" src={displayConfiguration.logo} />
130+
<UnitLogoInverted
131+
unitCode={name as OfferedByEnum}
132+
height={50}
133+
/>
130134
) : null}
131135
</ChannelHeader>
132136
<Stack gap={{ xs: "16px", lg: "32px" }}>

frontends/main/src/app-pages/DepartmentListingPage/DepartmentListingPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
Banner,
1414
Breadcrumbs,
1515
} from "ol-components"
16-
import { pluralize } from "ol-utilities"
16+
import { pluralize, backgroundSrcSetCSS } from "ol-utilities"
1717
import type { LearningResourceSchool } from "api"
1818
import { useSchoolsList } from "api/hooks/learningResources"
1919
import {
@@ -27,7 +27,7 @@ import {
2727
RiTerminalBoxLine,
2828
} from "@remixicon/react"
2929
import { HOME } from "@/common/urls"
30-
30+
import backgroundSteps from "@/public/images/backgrounds/background_steps.jpg"
3131
import { aggregateProgramCounts, aggregateCourseCounts } from "@/common/utils"
3232
import { useChannelCounts } from "api/hooks/channels"
3333

@@ -201,7 +201,6 @@ const DepartmentListingPage: React.FC = () => {
201201
return (
202202
<>
203203
<Banner
204-
backgroundUrl="/images/backgrounds/background_steps.jpg"
205204
title="Browse by Academic Department"
206205
header="At MIT, academic departments span a wide range of disciplines, from science and engineering to humanities. Select a department below to explore all of its non-degree learning offerings."
207206
navText={
@@ -211,6 +210,7 @@ const DepartmentListingPage: React.FC = () => {
211210
current="Departments"
212211
/>
213212
}
213+
backgroundUrl={backgroundSrcSetCSS(backgroundSteps)}
214214
/>
215215
<Container>
216216
<Grid container>

frontends/main/src/app-pages/HomePage/PersonalizeSection.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import React from "react"
22
import { Typography, styled, Container, ButtonLink } from "ol-components"
3+
import { backgroundSrcSetCSS } from "ol-utilities"
34
import { useUserMe } from "api/hooks/user"
45
import * as urls from "@/common/urls"
6+
import personalizeImage from "@/public/images/homepage/personalize-image.png"
7+
import personalizeBgImage from "@/public/images/homepage/personalize-bg.png"
58

69
const FullWidthBackground = styled.div(({ theme }) => ({
710
padding: "80px 0",
8-
background: 'url("/images/homepage/personalize-bg.png") center top no-repeat',
11+
background: `${backgroundSrcSetCSS(personalizeBgImage)} center top no-repeat`,
912
backgroundSize: "cover",
1013
[theme.breakpoints.down("md")]: {
1114
padding: "40px 0",
@@ -108,7 +111,7 @@ const PersonalizeSection = () => {
108111
return (
109112
<FullWidthBackground>
110113
<PersonalizeContainer>
111-
<ImageContainer src="/images/homepage/personalize-image.png" alt="" />
114+
<ImageContainer src={personalizeImage.src} alt="" />
112115
<PersonalizeContent />
113116
</PersonalizeContainer>
114117
</FullWidthBackground>

frontends/main/src/app-pages/LearningPathListingPage/LearningPathListingPage.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ const LearningPathListingPage: React.FC = () => {
8484
src="/images/backgrounds/course_search_banner.png"
8585
className="learningpaths-page"
8686
>
87-
{/* TODO <MetaTags title="Learning Paths" social={false} />
88-
<Helmet>
89-
<meta name="robots" content="noindex,noarchive" />
90-
</Helmet>
91-
*/}
9287
<Container maxWidth="md" style={{ paddingBottom: 100 }}>
9388
<GridContainer>
9489
<GridColumn variant="single-full">

0 commit comments

Comments
 (0)