Skip to content
Merged
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
15 changes: 0 additions & 15 deletions src/hooks/useDocumentTitle.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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};
4 changes: 0 additions & 4 deletions src/libs/UnreadIndicatorUpdater/updateUnread/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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};
34 changes: 5 additions & 29 deletions src/libs/UnreadIndicatorUpdater/updateUnread/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,28 @@ 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;
Comment thread
aimane-chnaif marked this conversation as resolved.
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', () => {
updateUnread(unreadTotalCount);
});

export default updateUnread;
export {setPageTitle};
3 changes: 0 additions & 3 deletions src/pages/TeachersUnite/SaveTheWorldPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = [
{
Expand Down
2 changes: 0 additions & 2 deletions src/pages/settings/AboutPage/AboutPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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[] = [
Expand Down
2 changes: 0 additions & 2 deletions src/pages/settings/Preferences/PreferencesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -48,7 +47,6 @@ function PreferencesPage() {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {shouldUseNarrowLayout} = useResponsiveLayout();
useDocumentTitle(`${translate('common.settings')} - ${translate('common.preferences')}`);

return (
<ScreenWrapper
Expand Down
3 changes: 0 additions & 3 deletions src/pages/settings/Profile/ProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
import Section from '@components/Section';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useDocumentTitle from '@hooks/useDocumentTitle';
import {useMemoizedLazyAsset, useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
Expand Down Expand Up @@ -71,8 +70,6 @@ function ProfilePage() {
const [vacationDelegate] = useOnyx(ONYXKEYS.NVP_PRIVATE_VACATION_DELEGATE);
const {isActingAsDelegate} = useDelegateNoAccessState();
const {showDelegateNoAccessModal} = useDelegateNoAccessActions();
useDocumentTitle(`${translate('common.settings')} - ${translate('common.profile')}`);

const publicOptions = [
{
description: translate('displayNamePage.headerTitle'),
Expand Down
2 changes: 0 additions & 2 deletions src/pages/settings/Rules/ExpenseRulesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import CustomListHeader from '@components/SelectionListWithModal/CustomListHeade
import TableListItemSkeleton from '@components/Skeletons/TableRowSkeleton';
import Text from '@components/Text';
import useAutoTurnSelectionModeOffWhenHasNoActiveOption from '@hooks/useAutoTurnSelectionModeOffWhenHasNoActiveOption';
import useDocumentTitle from '@hooks/useDocumentTitle';
import {useMemoizedLazyExpensifyIcons, useMemoizedLazyIllustrations} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useMobileSelectionMode from '@hooks/useMobileSelectionMode';
Expand Down Expand Up @@ -55,7 +54,6 @@ function ExpenseRulesPage() {
const [selectedRules, setSelectedRules] = useState<string[]>([]);
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
Expand Down
2 changes: 0 additions & 2 deletions src/pages/settings/Security/SecuritySettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
}, []);
Expand Down
2 changes: 0 additions & 2 deletions src/pages/settings/Troubleshoot/TroubleshootPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<string, unknown>) => {
const dataToShare = ExportOnyxState.maskOnyxState(value, shouldMaskOnyxState);
Expand Down
2 changes: 0 additions & 2 deletions src/pages/settings/Wallet/WalletPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
Loading