diff --git a/src/hooks/useDocumentTitle.ts b/src/hooks/useDocumentTitle.ts deleted file mode 100644 index 87db95bfddad..000000000000 --- a/src/hooks/useDocumentTitle.ts +++ /dev/null @@ -1,15 +0,0 @@ -import {useEffect} from 'react'; -import {setPageTitle} from '@libs/UnreadIndicatorUpdater/updateUnread'; - -function useDocumentTitle(title: string) { - useEffect(() => { - setPageTitle(title); - - // Reset to default title when component unmounts - return () => { - setPageTitle(''); - }; - }, [title]); -} - -export default useDocumentTitle; diff --git a/src/libs/UnreadIndicatorUpdater/updateUnread/index.android.ts b/src/libs/UnreadIndicatorUpdater/updateUnread/index.android.ts index 707d2f20d97d..2c79573ef906 100644 --- a/src/libs/UnreadIndicatorUpdater/updateUnread/index.android.ts +++ b/src/libs/UnreadIndicatorUpdater/updateUnread/index.android.ts @@ -3,8 +3,4 @@ import type UpdateUnread from './types'; // Android does not yet implement this const updateUnread: UpdateUnread = () => {}; -// Page title management is not applicable on native platforms -const setPageTitle = () => {}; - export default updateUnread; -export {setPageTitle}; diff --git a/src/libs/UnreadIndicatorUpdater/updateUnread/index.ios.ts b/src/libs/UnreadIndicatorUpdater/updateUnread/index.ios.ts index 5113b88f5ffa..fcaa1cf57502 100644 --- a/src/libs/UnreadIndicatorUpdater/updateUnread/index.ios.ts +++ b/src/libs/UnreadIndicatorUpdater/updateUnread/index.ios.ts @@ -9,8 +9,4 @@ const updateUnread: UpdateUnread = (totalCount) => { Airship.push.iOS.setBadgeNumber(totalCount); }; -// Page title management is not applicable on native platforms -const setPageTitle = () => {}; - export default updateUnread; -export {setPageTitle}; diff --git a/src/libs/UnreadIndicatorUpdater/updateUnread/index.ts b/src/libs/UnreadIndicatorUpdater/updateUnread/index.ts index 43218d4d880a..8e5f7d971903 100644 --- a/src/libs/UnreadIndicatorUpdater/updateUnread/index.ts +++ b/src/libs/UnreadIndicatorUpdater/updateUnread/index.ts @@ -5,47 +5,24 @@ import CONFIG from '@src/CONFIG'; import type UpdateUnread from './types'; let unreadTotalCount = 0; -let currentPageTitle = ''; - -/** - * Set the current page-specific title (called by useDocumentTitle hook) - * @param title - The page-specific title - */ -function setPageTitle(title: string) { - currentPageTitle = title; - // Immediately update the document title when page title changes - updateDocumentTitle(); -} - /** - * Update the actual document title and favicon + * Set the page title on web */ -function updateDocumentTitle() { - const hasUnread = unreadTotalCount !== 0; +const updateUnread: UpdateUnread = (totalCount) => { + const hasUnread = totalCount !== 0; + unreadTotalCount = totalCount; // This setTimeout is required because due to how react rendering messes with the DOM, the document title can't be modified synchronously, and we must wait until all JS is done // running before setting the title. setTimeout(() => { // There is a Chrome browser bug that causes the title to revert back to the previous when we are navigating back. Setting the title to an empty string // seems to improve this issue. document.title = ''; - - // Use page-specific title if available, otherwise use the default SITE_TITLE - const baseTitle = currentPageTitle || CONFIG.SITE_TITLE; - document.title = hasUnread ? `(${unreadTotalCount}) ${baseTitle}` : baseTitle; - + document.title = hasUnread ? `(${totalCount}) ${CONFIG.SITE_TITLE}` : CONFIG.SITE_TITLE; const favicon = document.getElementById('favicon'); if (favicon instanceof HTMLLinkElement) { favicon.href = hasUnread ? CONFIG.FAVICON.UNREAD : CONFIG.FAVICON.DEFAULT; } }, 0); -} - -/** - * Set the page title on web - */ -const updateUnread: UpdateUnread = (totalCount) => { - unreadTotalCount = totalCount; - updateDocumentTitle(); }; window.addEventListener('popstate', () => { @@ -53,4 +30,3 @@ window.addEventListener('popstate', () => { }); export default updateUnread; -export {setPageTitle}; diff --git a/src/pages/TeachersUnite/SaveTheWorldPage.tsx b/src/pages/TeachersUnite/SaveTheWorldPage.tsx index 65807a216380..ba6c499cca54 100644 --- a/src/pages/TeachersUnite/SaveTheWorldPage.tsx +++ b/src/pages/TeachersUnite/SaveTheWorldPage.tsx @@ -5,7 +5,6 @@ import MenuItemList from '@components/MenuItemList'; import ScreenWrapper from '@components/ScreenWrapper'; import ScrollView from '@components/ScrollView'; import Section from '@components/Section'; -import useDocumentTitle from '@hooks/useDocumentTitle'; import {useMemoizedLazyIllustrations} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; @@ -27,8 +26,6 @@ function SaveTheWorldPage() { const theme = useTheme(); const illustrations = useMemoizedLazyIllustrations(['TeachersUnite']); const saveTheWorldIllustration = useSaveTheWorldSectionIllustration(); - useDocumentTitle(`${translate('common.settings')} - ${translate('sidebarScreen.saveTheWorld')}`); - const menuItems = useMemo(() => { const baseMenuItems = [ { diff --git a/src/pages/settings/AboutPage/AboutPage.tsx b/src/pages/settings/AboutPage/AboutPage.tsx index e4f7fa7c9b8d..1108c8780a5b 100644 --- a/src/pages/settings/AboutPage/AboutPage.tsx +++ b/src/pages/settings/AboutPage/AboutPage.tsx @@ -10,7 +10,6 @@ import ScreenWrapper from '@components/ScreenWrapper'; import ScrollView from '@components/ScrollView'; import Section from '@components/Section'; import Text from '@components/Text'; -import useDocumentTitle from '@hooks/useDocumentTitle'; import {useMemoizedLazyExpensifyIcons, useMemoizedLazyIllustrations} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; @@ -62,7 +61,6 @@ function AboutPage() { const {shouldUseNarrowLayout} = useResponsiveLayout(); const aboutIllustration = useAboutSectionIllustration(); const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID); - useDocumentTitle(`${translate('common.settings')} - ${translate('initialSettingsPage.about')}`); const menuItems = useMemo(() => { const baseMenuItems: MenuItem[] = [ diff --git a/src/pages/settings/Preferences/PreferencesPage.tsx b/src/pages/settings/Preferences/PreferencesPage.tsx index 3c4b73f9da96..222c6ba3919d 100755 --- a/src/pages/settings/Preferences/PreferencesPage.tsx +++ b/src/pages/settings/Preferences/PreferencesPage.tsx @@ -8,7 +8,6 @@ import Section from '@components/Section'; import Switch from '@components/Switch'; import Text from '@components/Text'; import {useCurrencyListActions} from '@hooks/useCurrencyList'; -import useDocumentTitle from '@hooks/useDocumentTitle'; import {useMemoizedLazyIllustrations} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; @@ -48,7 +47,6 @@ function PreferencesPage() { const styles = useThemeStyles(); const {translate} = useLocalize(); const {shouldUseNarrowLayout} = useResponsiveLayout(); - useDocumentTitle(`${translate('common.settings')} - ${translate('common.preferences')}`); return ( ([]); const [deleteConfirmModalVisible, setDeleteConfirmModalVisible] = useState(false); const styles = useThemeStyles(); - useDocumentTitle(`${translate('common.settings')} - ${translate('expenseRulesPage.title')}`); useEffect(() => { // Clear selection when rule is changed as hash is outdated diff --git a/src/pages/settings/Security/SecuritySettingsPage.tsx b/src/pages/settings/Security/SecuritySettingsPage.tsx index bff10b7b8b6d..8e3a70756010 100644 --- a/src/pages/settings/Security/SecuritySettingsPage.tsx +++ b/src/pages/settings/Security/SecuritySettingsPage.tsx @@ -19,7 +19,6 @@ import Section from '@components/Section'; import Text from '@components/Text'; import TextLink from '@components/TextLink'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; -import useDocumentTitle from '@hooks/useDocumentTitle'; import {useMemoizedLazyExpensifyIcons, useMemoizedLazyIllustrations} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; @@ -106,7 +105,6 @@ function SecuritySettingsPage() { const hasDelegators = delegators.length > 0; const hasEverRegisteredForMultifactorAuthentication = account?.multifactorAuthenticationPublicKeyIDs !== CONST.MULTIFACTOR_AUTHENTICATION.PUBLIC_KEYS_AUTHENTICATION_NEVER_REGISTERED; - useDocumentTitle(`${translate('common.settings')} - ${translate('initialSettingsPage.security')}`); const setMenuPosition = useCallback(() => { if (!delegateButtonRef.current) { diff --git a/src/pages/settings/Subscription/SubscriptionSettingsPage.tsx b/src/pages/settings/Subscription/SubscriptionSettingsPage.tsx index ec683858d1fd..17001bc257e3 100644 --- a/src/pages/settings/Subscription/SubscriptionSettingsPage.tsx +++ b/src/pages/settings/Subscription/SubscriptionSettingsPage.tsx @@ -4,7 +4,6 @@ import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; import ScrollView from '@components/ScrollView'; -import useDocumentTitle from '@hooks/useDocumentTitle'; import {useMemoizedLazyIllustrations} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; @@ -29,8 +28,6 @@ function SubscriptionSettingsPage({route}: SubscriptionSettingsPageProps) { const styles = useThemeStyles(); const subscriptionPlan = useSubscriptionPlan(); const illustrations = useMemoizedLazyIllustrations(['CreditCardsNew']); - useDocumentTitle(`${translate('common.settings')} - ${translate('workspace.common.subscription')}`); - useEffect(() => { openSubscriptionPage(); }, []); diff --git a/src/pages/settings/Troubleshoot/TroubleshootPage.tsx b/src/pages/settings/Troubleshoot/TroubleshootPage.tsx index d8f6e9b5a24e..d86125f347e9 100644 --- a/src/pages/settings/Troubleshoot/TroubleshootPage.tsx +++ b/src/pages/settings/Troubleshoot/TroubleshootPage.tsx @@ -16,7 +16,6 @@ import SentryDebugToolMenu from '@components/SentryDebugToolMenu'; import Switch from '@components/Switch'; import TestToolMenu from '@components/TestToolMenu'; import TestToolRow from '@components/TestToolRow'; -import useDocumentTitle from '@hooks/useDocumentTitle'; import useEnvironment from '@hooks/useEnvironment'; import {useMemoizedLazyExpensifyIcons, useMemoizedLazyIllustrations} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; @@ -64,7 +63,6 @@ function TroubleshootPage() { const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT); const shouldOpenSurveyReasonPage = tryNewDot?.classicRedirect?.dismissed === false; const {setShouldResetSearchQuery} = useSearchActionsContext(); - useDocumentTitle(`${translate('common.settings')} - ${translate('initialSettingsPage.aboutPage.troubleshoot')}`); const exportOnyxState = useCallback(() => { ExportOnyxState.readFromOnyxDatabase().then((value: Record) => { const dataToShare = ExportOnyxState.maskOnyxState(value, shouldMaskOnyxState); diff --git a/src/pages/settings/Wallet/WalletPage/index.tsx b/src/pages/settings/Wallet/WalletPage/index.tsx index a6f83b09c40c..968e3bcca995 100644 --- a/src/pages/settings/Wallet/WalletPage/index.tsx +++ b/src/pages/settings/Wallet/WalletPage/index.tsx @@ -22,7 +22,6 @@ import Section from '@components/Section'; import Text from '@components/Text'; import useConfirmModal from '@hooks/useConfirmModal'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; -import useDocumentTitle from '@hooks/useDocumentTitle'; import {useMemoizedLazyExpensifyIcons, useMemoizedLazyIllustrations} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; @@ -107,7 +106,6 @@ function WalletPage() { const isPendingOnfidoResult = userWallet?.isPendingOnfidoResult ?? false; const hasFailedOnfido = userWallet?.hasFailedOnfido ?? false; const hasEligibleActiveAdmin = hasEligibleActiveAdminFromWorkspaces(allPolicies, currentUserLogin, paymentMethod?.selectedPaymentMethod?.bankAccountID?.toString()); - useDocumentTitle(`${translate('common.settings')} - ${translate('common.wallet')}`); const updateShouldShowLoadingSpinner = useCallback(() => { // In order to prevent a loop, only update state of the spinner if there is a change