/*
 * SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <hello@stalw.art>
 *
 * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
 */

import { useEffect } from 'react';

const APP_NAME = 'Stalwart';

// Keeps the tab title in sync with the current page instead of the static
// index.html title; falls back to the bare app name when no page title is given.
export function useDocumentTitle(title?: string | null) {
  useEffect(() => {
    document.title = title ? `${APP_NAME} | ${title}` : APP_NAME;
  }, [title]);
}
