From 4358a49e27f32536ddc037bfacef4480b80dcffd Mon Sep 17 00:00:00 2001 From: Roy Johnson Date: Fri, 26 Jul 2024 13:06:42 -0500 Subject: [PATCH] Remove buyprint (#2274) * Remove all BuyPrint stuff; leave placeholder in BuyBook component * Use amazon_link for BuyBook --------- Co-authored-by: staxly[bot] <35789409+staxly[bot]@users.noreply.github.com> --- script/prerender/local.ts | 7 -- script/prerender/thread.ts | 4 -- src/app/content/actions.ts | 2 - src/app/content/components/BuyBook.spec.tsx | 17 +++-- src/app/content/components/BuyBook.tsx | 27 +++---- src/app/content/components/Content.tsx | 2 +- .../__snapshots__/BuyBook.spec.tsx.snap | 26 +------ .../locationChange/buyPrintConfig.spec.ts | 71 ------------------- .../hooks/locationChange/buyPrintConfig.ts | 25 ------- src/app/content/hooks/locationChange/index.ts | 2 - src/app/content/reducer.ts | 4 -- src/app/content/selectors.ts | 5 -- src/app/content/types.ts | 2 - src/app/types.ts | 2 - src/config.js | 1 - .../createBuyPrintConfigLoader.spec.ts | 63 ---------------- src/gateways/createBuyPrintConfigLoader.ts | 61 ---------------- src/index.tsx | 6 -- src/service-worker.ts | 12 ---- src/test/createTestServices.ts | 4 -- 20 files changed, 23 insertions(+), 320 deletions(-) delete mode 100644 src/app/content/hooks/locationChange/buyPrintConfig.spec.ts delete mode 100644 src/app/content/hooks/locationChange/buyPrintConfig.ts delete mode 100644 src/gateways/createBuyPrintConfigLoader.spec.ts delete mode 100644 src/gateways/createBuyPrintConfigLoader.ts diff --git a/script/prerender/local.ts b/script/prerender/local.ts index 05d9dee155..45f53a7f74 100644 --- a/script/prerender/local.ts +++ b/script/prerender/local.ts @@ -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'; @@ -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, @@ -59,9 +56,6 @@ 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('buy-print'), - }); const practiceQuestionsLoader = createPracticeQuestionsLoader(); const bookConfigLoader = createBookConfigLoader(); @@ -69,7 +63,6 @@ async function render() { const renderHelpers = { archiveLoader, bookConfigLoader, - buyPrintConfigLoader, config, highlightClient, osWebLoader, diff --git a/script/prerender/thread.ts b/script/prerender/thread.ts index c10594384e..5106d28c94 100644 --- a/script/prerender/thread.ts +++ b/script/prerender/thread.ts @@ -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'; @@ -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, @@ -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, diff --git a/src/app/content/actions.ts b/src/app/content/actions.ts index 16fc708963..90ebedb7f1 100644 --- a/src/app/content/actions.ts +++ b/src/app/content/actions.ts @@ -20,8 +20,6 @@ export const resetToc = createStandardAction('Content/resetToc')(); export const openMobileMenu = createStandardAction('Content/openMobileMenu')(); export const closeMobileMenu = createStandardAction('Content/closeMobileMenu')(); -export const receiveBuyPrintConfig = createStandardAction('Content/receiveBuyPrintConfig')(); - export const requestBook = createStandardAction('Content/requestBook')(); export const receiveBook = createStandardAction('Content/receiveBook')(); diff --git a/src/app/content/components/BuyBook.spec.tsx b/src/app/content/components/BuyBook.spec.tsx index 3f63666775..c98cfa7ad9 100644 --- a/src/app/content/components/BuyBook.spec.tsx +++ b/src/app/content/components/BuyBook.spec.tsx @@ -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( - + ); const tree = component.toJSON(); expect(tree).toMatchSnapshot(); }); - it('returns null', () => { + it('returns null when book lacks amazon_link', () => { const component = renderer.create( - + ); const tree = component.toJSON(); diff --git a/src/app/content/components/BuyBook.tsx b/src/app/content/components/BuyBook.tsx index 13fbe0f18d..4755022c6e 100644 --- a/src/app/content/components/BuyBook.tsx +++ b/src/app/content/components/BuyBook.tsx @@ -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` @@ -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 {(msg) => msg} - {config.disclosure && {config.disclosure}} ; }; diff --git a/src/app/content/components/Content.tsx b/src/app/content/components/Content.tsx index 8de252b7c4..0ac4d0f615 100644 --- a/src/app/content/components/Content.tsx +++ b/src/app/content/components/Content.tsx @@ -103,7 +103,7 @@ const Content = ({mobileExpanded, book}: {mobileExpanded: boolean; book: Book}) - +