Skip to content

Commit

Permalink
add touch events for carousel for apps rendering target
Browse files Browse the repository at this point in the history
  • Loading branch information
marjisound committed Dec 13, 2024
1 parent b7c31f6 commit 1132cab
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 4 deletions.
16 changes: 16 additions & 0 deletions dotcom-rendering/src/components/Carousel.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import { ContainerOverrides } from './ContainerOverrides';
import { FormatBoundary } from './FormatBoundary';
import { Hide } from './Hide';
import { LeftColumn } from './LeftColumn';
import { getInteractionClient } from '../lib/bridgetApi';

Check failure on line 35 in dotcom-rendering/src/components/Carousel.importable.tsx

View workflow job for this annotation

GitHub Actions / lint / check

`../lib/bridgetApi` import should occur before import of `../lib/formatAttrString`
import { RenderingTarget } from 'src/types/renderingTarget';

Check failure on line 36 in dotcom-rendering/src/components/Carousel.importable.tsx

View workflow job for this annotation

GitHub Actions / lint / check

'src/types/renderingTarget' import is restricted from being used by a pattern. Paths starting with “src/” are forbidden. Please use a relative path instead

Check failure on line 36 in dotcom-rendering/src/components/Carousel.importable.tsx

View workflow job for this annotation

GitHub Actions / lint / check

All imports in the declaration are only used as types. Use `import type`

Check failure on line 36 in dotcom-rendering/src/components/Carousel.importable.tsx

View workflow job for this annotation

GitHub Actions / lint / check

`src/types/renderingTarget` import should occur before import of `../lib/articleFormat`

