Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
domlander committed Jun 28, 2024
1 parent 92f17d1 commit 75ebced
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ type Props = {
* Provides a link to switch to the homepage of the user's preferred edition.
*/
export const EditionSwitcherBanner = ({ pageId, edition }: Props) => {
const [shouldShowBanner] = useEditionSwitcherBanner(pageId, edition);
const [showBanner] = useEditionSwitcherBanner(pageId, edition);

const { data } = useSWR(key, () => apiPromise);
const isBannerClosed = !!data?.hidden;
const suggestedPageId = getEditionFromId(edition).pageId;
const suggestedEdition = getEditionFromId(edition).title.replace(
' edition',
Expand All @@ -93,10 +94,7 @@ export const EditionSwitcherBanner = ({ pageId, edition }: Props) => {
const defaultEdition = getEditionFromPageId(pageId);
const defaultEditionName = defaultEdition?.title.replace(' edition', '');

if (
data?.hidden ??
(!shouldShowBanner || !defaultEditionName || !suggestedPageId)
) {
if (isBannerClosed || !showBanner || !defaultEditionName) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions dotcom-rendering/src/components/HeaderTopBar.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const HeaderTopBar = ({
pageId = '',
}: HeaderTopBarProps) => {
const authStatus = useAuthStatus();
const [shouldShowBanner] = useEditionSwitcherBanner(pageId, editionId);
const [showBanner] = useEditionSwitcherBanner(pageId, editionId);

return (
<div
Expand Down Expand Up @@ -112,7 +112,7 @@ export const HeaderTopBar = ({
<HeaderTopBarEditionDropdown
editionId={editionId}
dataLinkName={dataLinkName}
showActiveEdition={!shouldShowBanner}
showActiveEdition={!showBanner}
/>
</Hide>
</div>
Expand Down
15 changes: 6 additions & 9 deletions dotcom-rendering/src/lib/useUserPreferredEdition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,21 @@ export const useEditionSwitcherBanner = (
userEdition: Edition,
): [boolean] => {
const pageEdition = getEditionFromPageId(pageId)?.editionId;
const isOnDifferentFrontToEdition =
const isOnWrongNetworkFront =
isNetworkFront(pageId) && pageEdition !== userEdition;

const [shouldShowBanner, setShouldShowBanner] = useState(
isOnDifferentFrontToEdition,
);
const [showBanner, setShowBanner] = useState(isOnWrongNetworkFront);

useEffect(() => {
setShouldShowBanner(
isOnDifferentFrontToEdition && !hideBannerThroughUserOverride(),
setShowBanner(
isOnWrongNetworkFront && !hideBannerThroughUserOverride(),
);
}, [isOnDifferentFrontToEdition]);
}, [isOnWrongNetworkFront]);

useEffect(() => {
addOrRemoveCookie();
}, []);

return [shouldShowBanner];
return [showBanner];
};

const key = 'edition-switcher-banner';
Expand Down

0 comments on commit 75ebced

Please sign in to comment.