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

add touch start and youch end events for key events carousel #12836

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions dotcom-rendering/.storybook/mocks/bridgetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ export const getDiscussionClient: BridgetApi<'getDiscussionClient'> = () => ({
recommend: async () => discussionErrorResponse,
});

export const getInteractionClient: BridgetApi<
'getInteractionClient'
> = () => ({});

export const ensure_all_exports_are_present = {
getUserClient,
getAcquisitionsClient,
Expand All @@ -100,6 +104,7 @@ export const ensure_all_exports_are_present = {
getNewslettersClient,
getDiscussionClient,
getTagClient,
getInteractionClient,
} satisfies {
[Method in keyof BridgeModule]: BridgetApi<Method>;
};
2 changes: 1 addition & 1 deletion dotcom-rendering/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@emotion/server": "11.11.0",
"@guardian/ab-core": "8.0.0",
"@guardian/braze-components": "21.0.0",
"@guardian/bridget": "8.0.0",
"@guardian/bridget": "8.1.0",
"@guardian/browserslist-config": "6.1.0",
"@guardian/cdk": "50.13.0",
"@guardian/commercial": "23.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
SvgChevronRightSingle,
} from '@guardian/source/react-components';
import { useRef } from 'react';
import { getInteractionClient } from '../lib/bridgetApi';
import { palette } from '../palette';
import type { RenderingTarget } from '../types/renderingTarget';
import { KeyEventCard } from './KeyEventCard';
Expand Down Expand Up @@ -113,13 +114,23 @@ export const KeyEventsCarousel = ({
}: Props) => {
const carousel = useRef<HTMLDivElement | null>(null);
const cardWidth = 200;
const isApps = renderingTarget === 'Apps';

const goPrevious = () => {
if (carousel.current) carousel.current.scrollLeft -= cardWidth;
};
const goNext = () => {
if (carousel.current) carousel.current.scrollLeft += cardWidth;
};

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

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

const filteredKeyEvents = keyEvents.filter(isValidKeyEvent);
const carouselLength = filteredKeyEvents.length;
const shortCarousel = carouselLength <= 4;
Expand All @@ -131,6 +142,8 @@ export const KeyEventsCarousel = ({
<div css={titleStyles}>Key events</div>
</Hide>
<div
onTouchStart={isApps ? onTouchStart : undefined}
onTouchEnd={isApps ? onTouchEnd : undefined}
ref={carousel}
id="key-events-carousel"
css={[carouselStyles, shortCarousel && leftMarginStyles]}
Expand Down
13 changes: 13 additions & 0 deletions dotcom-rendering/src/lib/bridgetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as Commercial from '@guardian/bridget/Commercial';
import * as Discussion from '@guardian/bridget/Discussion';
import * as Environment from '@guardian/bridget/Environment';
import * as Gallery from '@guardian/bridget/Gallery';
import * as Interaction from '@guardian/bridget/Interaction';
import * as Metrics from '@guardian/bridget/Metrics';
import * as Navigation from '@guardian/bridget/Navigation';
import * as Newsletters from '@guardian/bridget/Newsletters';
Expand Down Expand Up @@ -165,3 +166,15 @@ export const getDiscussionClient = (): Discussion.Client<void> => {
}
return discussionClient;
};

let interactionClient: Interaction.Client<void> | undefined = undefined;
export const getInteractionClient = (): Interaction.Client<void> => {
if (!interactionClient) {
interactionClient = createAppClient<Interaction.Client<void>>(
Interaction.Client,
'buffered',
'compact',
);
}
return interactionClient;
};
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading