Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove buyprint #2274

Merged
merged 6 commits into from
Jul 26, 2024
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
7 changes: 0 additions & 7 deletions script/prerender/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { ArchivePage, VersionedArchiveBookWithConfig } from '../../src/app/conte
import config from '../../src/config';
import createArchiveLoader from '../../src/gateways/createArchiveLoader';
import createBookConfigLoader from '../../src/gateways/createBookConfigLoader';
import createBuyPrintConfigLoader from '../../src/gateways/createBuyPrintConfigLoader';
import { BuyPrintResponse } from '../../src/gateways/createBuyPrintConfigLoader';
import createHighlightClient from '../../src/gateways/createHighlightClient';
import createOSWebLoader from '../../src/gateways/createOSWebLoader';
import { OSWebBook } from '../../src/gateways/createOSWebLoader';
Expand All @@ -29,7 +27,6 @@ import { renderSitemap, renderSitemapIndex } from './sitemap';
import userLoader from './stubbedUserLoader';

const {
REACT_APP_BUY_PRINT_CONFIG_URL,
REACT_APP_HIGHLIGHTS_URL,
REACT_APP_OS_WEB_API_URL,
REACT_APP_SEARCH_URL,
Expand Down Expand Up @@ -59,17 +56,13 @@ async function render() {
});
const searchClient = createSearchClient(`http://localhost:${port}${REACT_APP_SEARCH_URL}`);
const highlightClient = createHighlightClient(`http://localhost:${port}${REACT_APP_HIGHLIGHTS_URL}`);
const buyPrintConfigLoader = createBuyPrintConfigLoader(REACT_APP_BUY_PRINT_CONFIG_URL, {
cache: createDiskCache<string, BuyPrintResponse>('buy-print'),
});
const practiceQuestionsLoader = createPracticeQuestionsLoader();
const bookConfigLoader = createBookConfigLoader();

