Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
xlecunff-pass committed Nov 21, 2024
1 parent f52657c commit 35ab359
Show file tree
Hide file tree
Showing 14 changed files with 290 additions and 103 deletions.
30 changes: 30 additions & 0 deletions src/features/offer/components/OfferCine/CineContentCTA.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { FC } from 'react'
import styled from 'styled-components/native'

import { useOfferCTA } from 'features/offer/components/OfferContent/OfferCTAProvider'
import { ButtonWithLinearGradient } from 'ui/components/buttons/buttonWithLinearGradient/ButtonWithLinearGradient'
import { StickyBottomWrapper } from 'ui/components/StickyBottomWrapper/StickyBottomWrapper'
import { Spacer } from 'ui/theme'

export const CineContentCTA: FC = () => {
const { onPress, wording } = useOfferCTA()

return (
<StickyBottomWrapper>
<CallToActionContainer>
<Spacer.Column numberOfSpaces={6} />
<ButtonWithLinearGradient wording={wording} onPress={onPress} />
<Spacer.Column numberOfSpaces={6} />
</CallToActionContainer>
</StickyBottomWrapper>
)
}

const CallToActionContainer = styled.View(({ theme }) => ({
alignSelf: 'center',
paddingHorizontal: theme.contentPage.marginHorizontal,
width: '100%',
...(!theme.isMobileViewport && {
maxWidth: theme.contentPage.maxWidth,
}),
}))
27 changes: 23 additions & 4 deletions src/features/offer/components/OfferCine/OfferCineBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React, { FC } from 'react'
import React, { FC, useEffect } from 'react'
import { View, ViewStyle } from 'react-native'
import { InView } from 'react-native-intersection-observer'
import styled, { useTheme } from 'styled-components/native'

import { OfferResponseV2 } from 'api/gen'
import { MovieCalendarProvider } from 'features/offer/components/MoviesScreeningCalendar/MovieCalendarContext'
import { OfferCineContent } from 'features/offer/components/OfferCine/OfferCineContent'
import { useOfferCTA } from 'features/offer/components/OfferContent/OfferCTAProvider'
import { AppThemeType } from 'theme'
import { Anchor } from 'ui/components/anchor/Anchor'
import { useScrollToAnchor } from 'ui/components/anchor/AnchorContext'
import { getSpacing, Spacer, TypoDS } from 'ui/theme'
import { getHeadingAttrs } from 'ui/theme/typographyAttrs/getHeadingAttrs'

Expand All @@ -17,12 +21,27 @@ type Props = {

export const OfferCineBlock: FC<Props> = ({ title, onSeeVenuePress, offer }) => {
const theme = useTheme()
const { setButton, showButton } = useOfferCTA()
const scrollToAnchor = useScrollToAnchor()

useEffect(() => {
setButton('Accéder aux séances', () => {
scrollToAnchor('offer-cine-availabilities')
})
}, [scrollToAnchor, setButton])

return (
<Container testID="offer-new-xp-cine-block">
<TitleContainer>
<TypoDS.Title3 {...getHeadingAttrs(2)}>{title}</TypoDS.Title3>
</TitleContainer>
<Anchor name="offer-cine-availabilities">
<InView
onChange={(inView) => {
showButton(!inView)
}}>
<TitleContainer>
<TypoDS.Title3 {...getHeadingAttrs(2)}>{title}</TypoDS.Title3>
</TitleContainer>
</InView>
</Anchor>
<Spacer.Column numberOfSpaces={4} />
<MovieCalendarProvider nbOfDays={15} containerStyle={getCalendarStyle(theme)}>
<OfferCineContent offer={offer} onSeeVenuePress={onSeeVenuePress} />
Expand Down
43 changes: 43 additions & 0 deletions src/features/offer/components/OfferContent/OfferCTAProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, { createContext, useContext, ReactNode, useState, useCallback, useMemo } from 'react'

interface OfferCTAContextValue {
wording: string
onPress: () => void
setButton: (wording: string, onPress: () => void) => void
showButton: (isVisible: boolean) => void
isButtonVisible: boolean
}

const OfferCTAContext = createContext<OfferCTAContextValue | undefined>(undefined)

interface OfferCTAProviderProps {
children: ReactNode
}

export const OfferCTAProvider: React.FC<OfferCTAProviderProps> = ({ children }) => {
const [wording, setWording] = useState<string>('')
const [isVisible, setIsVisible] = useState<boolean>(false)
const [onPress, setOnPress] = useState<() => void>(() => () => {
return
})

const setButton = useCallback((newWording: string, newOnPress: () => void) => {
setWording(newWording)
setOnPress(() => newOnPress)
}, [])

const value = useMemo(
() => ({ wording, onPress, setButton, showButton: setIsVisible, isButtonVisible: isVisible }),
[isVisible, onPress, setButton, wording]
)

return <OfferCTAContext.Provider value={value}>{children}</OfferCTAContext.Provider>
}

export const useOfferCTA = (): OfferCTAContextValue => {
const context = useContext(OfferCTAContext)
if (!context) {
throw new Error('useOfferCTAButton must be used within an OfferCTAProvider')
}
return context
}
24 changes: 13 additions & 11 deletions src/features/offer/components/OfferContent/OfferContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import styled from 'styled-components/native'

import { UseNavigationType } from 'features/navigation/RootNavigator/types'
import { OfferContentBase } from 'features/offer/components/OfferContent/OfferContentBase'
import { OfferCTAProvider } from 'features/offer/components/OfferContent/OfferCTAProvider'
import { OfferCTAButton } from 'features/offer/components/OfferCTAButton/OfferCTAButton'
import { useOfferBatchTracking } from 'features/offer/helpers/useOfferBatchTracking/useOfferBatchTracking'
import { OfferContentProps } from 'features/offer/types'
Expand All @@ -18,11 +19,10 @@ export const OfferContent: FunctionComponent<OfferContentProps> = ({
subcategory,
}) => {
const { navigate } = useNavigation<UseNavigationType>()
const { trackEventHasSeenOfferOnce } = useOfferBatchTracking(subcategory.id)

const handlePress = (defaultIndex = 0) => {
navigate('OfferPreview', { id: offer.id, defaultIndex })
}
const { trackEventHasSeenOfferOnce } = useOfferBatchTracking(subcategory.id)

const footer = useMemo(
() => (
Expand All @@ -36,15 +36,17 @@ export const OfferContent: FunctionComponent<OfferContentProps> = ({
)

return (
<OfferContentBase
offer={offer}
searchGroupList={searchGroupList}
contentContainerStyle={CONTENT_CONTAINER_STYLE}
onOfferPreviewPress={handlePress}
footer={footer}
BodyWrapper={BodyWrapper}
subcategory={subcategory}
/>
<OfferCTAProvider>
<OfferContentBase
offer={offer}
searchGroupList={searchGroupList}
contentContainerStyle={CONTENT_CONTAINER_STYLE}
onOfferPreviewPress={handlePress}
BodyWrapper={BodyWrapper}
footer={footer}
subcategory={subcategory}
/>
</OfferCTAProvider>
)
}

Expand Down
35 changes: 19 additions & 16 deletions src/features/offer/components/OfferContent/OfferContent.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import styled from 'styled-components/native'

import { OfferImageResponse } from 'api/gen'
import { OfferContentBase } from 'features/offer/components/OfferContent/OfferContentBase'
import { OfferCTAProvider } from 'features/offer/components/OfferContent/OfferCTAProvider'
import { OfferCTAButton } from 'features/offer/components/OfferCTAButton/OfferCTAButton'
import { useOfferBatchTracking } from 'features/offer/helpers/useOfferBatchTracking/useOfferBatchTracking'
import { OfferContentProps } from 'features/offer/types'
Expand Down Expand Up @@ -53,22 +54,24 @@ export const OfferContent: FunctionComponent<OfferContentProps> = ({
)

return (
<React.Fragment>
<ImagesCarouselModal
hideModal={hideModal}
isVisible={visible}
imagesURL={offerImages}
defaultIndex={carouselDefaultIndex}
/>
<StyledOfferContentBase
offer={offer}
searchGroupList={searchGroupList}
subcategory={subcategory}
onOfferPreviewPress={handlePress}
BodyWrapper={BodyWrapper}
footer={footer}
/>
</React.Fragment>
<OfferCTAProvider>
<React.Fragment>
<ImagesCarouselModal
hideModal={hideModal}
isVisible={visible}
imagesURL={offerImages}
defaultIndex={carouselDefaultIndex}
/>
<StyledOfferContentBase
offer={offer}
searchGroupList={searchGroupList}
subcategory={subcategory}
onOfferPreviewPress={handlePress}
BodyWrapper={BodyWrapper}
footer={footer}
/>
</React.Fragment>
</OfferCTAProvider>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import styled from 'styled-components/native'

import { OfferImageResponse, OfferResponseV2 } from 'api/gen'
import { OfferBody } from 'features/offer/components/OfferBody/OfferBody'
import { useOfferCTA } from 'features/offer/components/OfferContent/OfferCTAProvider'
import { OfferHeader } from 'features/offer/components/OfferHeader/OfferHeader'
import { OfferImageContainer } from 'features/offer/components/OfferImageContainer/OfferImageContainer'

Check failure on line 24 in src/features/offer/components/OfferContent/OfferContentBase.tsx

View workflow job for this annotation

GitHub Actions / yarn-linter / yarn_lint

There should be at least one empty line between import groups
import { CineContentCTA } from 'features/offer/components/OfferNewXPCine/CineContentCTA'

Check failure on line 25 in src/features/offer/components/OfferContent/OfferContentBase.tsx

View workflow job for this annotation

GitHub Actions / yarn-linter / yarn_typescript

Cannot find module 'features/offer/components/OfferNewXPCine/CineContentCTA' or its corresponding type declarations.

Check failure on line 25 in src/features/offer/components/OfferContent/OfferContentBase.tsx

View workflow job for this annotation

GitHub Actions / yarn-linter / yarn_lint

There should be at least one empty line between import groups

Check failure on line 25 in src/features/offer/components/OfferContent/OfferContentBase.tsx

View workflow job for this annotation

GitHub Actions / yarn-linter / yarn_lint

`features/offer/components/OfferNewXPCine/CineContentCTA` import should occur before import of `react`

Check failure on line 25 in src/features/offer/components/OfferContent/OfferContentBase.tsx

View workflow job for this annotation

GitHub Actions / yarn-linter / yarn_lint

Unable to resolve path to module 'features/offer/components/OfferNewXPCine/CineContentCTA'
import { OfferPlaylistList } from 'features/offer/components/OfferPlaylistList/OfferPlaylistList'
import { OfferWebMetaHeader } from 'features/offer/components/OfferWebMetaHeader'
import { useOfferBatchTracking } from 'features/offer/helpers/useOfferBatchTracking/useOfferBatchTracking'
Expand Down Expand Up @@ -59,6 +61,7 @@ export const OfferContentBase: FunctionComponent<OfferContentBaseProps> = ({
} = useOfferPlaylist({ offer, offerSearchGroup: subcategory.searchGroupName, searchGroupList })
const scrollViewRef = useRef<ScrollView>(null)
const scrollYRef = useRef<number>(0)
const { isButtonVisible } = useOfferCTA()

const logConsultWholeOffer = useFunctionOnce(() => {
analytics.logConsultWholeOffer(offer.id)
Expand Down Expand Up @@ -120,9 +123,9 @@ export const OfferContentBase: FunctionComponent<OfferContentBaseProps> = ({

return (
<Container>
<OfferWebMetaHeader offer={offer} />
<OfferHeader title={offer.name} headerTransition={headerTransition} offer={offer} />
<AnchorProvider scrollViewRef={scrollViewRef} handleCheckScrollY={handleCheckScrollY}>
<OfferWebMetaHeader offer={offer} />
<OfferHeader title={offer.name} headerTransition={headerTransition} offer={offer} />
<ScrollViewContainer
testID="offerv2-container"
scrollEventThrottle={16}
Expand Down Expand Up @@ -152,8 +155,8 @@ export const OfferContentBase: FunctionComponent<OfferContentBaseProps> = ({
apiRecoParamsOtherCategories={apiRecoParamsOtherCategories}
/>
</ScrollViewContainer>
{isButtonVisible ? <CineContentCTA /> : footer}
</AnchorProvider>
{footer}
</Container>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { ComponentProps } from 'react'
import { navigate } from '__mocks__/@react-navigation/native'
import { OfferResponseV2, SubcategoryIdEnum } from 'api/gen'
import { mockOffer } from 'features/bookOffer/fixtures/offer'
import { OfferCTAProvider } from 'features/offer/components/OfferContent/OfferCTAProvider'
import { OfferPlace, OfferPlaceProps } from 'features/offer/components/OfferPlace/OfferPlace'
import { mockSubcategory } from 'features/offer/fixtures/mockSubcategory'
import { analytics } from 'libs/analytics'
Expand Down Expand Up @@ -633,7 +634,14 @@ const renderOfferPlace = ({
subcategory = mockSubcategory,
isDesktopViewport,
}: RenderOfferPlaceType) =>
render(reactQueryProviderHOC(<OfferPlace offer={offer} subcategory={subcategory} />), {
theme: { isDesktopViewport: isDesktopViewport ?? false },
wrapper: AnchorProvider,
})
render(
reactQueryProviderHOC(
<OfferCTAProvider>
<OfferPlace offer={offer} subcategory={subcategory} />
</OfferCTAProvider>
),
{
theme: { isDesktopViewport: isDesktopViewport ?? false },
wrapper: AnchorProvider,
}
)
Loading

0 comments on commit 35ab359

Please sign in to comment.