Skip to content

Commit e295ea4

Browse files
author
Whitzscott (Developer)
committed
feat: Added Helmet
1 parent 3e279f5 commit e295ea4

4 files changed

Lines changed: 89 additions & 33 deletions

File tree

src/App.tsx

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { Utils as utils } from '~/Utility';
1111
import { useUserStore } from '~/store';
1212
import { Box, useTheme } from '@mui/material';
1313
import { BlockedPage } from './routes/Routing';
14+
import { HelmetProvider } from 'react-helmet-async';
15+
import { HelmetWrapper } from '~/HelmetWrapper';
1416

1517
interface UserData {
1618
is_deleted: boolean;
@@ -110,43 +112,47 @@ const AppContent = () => {
110112
if (isBlocked) return <BlockedPage />;
111113

112114
return (
113-
<Box
114-
data-mui-theme={`theme-${currentTheme}`}
115-
aria-label="PyrenzAI"
116-
sx={{
117-
scrollBehavior: 'smooth',
118-
scrollbarWidth: 'thin',
119-
scrollbarColor: 'transparent transparent',
120-
'&::-webkit-scrollbar': {
121-
width: 8,
122-
opacity: 0.2,
123-
transition: 'opacity 0.3s ease',
124-
},
125-
'&:hover::-webkit-scrollbar': {
126-
opacity: 1,
127-
},
128-
'&::-webkit-scrollbar-track': {
129-
background: 'transparent',
130-
},
131-
'&::-webkit-scrollbar-thumb': {
132-
backgroundColor: 'rgba(100, 100, 100, 0.4)',
133-
borderRadius: 10,
134-
border: '2px solid transparent',
135-
backgroundClip: 'content-box',
136-
},
137-
}}
138-
>
139-
<Routes>{AppRoutes}</Routes>
140-
</Box>
115+
<HelmetWrapper>
116+
<Box
117+
data-mui-theme={`theme-${currentTheme}`}
118+
aria-label="PyrenzAI"
119+
sx={{
120+
scrollBehavior: 'smooth',
121+
scrollbarWidth: 'thin',
122+
scrollbarColor: 'transparent transparent',
123+
'&::-webkit-scrollbar': {
124+
width: 8,
125+
opacity: 0.2,
126+
transition: 'opacity 0.3s ease',
127+
},
128+
'&:hover::-webkit-scrollbar': {
129+
opacity: 1,
130+
},
131+
'&::-webkit-scrollbar-track': {
132+
background: 'transparent',
133+
},
134+
'&::-webkit-scrollbar-thumb': {
135+
backgroundColor: 'rgba(100, 100, 100, 0.4)',
136+
borderRadius: 10,
137+
border: '2px solid transparent',
138+
backgroundClip: 'content-box',
139+
},
140+
}}
141+
>
142+
<Routes>{AppRoutes}</Routes>
143+
</Box>
144+
</HelmetWrapper>
141145
);
142146
};
143147

144148
export function App() {
145149
return (
146-
<Router>
147-
<Suspense fallback={<Spinner />}>
148-
<AppContent />
149-
</Suspense>
150-
</Router>
150+
<HelmetProvider>
151+
<Router>
152+
<Suspense fallback={<Spinner />}>
153+
<AppContent />
154+
</Suspense>
155+
</Router>
156+
</HelmetProvider>
151157
);
152158
}

src/HelmetWrapper.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Helmet } from 'react-helmet-async';
2+
import { useLocation, matchPath } from 'react-router-dom';
3+
import { ReactNode } from 'react';
4+
import { routeTitleMap } from '~/meta/pageTitles';
5+
6+
export const HelmetWrapper = ({ children }: { children: ReactNode }) => {
7+
const location = useLocation();
8+
const path = location.pathname;
9+
10+
let title = 'Page';
11+
12+
for (const pattern in routeTitleMap) {
13+
const match = matchPath({ path: pattern, end: true }, path);
14+
if (match) {
15+
title = routeTitleMap[pattern];
16+
break;
17+
}
18+
}
19+
20+
return (
21+
<>
22+
<Helmet>
23+
<title>{title}</title>
24+
</Helmet>
25+
{children}
26+
</>
27+
);
28+
};

src/meta/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './pageTitles'

src/meta/pageTitles.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export const routeTitleMap: Record<string, string> = {
2+
'/': 'Home',
3+
'/Home': 'Home',
4+
'/Policy': 'Policy',
5+
'/Create': 'Create',
6+
'/Create/:char_uuid': 'Edit Character',
7+
'/Subscription': 'Subscription',
8+
'/Archive': 'Archive',
9+
'/Profile': 'Profile',
10+
'/Profile/:creator_uuid': 'Profile',
11+
'/Chat/:chat_uuid': 'Chat',
12+
'/Settings': 'Settings',
13+
'/ContentPolicy': 'Content Policy',
14+
'/docs': 'Docs',
15+
'/docs/:doc_name': 'Docs',
16+
'/Admin': 'Admin',
17+
'/character/:char_uuid': 'Character',
18+
'/Blocked': 'Blocked',
19+
'*': 'Page Not Found',
20+
};
21+

0 commit comments

Comments
 (0)