type Props = {
heading: string;
Expand All @@ -42,6 +44,7 @@ type Props = {
leftColSize: LeftColSize;
discussionApiUrl: string;
absoluteServerTimes: boolean;
renderingTarget: RenderingTarget;
};

type ArticleProps = Props & {
Expand Down Expand Up @@ -792,6 +795,7 @@ export const Carousel = ({
discussionApiUrl,
isOnwardContent = true,
absoluteServerTimes,
renderingTarget,
...props
}: ArticleProps | FrontProps) => {
const carouselRef = useRef<HTMLUListElement>(null);
Expand All @@ -800,6 +804,8 @@ export const Carousel = ({
const [maxIndex, setMaxIndex] = useState(0);
const isHorizontalScrollingSupported = useIsHorizontalScrollingSupported();

const isApps = renderingTarget === 'Apps';

const arrowName = 'carousel-small-arrow';

const isCuratedContent = onwardsSource === 'curated-content';
Expand Down Expand Up @@ -907,6 +913,14 @@ export const Carousel = ({
// when index changes and compare it against the prior maxIndex only.
useEffect(() => setMaxIndex((m) => Math.max(index, m)), [index]);

const onTouchStart = async () => {
await getInteractionClient().disableArticleSwipe(true);
};

const onTouchEnd = async () => {
await getInteractionClient().disableArticleSwipe(false);
};

if (!isHorizontalScrollingSupported) {
return null;
}
Expand Down Expand Up @@ -974,6 +988,8 @@ export const Carousel = ({
ref={carouselRef}
data-component={`carousel-small | maxIndex-${maxIndex}`}
data-heatphan-type="carousel"
onTouchStart={isApps ? onTouchStart : undefined}
onTouchEnd={isApps ? onTouchEnd : undefined}
>
{trails.map((trail, i) => {
const {
Expand Down
7 changes: 7 additions & 0 deletions dotcom-rendering/src/components/Carousel.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export const Headlines: StoryObj = ({ format }: StoryProps) => {
leftColSize="compact"
discussionApiUrl={discussionApiUrl}
absoluteServerTimes={true}
renderingTarget="Web"
/>
</Section>
);
Expand All @@ -295,6 +296,7 @@ export const SingleItemCarousel = () => {
leftColSize="compact"
discussionApiUrl={discussionApiUrl}
absoluteServerTimes={true}
renderingTarget="Web"
/>
</Section>
);
Expand Down Expand Up @@ -349,6 +351,7 @@ export const SingleOpinionCarousel = () => {
leftColSize="compact"
discussionApiUrl={discussionApiUrl}
absoluteServerTimes={true}
renderingTarget="Web"
/>
</Section>
);
Expand Down Expand Up @@ -379,6 +382,7 @@ export const Immersive = () => {
leftColSize="compact"
discussionApiUrl={discussionApiUrl}
absoluteServerTimes={true}
renderingTarget="Web"
/>
</Section>
</>
Expand Down Expand Up @@ -424,6 +428,7 @@ export const SpecialReportAlt = () => {
leftColSize="compact"
discussionApiUrl={discussionApiUrl}
absoluteServerTimes={true}
renderingTarget="Web"
/>
</Section>
);
Expand Down Expand Up @@ -639,6 +644,7 @@ export const AllCards = () => {
discussionApiUrl={discussionApiUrl}
format={defaultFormat}
absoluteServerTimes={true}
renderingTarget="Web"
/>
</Section>
);
Expand All @@ -663,6 +669,7 @@ export const FrontCarousel = () => (
discussionApiUrl={discussionApiUrl}
palette="PodcastPalette"
absoluteServerTimes={true}
renderingTarget="Web"
/>
</Section>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { OnwardsSource } from '../types/onwards';
import type { FETrailType, TrailType } from '../types/trails';
import { Carousel } from './Carousel.importable';
import { Placeholder } from './Placeholder';
import { RenderingTarget } from 'src/types/renderingTarget';

Check failure on line 12 in dotcom-rendering/src/components/FetchOnwardsData.importable.tsx

View workflow job for this annotation

GitHub Actions / lint / check

'src/types/renderingTarget' import is restricted from being used by a pattern. Paths starting with “src/” are forbidden. Please use a relative path instead

Check failure on line 12 in dotcom-rendering/src/components/FetchOnwardsData.importable.tsx

View workflow job for this annotation

GitHub Actions / lint / check

All imports in the declaration are only used as types. Use `import type`

Check failure on line 12 in dotcom-rendering/src/components/FetchOnwardsData.importable.tsx

View workflow job for this annotation

GitHub Actions / lint / check

`src/types/renderingTarget` import should occur before import of `../lib/articleFormat`

type Props = {
url: string;
Expand All @@ -17,6 +18,7 @@ type Props = {
format: ArticleFormat;
discussionApiUrl: string;
absoluteServerTimes: boolean;
renderingTarget: RenderingTarget;
};

type OnwardsResponse = {
Expand All @@ -37,6 +39,7 @@ export const FetchOnwardsData = ({
format,
discussionApiUrl,
absoluteServerTimes,
renderingTarget,
}: Props) => {
const { data, error } = useApi<OnwardsResponse>(url);

Expand Down Expand Up @@ -85,6 +88,7 @@ export const FetchOnwardsData = ({
}
discussionApiUrl={discussionApiUrl}
absoluteServerTimes={absoluteServerTimes}
renderingTarget={renderingTarget}
/>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions dotcom-rendering/src/components/Island.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ describe('Island: server-side rendering', () => {
shortUrlId=""
discussionApiUrl=""
absoluteServerTimes={true}
renderingTarget="Web"
/>
</WithConfig>,
),
Expand Down
5 changes: 5 additions & 0 deletions dotcom-rendering/src/components/OnwardsUpper.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { TagType } from '../types/tag';
import { BigSixOnwardsContent } from './BigSixOnwardsContent';
import { FetchOnwardsData } from './FetchOnwardsData.importable';
import { Section } from './Section';
import { RenderingTarget } from 'src/types/renderingTarget';

Check failure on line 17 in dotcom-rendering/src/components/OnwardsUpper.importable.tsx

View workflow job for this annotation

GitHub Actions / lint / check

'src/types/renderingTarget' import is restricted from being used by a pattern. Paths starting with “src/” are forbidden. Please use a relative path instead

Check failure on line 17 in dotcom-rendering/src/components/OnwardsUpper.importable.tsx

View workflow job for this annotation

GitHub Actions / lint / check

All imports in the declaration are only used as types. Use `import type`

Check failure on line 17 in dotcom-rendering/src/components/OnwardsUpper.importable.tsx

View workflow job for this annotation

GitHub Actions / lint / check

`src/types/renderingTarget` import should occur before import of `../lib/articleFormat`

type PillarForContainer =
| 'headlines'
Expand Down Expand Up @@ -181,6 +182,7 @@ type Props = {
shortUrlId: string;
discussionApiUrl: string;
absoluteServerTimes: boolean;
renderingTarget: RenderingTarget;
};

/**
Expand Down Expand Up @@ -215,6 +217,7 @@ export const OnwardsUpper = ({
shortUrlId,
discussionApiUrl,
absoluteServerTimes,
renderingTarget,
}: Props) => {
const abTestAPI = useAB()?.api;
const isInOnwardsAbTestVariant = abTestAPI?.isUserInVariant(
Expand Down Expand Up @@ -329,6 +332,7 @@ export const OnwardsUpper = ({
format={format}
discussionApiUrl={discussionApiUrl}
absoluteServerTimes={absoluteServerTimes}
renderingTarget={renderingTarget}
/>
</Section>
)}
Expand All @@ -344,6 +348,7 @@ export const OnwardsUpper = ({
format={format}
discussionApiUrl={discussionApiUrl}
absoluteServerTimes={absoluteServerTimes}
renderingTarget={renderingTarget}
/>
</Section>
)}
Expand Down
7 changes: 6 additions & 1 deletion dotcom-rendering/src/layouts/AudioLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import type { NavType } from '../model/extract-nav';
import { palette as themePalette } from '../palette';
import type { ArticleDeprecated } from '../types/article';
import { BannerWrapper, Stuck } from './lib/stickiness';
import { RenderingTarget } from '../types/renderingTarget';

const AudioGrid = ({ children }: { children: React.ReactNode }) => (
<div
Expand Down Expand Up @@ -147,14 +148,16 @@ const usCardStyles = css`
interface Props {
article: ArticleDeprecated;
format: ArticleFormat;
renderingTarget: RenderingTarget;
}

interface WebProps extends Props {
NAV: NavType;
renderingTarget: 'Web';
}

export const AudioLayout = (props: WebProps) => {
const { article, format } = props;
const { article, format, renderingTarget } = props;
const audioData = getAudioData(article.mainMediaElements);

const {
Expand Down Expand Up @@ -552,6 +555,7 @@ export const AudioLayout = (props: WebProps) => {
article.config.discussionApiUrl
}
absoluteServerTimes={absoluteServerTimes}
renderingTarget={renderingTarget}
/>
</Island>
</Section>
Expand All @@ -575,6 +579,7 @@ export const AudioLayout = (props: WebProps) => {
shortUrlId={article.config.shortUrlId}
discussionApiUrl={article.config.discussionApiUrl}
absoluteServerTimes={absoluteServerTimes}
renderingTarget={renderingTarget}
/>
</Island>
{showComments && (
Expand Down
2 changes: 2 additions & 0 deletions dotcom-rendering/src/layouts/CommentLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ export const CommentLayout = (props: WebProps | AppsProps) => {
article.config.discussionApiUrl
}
absoluteServerTimes={absoluteServerTimes}
renderingTarget={renderingTarget}
/>
</Island>
</Section>
Expand All @@ -821,6 +822,7 @@ export const CommentLayout = (props: WebProps | AppsProps) => {
shortUrlId={article.config.shortUrlId}
discussionApiUrl={article.config.discussionApiUrl}
absoluteServerTimes={absoluteServerTimes}
renderingTarget={renderingTarget}
/>
</Island>

Expand Down
2 changes: 2 additions & 0 deletions dotcom-rendering/src/layouts/DecideLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ const DecideLayoutWeb = ({
article={article}
NAV={NAV}
format={format}
renderingTarget={renderingTarget}
/>
);
case ArticleDesign.Audio:
Expand All @@ -271,6 +272,7 @@ const DecideLayoutWeb = ({
article={article}
format={format}
NAV={NAV}
renderingTarget={renderingTarget}
/>
);
default:
Expand Down
4 changes: 4 additions & 0 deletions dotcom-rendering/src/layouts/FrontLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import type {
} from '../types/front';
import { pageSkinContainer } from './lib/pageSkin';
import { BannerWrapper, Stuck } from './lib/stickiness';
import { useConfig } from '../components/ConfigContext';

interface Props {
front: DCRFrontType;
Expand Down Expand Up @@ -135,6 +136,8 @@ export const FrontLayout = ({ front, NAV }: Props) => {
editionId,
} = front;

const { renderingTarget } = useConfig();

const renderAds = canRenderAds(front);

const hasPageSkin = renderAds && hasPageSkinConfig;
Expand Down Expand Up @@ -676,6 +679,7 @@ export const FrontLayout = ({ front, NAV }: Props) => {
absoluteServerTimes={
absoluteServerTimes
}
renderingTarget={renderingTarget}
/>
</Island>
</Section>
Expand Down
2 changes: 2 additions & 0 deletions dotcom-rendering/src/layouts/ImmersiveLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ export const ImmersiveLayout = (props: WebProps | AppProps) => {
article.config.discussionApiUrl
}
absoluteServerTimes={absoluteServerTimes}
renderingTarget={renderingTarget}
/>
</Island>
</Section>
Expand All @@ -889,6 +890,7 @@ export const ImmersiveLayout = (props: WebProps | AppProps) => {
shortUrlId={article.config.shortUrlId}
discussionApiUrl={article.config.discussionApiUrl}
absoluteServerTimes={absoluteServerTimes}
renderingTarget={renderingTarget}
/>
</Island>

Expand Down
2 changes: 2 additions & 0 deletions dotcom-rendering/src/layouts/InteractiveLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ export const InteractiveLayout = (props: WebProps | AppsProps) => {
article.config.discussionApiUrl
}
absoluteServerTimes={absoluteServerTimes}
renderingTarget={renderingTarget}
/>
</Island>
</Section>
Expand All @@ -670,6 +671,7 @@ export const InteractiveLayout = (props: WebProps | AppsProps) => {
shortUrlId={article.config.shortUrlId}
discussionApiUrl={article.config.discussionApiUrl}
absoluteServerTimes={absoluteServerTimes}
renderingTarget={renderingTarget}
/>
</Island>

Expand Down
2 changes: 2 additions & 0 deletions dotcom-rendering/src/layouts/LiveLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ export const LiveLayout = (props: WebProps | AppsProps) => {
article.config.discussionApiUrl
}
absoluteServerTimes={absoluteServerTimes}
renderingTarget={renderingTarget}
/>
</Island>
</Section>
Expand All @@ -998,6 +999,7 @@ export const LiveLayout = (props: WebProps | AppsProps) => {
shortUrlId={article.config.shortUrlId}
discussionApiUrl={article.config.discussionApiUrl}
absoluteServerTimes={absoluteServerTimes}
renderingTarget={renderingTarget}
/>
</Island>

Expand Down
11 changes: 10 additions & 1 deletion dotcom-rendering/src/layouts/NewsletterSignupLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ import { isValidUrl } from '../lib/isValidUrl';
import type { NavType } from '../model/extract-nav';
import type { ArticleDeprecated } from '../types/article';
import { BannerWrapper, Stuck } from './lib/stickiness';
import { RenderingTarget } from '../types/renderingTarget';

type Props = {
article: ArticleDeprecated;
NAV: NavType;
format: ArticleFormat;
renderingTarget: RenderingTarget;
};

const mainColWrapperStyle = css`
Expand Down Expand Up @@ -183,7 +185,12 @@ const getMainMediaCaptions = (
: undefined,
);

export const NewsletterSignupLayout = ({ article, NAV, format }: Props) => {
export const NewsletterSignupLayout = ({
article,
NAV,
format,
renderingTarget,
}: Props) => {
const {
promotedNewsletter,
config: { host, hasSurveyAd },
Expand Down Expand Up @@ -435,6 +442,7 @@ export const NewsletterSignupLayout = ({ article, NAV, format }: Props) => {
article.config.discussionApiUrl
}
absoluteServerTimes={absoluteServerTimes}
renderingTarget={renderingTarget}
/>
</Island>
</Section>
Expand All @@ -458,6 +466,7 @@ export const NewsletterSignupLayout = ({ article, NAV, format }: Props) => {
shortUrlId={article.config.shortUrlId}
discussionApiUrl={article.config.discussionApiUrl}
absoluteServerTimes={absoluteServerTimes}
renderingTarget={renderingTarget}
/>
</Island>
</main>
Expand Down
Loading

0 comments on commit 1132cab

Please sign in to comment.