go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/common/components/page_meta/page_meta.tsx (about)

     1  // Copyright 2023 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  import { useEffect } from 'react';
    16  import { Helmet } from 'react-helmet';
    17  
    18  import { UiPage } from '@/common/constants/view';
    19  
    20  import {
    21    useProject,
    22    useSetProject,
    23    useSetSelectedPage,
    24  } from './page_meta_provider';
    25  
    26  interface Props {
    27    title: string;
    28    selectedPage?: UiPage;
    29    project?: string;
    30  }
    31  
    32  /**
    33   * Handles setting the sidebar selected item and title of the page.
    34   */
    35  export const PageMeta = ({ title, selectedPage, project }: Props) => {
    36    const setProject = useSetProject();
    37    const setSelectedPage = useSetSelectedPage();
    38    const currentProject = useProject();
    39  
    40    useEffect(() => {
    41      setSelectedPage(selectedPage);
    42      setProject(project || currentProject);
    43    }, [setSelectedPage, selectedPage, project, setProject, currentProject]);
    44  
    45    return (
    46      <Helmet titleTemplate="%s | LUCI" defaultTitle="LUCI">
    47        {title && <title>{title}</title>}
    48      </Helmet>
    49    );
    50  };