Skip to content

Commit

Permalink
[frontend] Fix for title
Browse files Browse the repository at this point in the history
  • Loading branch information
Kedae authored and VerboseCat committed Oct 30, 2024
1 parent f0603a1 commit 19d08d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { ThemeOptions } from '@mui/material/styles/createTheme';
import { UserContext, UserContextType } from '../utils/hooks/useAuth';
import themeDark from './ThemeDark';
import themeLight from './ThemeLight';
import { useDocumentFaviconModifier, useDocumentTitleModifier, useDocumentThemeModifier } from '../utils/hooks/useDocumentModifier';
import { useDocumentFaviconModifier, useDocumentThemeModifier } from '../utils/hooks/useDocumentModifier';
import { AppThemeProvider_settings$data } from './__generated__/AppThemeProvider_settings.graphql';
import useConnectedDocumentModifier from '../utils/hooks/useConnectedDocumentModifier';
import { pascalize } from '../utils/String';

interface AppThemeProviderProps {
children: React.ReactNode;
Expand Down Expand Up @@ -62,8 +64,8 @@ const AppThemeProvider: FunctionComponent<AppThemeProviderProps> = ({
settings,
}) => {
const { me } = useContext<UserContextType>(UserContext);
const platformTitle = settings?.platform_title ?? 'OpenCTI - Cyber Threat Intelligence Platform';
useDocumentTitleModifier(platformTitle);
const { setTitle } = useConnectedDocumentModifier();
setTitle(pascalize(window.location.pathname.split('/').at(-1)));
useDocumentFaviconModifier(settings?.platform_favicon);
// region theming
const defaultTheme = settings?.platform_theme ?? null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import useAuth from './useAuth';
import { useContext } from 'react';
import { UserContext, UserContextType } from './useAuth';

const setDocumentTitle = (title: string) => {
document.title = title;
};

const useConnectedDocumentModifier = () => {
const { settings } = useAuth();
const { settings } = useContext<UserContextType>(UserContext);
const setTitle = (title: string) => {
setDocumentTitle(`${title} | ${settings.platform_title}`);
setDocumentTitle(`${title}${!settings ? '' : ` | ${settings.platform_title}`}`);
};
return { setTitle };
};
Expand Down

0 comments on commit 19d08d1

Please sign in to comment.