Skip to content

Refactor LiveblogNotifications#15594

Open
JamieB-gu wants to merge 5 commits intomainfrom
refactor-liveblog-notifications-button
Open

Refactor LiveblogNotifications#15594
JamieB-gu wants to merge 5 commits intomainfrom
refactor-liveblog-notifications-button

Conversation

@JamieB-gu
Copy link
Copy Markdown
Contributor

@JamieB-gu JamieB-gu commented Mar 25, 2026

We want to expand usage of the notifications button to include subscribing to football match events. This refactor makes the button more generic and testable, to facilitate this.

Firstly the component has been renamed to NotificationsToggle, so that it can be reused for both liveblog notifications (new content) and football notifications (match events such as goals). This component contains the logic for user events, calling Bridget, and synchronising UI with the subscription state.

The UI of the button itself is handled in a new, presentational component called ToggleButton, which replaces
FollowNotificationsButton and is more suitable for customisation to the new football design. FollowNotificationsButton will soon be deleted, as its only other usage is in the process of being deprecated in a separate change (#15558).

Wrapping NotificationsToggle is a lightweight island component that dependency-injects the Bridget client. This allows us to use a "live" implementation of this client in production, and a mock implementation in tests and stories. As a result, this change also adds a story containing UI tests that make use of a mock Bridget client.

The type describing the API of the Notifications Bridget client has been simplified to make dependency injection and mocking simpler. A similar type can be rolled out for the other Bridget clients in a future change.

Part of #14905.

We want to expand usage of the notifications button to include
subscribing to football match events. This refactor makes the button
more generic and testable, to facilitate this.

Firstly the component has been renamed to `NotificationsToggle`, so that
it can be reused for both liveblog notifications (new content) and
football notifications (match events such as goals). This component
contains the logic for user events, calling Bridget, and synchronising
UI with the subscription state.

The UI of the button itself is handled in a new, presentational
component called `ToggleButton`, which replaces
`FollowNotificationsButton` and is more suitable for customisation to
the new football design. `FollowNotificationsButton` will soon be
deleted, as its only other usage is in the process of being deprecated
in a separate change.

Wrapping `NotificationsToggle` is a lightweight island component that
dependency-injects the Bridget client. This allows us to use a "live"
implementation of this client in production, and a mock implementation
in tests and stories. As a result, this change also adds a story
containing UI tests that make use of a mock Bridget client.

The type describing the API of the `Notifications` Bridget client has
been simplified to make dependency injection and mocking simpler. A
similar type can be rolled out for the other Bridget clients in a future
change.
@JamieB-gu JamieB-gu requested review from a team and aracho1 March 25, 2026 18:44
@arelra
Copy link
Copy Markdown
Member

arelra commented Mar 25, 2026

.importable.tsx -> .island.tsx

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 25, 2026

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 26, 2026

If you have two component files with similar names, but one includes
`.island`, the "name" attribute in the "gu-island" element doesn't match
the file name (extra characters get added). This means that when the
hydration code attempts to import the island JS, using this name, it
cannot find the file. The fix for now is to give the two components
distinct names.
@JamieB-gu JamieB-gu added run_chromatic Runs chromatic when label is applied maintenance Departmental tracking: maintenance work, not a fix or a feature labels Mar 31, 2026
@JamieB-gu JamieB-gu self-assigned this Mar 31, 2026
@JamieB-gu JamieB-gu marked this pull request as ready for review March 31, 2026 11:03
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Mar 31, 2026
@JamieB-gu JamieB-gu added the run_chromatic Runs chromatic when label is applied label Mar 31, 2026
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Mar 31, 2026
@JamieB-gu JamieB-gu removed this from the Decommission Legacy App Templates milestone Mar 31, 2026
notificationsClient: Props['notificationsClient'],
): [
boolean | undefined,
React.Dispatch<React.SetStateAction<boolean | undefined>>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor non-blocking. Perhaps a project-wide utility type would be useful e.g.

type SetState<T> = React.Dispatch<React.SetStateAction<T>>;

}
};

const handleError =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor non-blocking. A version of this would be another useful library function.

I see a similar somewhat similar function here:

const logAndReportError = (src: string, error: Error) => {
const message = `Autoplay failure for self-hosted video. Source: ${src} could not be played. Error: ${String(
error,
)}`;
if (error instanceof Error) {
window.guardian.modules.sentry.reportError(
new Error(message),
'self-hosted-video',
);
}
log('dotcom', message);
};

Copy link
Copy Markdown
Member

@arelra arelra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Departmental tracking: maintenance work, not a fix or a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants