Skip to content

Commit b8a0020

Browse files
Merge branch 'main' into al-1710-popstate
2 parents 3d3b141 + 7a9b595 commit b8a0020

26 files changed

+11925
-9923
lines changed

dotcom-rendering/scripts/jest/setup.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ const windowGuardian = {
6060
// Stub global Guardian object
6161
// We should never be able to directly set things to the global window object.
6262
// But in this case we want to stub things for testing, so it's ok to ignore this rule
63-
// @ts-expect-error
64-
!isServer && (window.guardian = windowGuardian);
63+
if (!isServer) {
64+
// @ts-expect-error
65+
window.guardian = windowGuardian;
66+
}
6567

6668
// Mock Local Storage
6769
// See: https://github.com/facebook/jest/issues/2098#issuecomment-260733457
@@ -86,10 +88,11 @@ const localStorageMock = (function () {
8688
};
8789
})();
8890

89-
!isServer &&
91+
if (!isServer) {
9092
Object.defineProperty(window, 'localStorage', {
9193
value: localStorageMock,
9294
});
95+
}
9396

9497
/**
9598
* This is to polyfill `TextEncoder` and `TextDecoder`.

dotcom-rendering/src/client/sentryLoader/sentryLoader.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ export const sentryLoader = (): Promise<void> => {
5757
isInBrowserVariantTest,
5858
random: Math.random(),
5959
});
60-
canLoadSentry ? loadSentryOnError() : stubSentry();
60+
if (canLoadSentry) {
61+
loadSentryOnError();
62+
} else {
63+
stubSentry();
64+
}
6165
return Promise.resolve();
6266
};
6367

dotcom-rendering/src/components/Discussion/Comments.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,9 @@ export const Comments = ({
270270
handleFilterChange(newFilterObject);
271271
}
272272

273-
isWeb && dispatchCommentsStateChange();
273+
if (isWeb) {
274+
dispatchCommentsStateChange();
275+
}
274276
};
275277

276278
useEffect(() => {
@@ -302,7 +304,9 @@ export const Comments = ({
302304

303305
const onPageChange = (pageNumber: number) => {
304306
setPage(pageNumber);
305-
isWeb && dispatchCommentsStateChange();
307+
if (isWeb) {
308+
dispatchCommentsStateChange();
309+
}
306310
};
307311

308312
initialiseApi({ additionalHeaders, baseUrl, apiKey, idApiUrl });

dotcom-rendering/src/components/Discussion/TopPicks.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ export const TopPicks = ({
5656
const leftColComments: Array<CommentType | ReplyType> = [];
5757
const rightColComments: Array<CommentType | ReplyType> = [];
5858
for (const [index, comment] of comments.entries()) {
59-
index % 2 === 0
60-
? leftColComments.push(comment)
61-
: rightColComments.push(comment);
59+
if (index % 2 === 0) {
60+
leftColComments.push(comment);
61+
} else {
62+
rightColComments.push(comment);
63+
}
6264
}
6365
return (
6466
<div css={picksWrapper}>

dotcom-rendering/src/components/EditorialButton/EditorialButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ButtonProps as CoreButtonProps } from '@guardian/source/react-comp
22
import { Button as CoreButton } from '@guardian/source/react-components';
33
import { decideBackground, decideBorder, decideFont } from './styles';
44

5-
export interface EditorialButtonProps extends CoreButtonProps {}
5+
export type EditorialButtonProps = CoreButtonProps;
66

77
/**
88
*

dotcom-rendering/src/components/EditorialButton/EditorialLinkButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { LinkButtonProps as CoreLinkButtonProps } from '@guardian/source/re
22
import { LinkButton as CoreLinkButton } from '@guardian/source/react-components';
33
import { decideBackground, decideBorder, decideFont } from './styles';
44

5-
export interface EditorialLinkButtonProps extends CoreLinkButtonProps {}
5+
export type EditorialLinkButtonProps = CoreLinkButtonProps;
66

77
/**
88
*

dotcom-rendering/src/components/FollowWrapper.importable.tsx

Lines changed: 84 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ export const FollowWrapper = ({ id, displayName }: Props) => {
3131
return !blockList.includes(tagId);
3232
};
3333

34-
isBridgetCompatible &&
35-
isMyGuardianEnabled &&
36-
isNotInBlockList(id) &&
34+
if (isBridgetCompatible && isMyGuardianEnabled && isNotInBlockList(id)) {
3735
setShowFollowTagButton(true);
36+
}
3837

3938
useEffect(() => {
4039
const topic = new Topic({
@@ -50,12 +49,12 @@ export const FollowWrapper = ({ id, displayName }: Props) => {
5049
window.guardian.modules.sentry.reportError(
5150
error,
5251
'bridget-getNotificationsClient-isFollowing-error',
53-
),
54-
log(
55-
'dotcom',
56-
'Bridget getNotificationsClient.isFollowing Error:',
57-
error,
58-
);
52+
);
53+
log(
54+
'dotcom',
55+
'Bridget getNotificationsClient.isFollowing Error:',
56+
error,
57+
);
5958
});
6059

6160
void getTagClient()
@@ -65,12 +64,8 @@ export const FollowWrapper = ({ id, displayName }: Props) => {
6564
window.guardian.modules.sentry.reportError(
6665
error,
6766
'bridget-getTagClient-isFollowing-error',
68-
),
69-
log(
70-
'dotcom',
71-
'Bridget getTagClient.isFollowing Error:',
72-
error,
73-
);
67+
);
68+
log('dotcom', 'Bridget getTagClient.isFollowing Error:', error);
7469
});
7570
}, [id, displayName]);
7671

@@ -81,39 +76,41 @@ export const FollowWrapper = ({ id, displayName }: Props) => {
8176
type: 'tag-contributor',
8277
});
8378

84-
isFollowingTag
85-
? void getTagClient()
86-
.unfollow(topic)
87-
.then((success) => {
88-
success && setIsFollowingTag(false);
89-
})
90-
.catch((error) => {
91-
window.guardian.modules.sentry.reportError(
92-
error,
93-
'bridget-getTagClient-unfollow-error',
94-
),
95-
log(
96-
'dotcom',
97-
'Bridget getTagClient.unfollow Error:',
98-
error,
99-
);
100-
})
101-
: void getTagClient()
102-
.follow(topic)
103-
.then((success) => {
104-
success && setIsFollowingTag(true);
105-
})
106-
.catch((error) => {
107-
window.guardian.modules.sentry.reportError(
108-
error,
109-
'bridget-getTagClient-follow-error',
110-
),
111-
log(
112-
'dotcom',
113-
'Bridget getTagClient.follow Error:',
114-
error,
115-
);
116-
});
79+
if (isFollowingTag) {
80+
void getTagClient()
81+
.unfollow(topic)
82+
.then((success) => {
83+
if (success) {
84+
setIsFollowingTag(false);
85+
}
86+
})
87+
.catch((error) => {
88+
window.guardian.modules.sentry.reportError(
89+
error,
90+
'bridget-getTagClient-unfollow-error',
91+
);
92+
log(
93+
'dotcom',
94+
'Bridget getTagClient.unfollow Error:',
95+
error,
96+
);
97+
});
98+
} else {
99+
void getTagClient()
100+
.follow(topic)
101+
.then((success) => {
102+
if (success) {
103+
setIsFollowingTag(true);
104+
}
105+
})
106+
.catch((error) => {
107+
window.guardian.modules.sentry.reportError(
108+
error,
109+
'bridget-getTagClient-follow-error',
110+
);
111+
log('dotcom', 'Bridget getTagClient.follow Error:', error);
112+
});
113+
}
117114
};
118115

119116
const notificationsHandler = () => {
@@ -123,39 +120,45 @@ export const FollowWrapper = ({ id, displayName }: Props) => {
123120
type: 'tag-contributor',
124121
});
125122

126-
isFollowingNotifications
127-
? void getNotificationsClient()
128-
.unfollow(topic)
129-
.then((success) => {
130-
success && setIsFollowingNotifications(false);
131-
})
132-
.catch((error) => {
133-
window.guardian.modules.sentry.reportError(
134-
error,
135-
'briidget-getNotificationsClient-unfollow-error',
136-
),
137-
log(
138-
'dotcom',
139-
'Bridget getNotificationsClient.unfollow Error:',
140-
error,
141-
);
142-
})
143-
: void getNotificationsClient()
144-
.follow(topic)
145-
.then((success) => {
146-
success && setIsFollowingNotifications(true);
147-
})
148-
.catch((error) => {
149-
window.guardian.modules.sentry.reportError(
150-
error,
151-
'bridget-getNotificationsClient-follow-error',
152-
),
153-
log(
154-
'dotcom',
155-
'Bridget getNotificationsClient.follow Error:',
156-
error,
157-
);
158-
});
123+
if (isFollowingNotifications) {
124+
void getNotificationsClient()
125+
.unfollow(topic)
126+
.then((success) => {
127+
if (success) {
128+
setIsFollowingNotifications(false);
129+
}
130+
})
131+
.catch((error) => {
132+
window.guardian.modules.sentry.reportError(
133+
error,
134+
'briidget-getNotificationsClient-unfollow-error',
135+
);
136+
log(
137+
'dotcom',
138+
'Bridget getNotificationsClient.unfollow Error:',
139+
error,
140+
);
141+
});
142+
} else {
143+
void getNotificationsClient()
144+
.follow(topic)
145+
.then((success) => {
146+
if (success) {
147+
setIsFollowingNotifications(true);
148+
}
149+
})
150+
.catch((error) => {
151+
window.guardian.modules.sentry.reportError(
152+
error,
153+
'bridget-getNotificationsClient-follow-error',
154+
);
155+
log(
156+
'dotcom',
157+
'Bridget getNotificationsClient.follow Error:',
158+
error,
159+
);
160+
});
161+
}
159162
};
160163

161164
return (

dotcom-rendering/src/components/InteractiveContentsBlockComponent.importable.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ export const InteractiveContentsBlockComponent = ({
247247
});
248248

249249
for (const item of enhancedSubheadings) {
250-
item.ref && observer.observe(item.ref);
250+
if (item.ref) {
251+
observer.observe(item.ref);
252+
}
251253
}
252254

253255
if (endDocumentElementId) {

dotcom-rendering/src/components/Island.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,45 @@ import { StickyBottomBanner } from './StickyBottomBanner.importable';
4343

4444
const Mock = () => <>🏝️</>;
4545

46+
/* eslint-disable-next-line @typescript-eslint/no-unused-expressions --
47+
* The expression is intentionally never used, the file is just being tested for
48+
* compilation, as mentioned above. */
4649
() => (
4750
<Island priority="critical">
4851
<Mock />
4952
</Island>
5053
);
5154