const {server} = await startServer({port, onlyProxy: true});
const renderHelpers = {
archiveLoader,
bookConfigLoader,
buyPrintConfigLoader,
config,
highlightClient,
osWebLoader,
Expand Down
4 changes: 0 additions & 4 deletions script/prerender/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { assertDefined, assertNotNull, assertObject, assertString, tuple } from
import config from '../../src/config';
import createArchiveLoader from '../../src/gateways/createArchiveLoader';
import createBookConfigLoader from '../../src/gateways/createBookConfigLoader';
import createBuyPrintConfigLoader from '../../src/gateways/createBuyPrintConfigLoader';
import createHighlightClient from '../../src/gateways/createHighlightClient';
import createOSWebLoader from '../../src/gateways/createOSWebLoader';
import createPracticeQuestionsLoader from '../../src/gateways/createPracticeQuestionsLoader';
Expand Down Expand Up @@ -46,7 +45,6 @@ const {
ARCHIVE_URL,
HIGHLIGHTS_URL,
OS_WEB_URL,
REACT_APP_BUY_PRINT_CONFIG_URL,
REACT_APP_HIGHLIGHTS_URL,
REACT_APP_OS_WEB_API_URL,
REACT_APP_SEARCH_URL,
Expand Down Expand Up @@ -125,14 +123,12 @@ async function makeTaskFunctionsMap() {
const osWebLoader = createOSWebLoader(`${OS_WEB_URL}${REACT_APP_OS_WEB_API_URL}`);
const searchClient = createSearchClient(`${SEARCH_URL}${REACT_APP_SEARCH_URL}`);
const highlightClient = createHighlightClient(`${HIGHLIGHTS_URL}${REACT_APP_HIGHLIGHTS_URL}`);
const buyPrintConfigLoader = createBuyPrintConfigLoader(REACT_APP_BUY_PRINT_CONFIG_URL);
const practiceQuestionsLoader = createPracticeQuestionsLoader();
const bookConfigLoader = createBookConfigLoader();

const services = {
archiveLoader,
bookConfigLoader,
buyPrintConfigLoader,
config,
highlightClient,
osWebLoader,
Expand Down
2 changes: 0 additions & 2 deletions src/app/content/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export const resetToc = createStandardAction('Content/resetToc')<void>();
export const openMobileMenu = createStandardAction('Content/openMobileMenu')<void>();
export const closeMobileMenu = createStandardAction('Content/closeMobileMenu')<void>();

export const receiveBuyPrintConfig = createStandardAction('Content/receiveBuyPrintConfig')<State['buyPrint']>();

export const requestBook = createStandardAction('Content/requestBook')<Params['book']>();
export const receiveBook = createStandardAction('Content/receiveBook')<Book>();

Expand Down
17 changes: 11 additions & 6 deletions src/app/content/components/BuyBook.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,34 @@ import renderer from 'react-test-renderer';
import createTestStore from '../../../test/createTestStore';
import TestContainer from '../../../test/TestContainer';
import { Store } from '../../types';
import { receiveBuyPrintConfig } from '../actions';
import { Book } from '../types';
import BuyBook from './BuyBook';

describe('BuyBook', () => {
let store: Store;
const bookWithLink = {
amazon_link: 'https://amazon.com/some-book',
} as Book;
const bookWithoutLink = {
amazon_link: '',
} as Book;

beforeEach(() => {
store = createTestStore();
});

it('renders when config is available', () => {
store.dispatch(receiveBuyPrintConfig({url: 'https://example.com', disclosure: 'asdf'}));
it('renders when book has amazon_link', () => {
const component = renderer.create(<TestContainer store={store}>
<BuyBook />
<BuyBook book={bookWithLink } />
</TestContainer>);

const tree = component.toJSON();
expect(tree).toMatchSnapshot();
});

it('returns null', () => {
it('returns null when book lacks amazon_link', () => {
const component = renderer.create(<TestContainer store={store}>
<BuyBook />
<BuyBook book={bookWithoutLink} />
</TestContainer>);

const tree = component.toJSON();
Expand Down
27 changes: 8 additions & 19 deletions src/app/content/components/BuyBook.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React from 'react';
import { FormattedMessage } from 'react-intl';
import { useSelector } from 'react-redux';
import styled from 'styled-components/macro';
import { textRegularSize, textRegularStyle } from '../../components/Typography';
import { textRegularSize } from '../../components/Typography';
import theme from '../../theme';
import { buyPrintConfig } from '../selectors';
import { contentTextWidth } from './constants';
import { disablePrint } from './utils/disablePrint';
import { Book, BookWithOSWebData } from '../types';

// tslint:disable-next-line:variable-name
const BuyBookAlignment = styled.div`
Expand Down Expand Up @@ -34,34 +33,24 @@ const BuyBookLink = styled.a`
font-weight: 700;
`;

// tslint:disable-next-line:variable-name
const BuyPrintDisclosure = styled.p`
flex: 1;
align-self: stretch;
margin: 1.6rem 0 0 0;
${textRegularStyle}
font-size: 1.2rem;
line-height: 1.7rem;
`;

// tslint:disable-next-line: variable-name
const BuyBook = () => {
const config = useSelector(buyPrintConfig);

if (!config) { return null; }
const BuyBook = ({book}: {book: Book}) => {
const bookWithOSwebData = book as BookWithOSWebData;

if (!bookWithOSwebData.amazon_link) {
return null;
}
return <BuyBookAlignment>
<BuyBookLink
target='_blank'
rel='noopener'
href={config.url}
href={bookWithOSwebData.amazon_link}
data-analytics-label='buy-book'
>
<FormattedMessage id='i18n:toolbar:buy-book:text'>
{(msg) => msg}
</FormattedMessage>
</BuyBookLink>
{config.disclosure && <BuyPrintDisclosure>{config.disclosure}</BuyPrintDisclosure>}
</BuyBookAlignment>;
};

Expand Down
2 changes: 1 addition & 1 deletion src/app/content/components/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const Content = ({mobileExpanded, book}: {mobileExpanded: boolean; book: Book})
<Page>
<PrevNextBar />
<LabsCTA />
<BuyBook />
<BuyBook book={book} />
</Page>
<Attribution />
<Footer />
Expand Down
26 changes: 3 additions & 23 deletions src/app/content/components/__snapshots__/BuyBook.spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`BuyBook renders when config is available 1`] = `
exports[`BuyBook renders when book has amazon_link 1`] = `
.c0 {
width: 100%;
display: -webkit-box;
Expand Down Expand Up @@ -40,21 +40,6 @@ exports[`BuyBook renders when config is available 1`] = `
font-weight: 700;
}

.c2 {
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
-webkit-align-self: stretch;
-ms-flex-item-align: stretch;
align-self: stretch;
margin: 1.6rem 0 0 0;
color: #424242;
font-size: 1.6rem;
line-height: 2.5rem;
font-size: 1.2rem;
line-height: 1.7rem;
}

@media print {
.c0 {
display: none;
Expand All @@ -67,18 +52,13 @@ exports[`BuyBook renders when config is available 1`] = `
<a
className="c1"
data-analytics-label="buy-book"
href="https://example.com"
href="https://amazon.com/some-book"
rel="noopener"
target="_blank"
>
Order a print copy
</a>
<p
className="c2"
>
asdf
</p>
</div>
`;

exports[`BuyBook returns null 1`] = `null`;
exports[`BuyBook returns null when book lacks amazon_link 1`] = `null`;
71 changes: 0 additions & 71 deletions src/app/content/hooks/locationChange/buyPrintConfig.spec.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/app/content/hooks/locationChange/buyPrintConfig.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/app/content/hooks/locationChange/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { loadStudyGuides } from '../../studyGuides/hooks';
import initializeIntl from '../intlHook';
import receiveContent from '../receiveContent';
import registerPageView from '../registerPageView';
import loadBuyPrintConfig from './buyPrintConfig';
import resolveContent, { resolveBook } from './resolveContent';

export const contentRouteHookBody: RouteHookBody<typeof content> = (services) => {
Expand All @@ -28,7 +27,6 @@ export const contentRouteHookBody: RouteHookBody<typeof content> = (services) =>
await Promise.all([
boundRegisterPageView(action),
syncSearch(services)(action),
loadBuyPrintConfig(services)(),
loadStudyGuides(services)(),
loadPracticeQuestions(services)(),
initializeIntl(services)(),
Expand Down
4 changes: 0 additions & 4 deletions src/app/content/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { State } from './types';

export const initialState = {
bookStylesUrl: null,
buyPrint: null,
highlights: initialHighlightState,
loading: {},
mobileMenuOpen: false,
Expand Down Expand Up @@ -96,9 +95,6 @@ function reduceContent(state: State, action: AnyAction) {
const loading = omit('page', state.loading);
return {...omit(['page', 'references'], state), loading, pageNotFoundId: action.payload};
}
case getType(actions.receiveBuyPrintConfig): {
return {...state, buyPrint: action.payload};
}
case getType(locationChange): {
if (!matchForRoute(content, action.payload.match)) {
return initialState;
Expand Down
5 changes: 0 additions & 5 deletions src/app/content/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ export const book = createSelector(
(state) => state.book
);

export const buyPrintConfig = createSelector(
localState,
(state) => state.buyPrint
);

export const bookTheme = createSelector(
book,
(currentBook) => hasOSWebData(currentBook) ? currentBook.theme : defaultTheme
Expand Down
2 changes: 0 additions & 2 deletions src/app/content/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BooksConfig } from '../../gateways/createBookConfigLoader';
import { BuyPrintResponse } from '../../gateways/createBuyPrintConfigLoader';
import { Route, RouteParams } from '../navigation/types';
import { TextResizerValue } from './constants';
import { State as HighlightState } from './highlights/types';
Expand Down Expand Up @@ -55,7 +54,6 @@ export interface State {
book?: Book;
page?: Page;
references: Array<PageReferenceMap | PageReferenceError>;
buyPrint: Pick<BuyPrintResponse['buy_urls'][number], 'url' | 'disclosure'> | null;
textSize: TextResizerValue | null;
bookStylesUrl: string | null;
}
Expand Down
Loading
Loading