-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Layouts * Flex-page * Details page, part 1 * details/links-to-translations * details/resource-box * details/common (get-this-title) * details/get-this-title (give-before-*) * models * explore-by-subject * Code review items
- Loading branch information
1 parent
681bfd4
commit edcb242
Showing
30 changed files
with
1,407 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 17 additions & 3 deletions
20
src/app/pages/details/common/get-this-title-files/give-before-pdf/use-donation-popup-data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,28 @@ | ||
import React from 'react'; | ||
import {useDataFromSlug} from '~/helpers/page-data-utils'; | ||
|
||
export type DonationPopupData = { | ||
download_image: string; | ||
download_ready?: string; | ||
header_image: string; | ||
header_title: string; | ||
header_subtitle: string; | ||
give_link_text: string; | ||
give_link: string; | ||
thank_you_link_text: string; | ||
thank_you_link: string; | ||
giving_optional: string; | ||
go_to_pdf_link_text: string; | ||
hide_donation_popup: boolean; | ||
}; | ||
|
||
export default function useDonationPopupData() { | ||
// When useDataFromSlug moves to TS, we can make it type-generic | ||
const data1 = useDataFromSlug('donations/donation-popup'); | ||
const data = React.useMemo( | ||
() => (data1?.length > 0 ? data1[0] : {}), | ||
[data1] | ||
); | ||
|
||
return data; | ||
return data as DonationPopupData; | ||
} | ||
|
||
export type DonationPopupData = ReturnType<typeof useDonationPopupData>; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React from 'react'; | ||
import {useToggle} from '~/helpers/data'; | ||
import { | ||
TocOption, | ||
WebviewOption, | ||
PdfOption, | ||
BookshareOption, | ||
IbooksOption, | ||
KindleOption, | ||
CheggOption, | ||
OptionExpander | ||
} from './get-this-title-files/options'; | ||
import OrderPrintCopy from './get-this-title-files/order-print-copy/order-print-copy'; | ||
import './get-this-title-files/get-this-title.scss'; | ||
import trackLink from './track-link'; | ||
|
||
type Model = { | ||
id: string; | ||
slug: string; | ||
bookshareLink: string; | ||
ibookLink: string; | ||
kindleLink: string; | ||
}; | ||
type ModelKey = 'bookshareLink' | 'ibookLink' | 'kindleLink'; | ||
type TrackedMouseEvent = Parameters<typeof trackLink>[0]; | ||
|
||
function AdditionalOptions({model}: {model: Model}) { | ||
return ( | ||
<React.Fragment> | ||
<BookshareOption model={model} /> | ||
<IbooksOption model={model} /> | ||
<KindleOption model={model} /> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
export default function GetThisTitle({model}: {model: Model}) { | ||
const additionalOptions = ( | ||
['bookshareLink', 'ibookLink', 'kindleLink'] as ModelKey[] | ||
).filter((key) => model[key]).length; | ||
const [expanded, toggleExpanded] = useToggle(additionalOptions < 1); | ||
const interceptLinkClicks = React.useCallback<React.MouseEventHandler>( | ||
(event: TrackedMouseEvent) => { | ||
trackLink(event, model.id); | ||
}, | ||
[model.id] | ||
); | ||
|
||
return ( | ||
<div className="get-the-book"> | ||
<div className="get-this-title"> | ||
<div | ||
className="options" | ||
onClick={interceptLinkClicks} | ||
data-analytics-nav="Get the book" | ||
> | ||
<TocOption model={model} /> | ||
<WebviewOption model={model} /> | ||
<PdfOption model={model} /> | ||
<CheggOption model={model} /> | ||
{expanded && <AdditionalOptions model={model} />} | ||
<OptionExpander | ||
{...{expanded, additionalOptions}} | ||
toggle={toggleExpanded} | ||
/> | ||
</div> | ||
</div> | ||
<OrderPrintCopy slug={model.slug} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import {render, screen} from '@testing-library/preact'; | ||
import {describe, it} from '@jest/globals'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import LandingLayout from '~/layouts/landing/landing'; | ||
|
||
describe('layouts/landing', () => { | ||
const data: Parameters<typeof LandingLayout>[0]['data'] = { | ||
title: 'the-title', | ||
layout: [] | ||
}; | ||
|
||
it('renders without layout values', () => { | ||
render( | ||
<MemoryRouter initialEntries={['']}> | ||
<LandingLayout data={data}> | ||
<div>child contents</div> | ||
</LandingLayout> | ||
</MemoryRouter> | ||
); | ||
expect(screen.getAllByRole('img')).toHaveLength(2); | ||
expect(screen.getAllByRole('link')).toHaveLength(3); | ||
}); | ||
it('renders with layout values', () => { | ||
data.layout.push({ | ||
value: { | ||
navLinks: [ | ||
{ | ||
text: 'link-name', | ||
target: { | ||
type: 'link-type', | ||
value: 'link-value' | ||
} | ||
} | ||
] | ||
} | ||
}); | ||
render( | ||
<MemoryRouter initialEntries={['']}> | ||
<LandingLayout data={data}> | ||
<div>child contents</div> | ||
</LandingLayout> | ||
</MemoryRouter> | ||
); | ||
expect(screen.getAllByRole('link')).toHaveLength(4); | ||
}); | ||
}); |
Oops, something went wrong.