55+
/* eslint-disable-next-line @typescript-eslint/no-unused-expressions --
56+
* The expression is intentionally never used, the file is just being tested for
57+
* compilation, as mentioned above. */
5258
() => (
5359
<Island priority="critical" defer={{ until: 'visible' }}>
5460
<Mock />
5561
</Island>
5662
);
5763

64+
/* eslint-disable-next-line @typescript-eslint/no-unused-expressions --
65+
* The expression is intentionally never used, the file is just being tested for
66+
* compilation, as mentioned above. */
5867
() => (
5968
<Island priority="critical" defer={{ until: 'idle' }}>
6069
<Mock />
6170
</Island>
6271
);
6372

73+
/* eslint-disable-next-line @typescript-eslint/no-unused-expressions --
74+
* The expression is intentionally never used, the file is just being tested for
75+
* compilation, as mentioned above. */
6476
() => (
6577
<Island priority="feature" defer={{ until: 'interaction' }}>
6678
<Mock />
6779
</Island>
6880
);
6981

82+
/* eslint-disable-next-line @typescript-eslint/no-unused-expressions --
83+
* The expression is intentionally never used; the file is just being tested for
84+
* compilation, as mentioned above. */
7085
() => (
7186
// @ts-expect-error -- non-critical island must be deferred
7287
<Island priority="feature">

dotcom-rendering/src/components/LightboxJavascript.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ const close = async (
252252
});
253253
closeLightbox(lightbox, handleKeydown);
254254
history.back();
255-
previouslyFocused && restoreFocus(previouslyFocused);
255+
if (previouslyFocused) {
256+
restoreFocus(previouslyFocused);
257+
}
256258
};
257259

258260
const toggleInfo = (
@@ -462,7 +464,9 @@ const initialiseLightbox = (lightbox: HTMLElement) => {
462464
// which closes fullscreen mode but not the lightbox, so let's close it
463465
closeLightbox(lightbox, handleKeydown);
464466
history.back();
465-
previouslyFocused && restoreFocus(previouslyFocused);
467+
if (previouslyFocused) {
468+
restoreFocus(previouslyFocused);
469+
}
466470
}
467471
}
468472
});
@@ -484,7 +488,9 @@ const initialiseLightbox = (lightbox: HTMLElement) => {
484488
// There's no img hash so close the lightbox
485489
void exitFullscreen();
486490
closeLightbox(lightbox, handleKeydown);
487-
previouslyFocused && restoreFocus(previouslyFocused);
491+
if (previouslyFocused) {
492+
restoreFocus(previouslyFocused);
493+
}
488494
}
489495
});
490496

0 commit comments

Comments
 (0)