Skip to content
Open
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
22 changes: 11 additions & 11 deletions src/app/components/accordion-group/accordion-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ function Item({

type ItemType = {
title: string;
inline?: React.ReactNode;
contentComponent: React.ReactNode;
} | {
inline: React.ReactNode;
};

export default function AccordionGroup({
Expand Down Expand Up @@ -161,16 +162,15 @@ export default function AccordionGroup({
preExpanded={preExpandedUuids}
data-analytics-nav={analyticsNav}
>
{items.map(
(item) =>
item.inline || (
<Item
analytics={!!analyticsNav}
key={item.title}
{...item}
checkChevronDirection={chevronDirection}
/>
)
{items.filter((i) => 'title' in i).map(
(item) => (
<Item
analytics={!!analyticsNav}
key={item.title}
{...item}
checkChevronDirection={chevronDirection}
/>
)
)}
</Accordion>
</div>
Expand Down
20 changes: 10 additions & 10 deletions src/app/pages/details/common/get-this-title-files/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export function WebviewOption({model}: {model: Model}) {
const {GiveDialog, openGiveDialog} = useOpenGiveDialog();
const trackDownload = React.useCallback(
(event: TrackedMouseEvent) => {
trackLink(event, model.id);
trackLink(event, model.id.toString());
},
[model.id]
);
Expand All @@ -140,10 +140,10 @@ export function WebviewOption({model}: {model: Model}) {
<GiveDialog
link={webviewLink}
variant="View online"
warning={model.contentWarningText}
warning={model.contentWarningText ?? undefined}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal but I wonder if it would be nice to align the component types to the model so we don't have to do this

track="Online"
onDownload={trackDownload}
id={model.id}
id={model.id.toString()}
/>
{showCallout && (
<div className="callout recommended-callout">
Expand Down Expand Up @@ -173,12 +173,12 @@ export function PdfOption({model}: {model: Model}) {
const {GiveDialog, openGiveDialog} = useOpenGiveDialog();
const trackDownload = React.useCallback(
(event: TrackedMouseEvent) => {
trackLink(event, model.id);
trackLink(event, model.id.toString());
},
[model.id]
);

return (
return pdfLink ? (
<React.Fragment>
<SimpleLinkOption
link={pdfLink}
Expand All @@ -190,11 +190,11 @@ export function PdfOption({model}: {model: Model}) {
link={pdfLink}
track="PDF"
onDownload={trackDownload}
id={model.id}
warning={model.contentWarningText}
id={model.id.toString()}
warning={model.contentWarningText ?? undefined}
/>
</React.Fragment>
);
) : null;
}

export function usePrintCopyDialog() {
Expand Down Expand Up @@ -254,8 +254,8 @@ export function KindleOption({model}: {model: Model}) {

export function CheggOption({model}: {model: Model}) {
return (
<Option condition={model.cheggLink}>
<a href={model.cheggLink} data-track="Chegg Reader">
<Option condition={model.cheggLink ?? false}>
<a href={model.cheggLink as string} data-track="Chegg Reader">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type for this property seems confusing - it could be null, but not here? Do we need an assertString helper?

<img
className="logo-img"
src="/dist/images/icons/Chegglogo.svg"
Expand Down
14 changes: 7 additions & 7 deletions src/app/pages/details/common/get-this-title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import './get-this-title-files/get-this-title.scss';
import trackLink from './track-link';

export type Model = {
id: string;
id: number;
slug: string;
bookState: string;
comingSoon: boolean;
Expand All @@ -23,13 +23,13 @@ export type Model = {
kindleLink: string;
webviewRexLink: string;
webviewLink: string;
contentWarningText?: string;
contentWarningText: string | null;
rexCalloutTitle?: string;
rexCalloutBlurb?: string;
highResolutionPdfUrl: string;
lowResolutionPdfUrl: string;
cheggLink: string; // These may not be supported at all anymore,
cheggLinkText: string; // but the CMS is still serving them.
highResolutionPdfUrl: string | null;
lowResolutionPdfUrl: string | null;
cheggLink: string | null; // These may not be supported at all anymore,
cheggLinkText: string | null; // but the CMS is still serving them.
};
type ModelKey = 'bookshareLink' | 'kindleLink';
type TrackedMouseEvent = Parameters<typeof trackLink>[0];
Expand All @@ -50,7 +50,7 @@ export default function GetThisTitle({model}: {model: Model}) {
const [expanded, toggleExpanded] = useToggle(additionalOptions < 1);
const interceptLinkClicks = React.useCallback<React.MouseEventHandler>(
(event: TrackedMouseEvent) => {
trackLink(event, model.id);
trackLink(event, model.id.toString());
},
[model.id]
);
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/details/common/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type PartnerData = {
}

export function usePartnerFeatures(bookAbbreviation: string) {
const [blurbs, setBlurbs] = useState<object[]>([]);
const [blurbs, setBlurbs] = useState<ReturnType<typeof toBlurb>[]>([]);
const [includePartners, setIncludePartners] = useState('');

useEffect(() => {
Expand All @@ -64,5 +64,5 @@ export function usePartnerFeatures(bookAbbreviation: string) {
});
}, [bookAbbreviation]);

return [blurbs, includePartners];
return [blurbs, includePartners] as const;
}
6 changes: 3 additions & 3 deletions src/app/pages/details/common/publication-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import useDetailsContext, {ContextValues, IsbnType} from '../context';

function PdfUpdateInfo({updateDate, url}: {
updateDate?: string | null;
url?: string;
url: string | null;
}) {
if (!updateDate) {
return null;
Expand Down Expand Up @@ -209,8 +209,8 @@ function LabeledDate({label, date, className}: {
);
}

export default function PublicationInfo({url, polish}: {
url: string;
export default function PublicationInfo({url = null, polish}: {
url?: string | null;
polish?: boolean;
}) {
const model = useDetailsContext();
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/details/common/resource-box/left-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function LeftButton({model}: {model: ResourceModel & LinkIsSet}) {
const trackDownloadClick = React.useCallback(
(event: TrackedMouseEvent) => {
if (userStatus?.isInstructor) {
trackLink(event, model.bookModel?.id.toString());
trackLink(event, model.bookModel.id.toString());
}
},
[model.bookModel, userStatus]
Expand Down
13 changes: 7 additions & 6 deletions src/app/pages/details/common/resource-box/resource-box-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function encodeLocation(search: string) {
}

export type ResourceData = {
linkExternal: string;
linkDocumentUrl: string;
linkExternal?: string;
linkDocumentUrl?: string;
linkDocument?: {
file: string;
};
Expand All @@ -29,17 +29,18 @@ export type ResourceData = {
heading: string;
resourceCategory: string;
resourceUnlocked: boolean;
creatorFestResource: boolean;
creatorFestResource?: boolean;
description: string;
comingSoonText?: string;
};
comingSoonText: string | null;
videoReferenceNumber?: number | null;
k12?: boolean;
printLink: string | null;
resourceUnlocked: boolean;
resourceUnlocked?: boolean;
lockedText?: string;
resourceHeading: string;
resourceDescription: string;
resourceHeading?: string;
resourceDescription?: string;
featured?: boolean;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {useState} from 'react';
import buildContext from '~/components/jsx-helpers/build-context';
import type {ResourceData} from './common/resource-box/resource-box-utils';
import type {PromoteData} from './desktop-view/promo';
import type {Model as GetThisTitleModel} from './common/get-this-title';

export type LocaleType = {
locale: string;
Expand All @@ -24,7 +25,7 @@ type StuffContent = {
heading: string;
};
};
type VideoContent = {
export type VideoContent = {
title: string;
description: string;
embed: string;
Expand All @@ -37,13 +38,14 @@ type Author = {

export type IsbnType = 'print' | 'printSoftcover' | 'digital' | 'assignable';

export type ContextValues = {
export type ContextValues = GetThisTitleModel & {
id: number;
slug: string;
translations: Array<TranslationType>;
bookState: string;
comingSoon: boolean;
coverColor: string;
description: string;
meta: LocaleType;
reverseGradient: boolean;
title: string;
Expand All @@ -59,7 +61,7 @@ export type ContextValues = {
webinarContent?: WebinarContent;
freeStuffStudent: StuffContent;
freeStuffInstructor: StuffContent;
videos: VideoContent[];
videos: [VideoContent[]] | never[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type seems odd, but maybe only because the CMS data shape is odd?

setUseCardBackground?: React.Dispatch<React.SetStateAction<boolean>>;
authors: Author[];
created: string;
Expand Down
109 changes: 0 additions & 109 deletions src/app/pages/details/desktop-view/desktop-view.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first commit shows the JS->TS changes, and there are a few more changes in the 2nd commit.

This file was deleted.

Loading