diff --git a/src/app/pages/subjects/new/context.tsx b/src/app/pages/subjects/new/context.tsx index 4d378bf86..fa783d711 100644 --- a/src/app/pages/subjects/new/context.tsx +++ b/src/app/pages/subjects/new/context.tsx @@ -2,20 +2,26 @@ import React from 'react'; import buildContext from '~/components/jsx-helpers/build-context'; import usePageData from '~/helpers/use-page-data'; import useLanguageContext from '~/contexts/language'; -import type { LocaleEntry } from '~components/language-selector/language-selector'; -import type { InfoBox } from './info-boxes'; -import { toNumber } from 'lodash'; +import type {LocaleEntry} from '~/components/language-selector/language-selector'; +import type {InfoBox} from './info-boxes'; +import type {TutorValue} from './tutor-ad'; +import {toNumber} from 'lodash'; type DevStandardKeys = 'devStandard1Heading'; type DevStandardPair = {[key in DevStandardKeys]: string}; export type SubjectData = { icon: string; categories: string[]; -} +}; +export type ImageData = { + id: number; + title: string; + file: string; +}; type SubjectsPageData = { title: string; pageDescription: string; - subjects: { [key: string]: SubjectData} + subjects: {[key: string]: SubjectData}; translations: Array<{value: LocaleEntry[]}>; books?: { bookState: string; @@ -26,10 +32,16 @@ type SubjectsPageData = { headingImage: { meta: { downloadUrl: string; + }; + }; + infoBoxes: InfoBox[]; + tutorAd: [ + { + value: TutorValue; } - } - infoBoxes: InfoBox[] + ]; }; + // The Page data before DevStandardPair is translated to aboutBlurbs type RawPageData = SubjectsPageData & DevStandardPair; @@ -86,7 +98,4 @@ function useContextValue() { const {useContext, ContextProvider} = buildContext({useContextValue}); -export { - useContext as default, - ContextProvider as SubjectsContextProvider -}; +export {useContext as default, ContextProvider as SubjectsContextProvider}; diff --git a/src/app/pages/subjects/new/import-tutor-ad.js b/src/app/pages/subjects/new/import-tutor-ad.js new file mode 100644 index 000000000..9c3d55946 --- /dev/null +++ b/src/app/pages/subjects/new/import-tutor-ad.js @@ -0,0 +1,3 @@ +import TutorAd from './tutor-ad'; + +export default TutorAd; diff --git a/src/app/pages/subjects/new/info-boxes.tsx b/src/app/pages/subjects/new/info-boxes.tsx index 08b66d57d..8dfd0342e 100644 --- a/src/app/pages/subjects/new/info-boxes.tsx +++ b/src/app/pages/subjects/new/info-boxes.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import useSubjectsContext from './context'; +import useSubjectsContext, {ImageData} from './context'; import RawHTML from '~/components/jsx-helpers/raw-html'; import './info-boxes.scss'; @@ -7,13 +7,9 @@ export type InfoBox = { value: { heading: string; text: string; - image: { - id: number; - title: string; - file: string; - } - }[] -} + image: ImageData; + }[]; +}; function AboutBlurb({image, heading, text: description}: InfoBox['value'][0]) { return ( @@ -33,7 +29,9 @@ export function InfoBoxes({infoBoxes}: {infoBoxes: InfoBox['value']}) { return (
- {infoBoxes.map((b, i) => )} + {infoBoxes.map((b, i) => ( + + ))}
); @@ -43,5 +41,5 @@ export default function InfoBoxesUsingContext() { const {infoBoxes} = useSubjectsContext(); const unwrappedData = infoBoxes[0]?.value; - return (); + return ; } diff --git a/src/app/pages/subjects/new/specific/context.d.ts b/src/app/pages/subjects/new/specific/context.d.ts index a27119916..ca5b8351e 100644 --- a/src/app/pages/subjects/new/specific/context.d.ts +++ b/src/app/pages/subjects/new/specific/context.d.ts @@ -1,5 +1,6 @@ import React from 'react'; import { LocaleEntry } from '~/components/language-selector/language-selector'; +import { ImageData } from '../context'; import type { InfoBox } from '../info-boxes'; // There will be more, but this is what I need for now @@ -36,7 +37,7 @@ type SectionContent = { type SectionInfo = { content: SectionContent & { - image: string; + image: ImageData; adHtml: string; } }; diff --git a/src/app/pages/subjects/new/specific/specific.tsx b/src/app/pages/subjects/new/specific/specific.tsx index 1a3957af1..8208874ff 100644 --- a/src/app/pages/subjects/new/specific/specific.tsx +++ b/src/app/pages/subjects/new/specific/specific.tsx @@ -17,7 +17,7 @@ import LazyLoad from 'react-lazyload'; import useFoundSubject from './use-found-subject'; import AboutOpenStax from '../about-openstax'; import {InfoBoxes} from '../info-boxes'; -import { useCanonicalLink } from '~/helpers/use-document-head'; +import {useCanonicalLink} from '~/helpers/use-document-head'; import cn from 'classnames'; import './specific.scss'; @@ -43,17 +43,13 @@ function TutorAd() { return null; } const { - content: { - image, - heading, - adHtml: html, - linkHref: ctaLink, - linkText: ctaText - } + content: {image, heading, adHtml, linkHref, linkText} } = tutorAd; return ( - + ); } @@ -89,32 +85,32 @@ function MainContent({subject}: {subject: FoundSubject}) { -
+
-
+
-
+
@@ -138,8 +134,8 @@ function SubjectInContext({subject}: {subject: FoundSubject}) { -
-
+
+
diff --git a/src/app/pages/subjects/new/subjects.tsx b/src/app/pages/subjects/new/subjects.tsx index 6a9d0a913..23bd054fe 100644 --- a/src/app/pages/subjects/new/subjects.tsx +++ b/src/app/pages/subjects/new/subjects.tsx @@ -11,7 +11,7 @@ import './subjects.scss'; const importLanguageSelector = () => import('./language-selector-section.js'); const importSubjectsListing = () => import('./import-subjects-listing.js'); -const importTutorAd = () => import('./tutor-ad.js'); +const importTutorAd = () => import('./import-tutor-ad.js'); const importInfoBoxes = () => import('./import-info-boxes.js'); const importPhilanthropicSupport = () => import('./philanthropic-support.js'); diff --git a/src/app/pages/subjects/new/tutor-ad.js b/src/app/pages/subjects/new/tutor-ad.tsx similarity index 51% rename from src/app/pages/subjects/new/tutor-ad.js rename to src/app/pages/subjects/new/tutor-ad.tsx index a2f8f71c7..b3b07cab9 100644 --- a/src/app/pages/subjects/new/tutor-ad.js +++ b/src/app/pages/subjects/new/tutor-ad.tsx @@ -1,10 +1,24 @@ import React from 'react'; -import useSubjectsContext from './context'; +import useSubjectsContext, {ImageData} from './context'; import RawHTML from '~/components/jsx-helpers/raw-html'; import useOptimizedImage from '~/helpers/use-optimized-image'; import './tutor-ad.scss'; -export function TutorAdThatTakesData({heading, image, html, ctaLink, ctaText}) { +export type TutorValue = { + heading: string; + image: ImageData; + adHtml: string; + linkHref: string; + linkText: string; +}; + +export function TutorAdThatTakesData({ + heading, + image, + adHtml, + linkHref, + linkText +}: TutorValue) { const optimizedImage = useOptimizedImage(image?.file, 400); return ( @@ -12,8 +26,10 @@ export function TutorAdThatTakesData({heading, image, html, ctaLink, ctaText}) {

{heading}

- - {ctaText} + + + {linkText} +
); @@ -21,9 +37,11 @@ export function TutorAdThatTakesData({heading, image, html, ctaLink, ctaText}) { export default function TutorAd() { const {tutorAd} = useSubjectsContext(); - const {image, heading, adHtml: html, linkHref: ctaLink, linkText: ctaText} = tutorAd[0].value; + const {image, heading, adHtml, linkHref, linkText} = tutorAd[0].value; return ( - + ); }