Skip to content

Commit 1cf022d

Browse files
committed
PEER-219: Add Page title
Signed-off-by: SeeuSim <[email protected]>
1 parent e88094f commit 1cf022d

File tree

17 files changed

+49
-36
lines changed

17 files changed

+49
-36
lines changed

frontend/src/components/blocks/interview/editor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import { Skeleton } from '@/components/ui/skeleton';
1717
import { getTheme, type IEditorTheme, languages, themeOptions } from '@/lib/editor/extensions';
1818
import { useCollab } from '@/lib/hooks/use-collab';
19-
import { useUser } from '@/stores/auth-store';
19+
import { useAuthedRoute } from '@/stores/auth-store';
2020

2121
import { CompleteDialog } from './room/complete-dialog';
2222
import { OtherUserCompletingDialog } from './room/other-user-completing-dialog';
@@ -32,7 +32,7 @@ type EditorProps = {
3232
};
3333

3434
export const Editor = ({ questionId, room, onAIClick, onPartnerClick }: EditorProps) => {
35-
const { userId } = useUser();
35+
const { userId } = useAuthedRoute();
3636
const { height } = useWindowSize();
3737
const [theme, setTheme] = useState<IEditorTheme>('vscodeDark');
3838
const {

frontend/src/components/blocks/interview/partner-chat.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState } from 'react';
22

33
import { useChat } from '@/lib/hooks/use-chat';
4-
import { useUser } from '@/stores/auth-store';
4+
import { useAuthedRoute } from '@/stores/auth-store';
55

66
import { ChatLayout } from './chat/chat-layout';
77

@@ -12,7 +12,7 @@ interface PartnerChatProps {
1212
}
1313

1414
export const PartnerChat: React.FC<PartnerChatProps> = ({ isOpen, onClose, roomId }) => {
15-
const { userId } = useUser();
15+
const { userId } = useAuthedRoute();
1616
const { messages, sendMessage, connected, error } = useChat({ roomId });
1717
const [isLoading, setIsLoading] = useState(false);
1818

frontend/src/components/blocks/route-guard.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
useNavigate,
1010
} from 'react-router-dom';
1111

12-
import { usePageTitle } from '@/lib/hooks/use-page-title';
1312
import { ROUTES, UNAUTHED_ROUTES } from '@/lib/routes';
1413
import { checkIsAuthed } from '@/services/user-service';
1514
import { AuthStoreProvider } from '@/stores/auth-store';
@@ -48,7 +47,7 @@ export const RouteGuard = () => {
4847
return (
4948
<Suspense fallback={<Loading />}>
5049
<Await resolve={data.payload}>
51-
{({ authedPayload, isAuthedRoute, path }) => {
50+
{({ authedPayload, isAuthedRoute, path: _p }) => {
5251
const [isLoading, setIsLoading] = useState(true);
5352
useEffect(() => {
5453
if (authedPayload.isAuthed !== isAuthedRoute) {
@@ -57,10 +56,12 @@ export const RouteGuard = () => {
5756

5857
setIsLoading(false);
5958
}, [authedPayload]);
60-
usePageTitle(path);
6159
return (
6260
<AuthStoreProvider
63-
value={{ userId: authedPayload.userId ?? '', username: authedPayload.userName ?? '' }}
61+
value={{
62+
userId: authedPayload.userId ?? '',
63+
username: authedPayload.username ?? '',
64+
}}
6465
>
6566
{isLoading ? <Loading /> : <Outlet />}
6667
</AuthStoreProvider>

frontend/src/lib/hooks/use-chat.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useRef, useState } from 'react';
22
import { io, Socket } from 'socket.io-client';
33

44
import { CHAT_SOCKET } from '@/services/api-clients';
5-
import { useUser } from '@/stores/auth-store';
5+
import { useAuthedRoute } from '@/stores/auth-store';
66
import { Message } from '@/types/chat-types';
77

88
const WS_EVENT = {
@@ -24,7 +24,7 @@ interface UseChatProps {
2424
}
2525

2626
export const useChat = ({ roomId }: UseChatProps) => {
27-
const { userId } = useUser();
27+
const { userId } = useAuthedRoute();
2828
const [messages, setMessages] = useState<Message[]>([]);
2929
const [connected, setConnected] = useState(false);
3030
const [error, setError] = useState<string | null>(null);

frontend/src/lib/hooks/use-collab.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as Y from 'yjs';
88

99
import { extensions as baseExtensions, getLanguage } from '@/lib/editor/extensions';
1010
import { COLLAB_WS } from '@/services/api-clients';
11-
import { useUser } from '@/stores/auth-store';
11+
import { useAuthedRoute } from '@/stores/auth-store';
1212
import type { IYjsUserState } from '@/types/collab-types';
1313

1414
// credit: https://github.com/yjs/y-websocket
@@ -29,7 +29,7 @@ const getRandomColor = () => {
2929

3030
// TODO: Test if collab logic works
3131
export const useCollab = (roomId: string) => {
32-
const { userId, username } = useUser();
32+
const { userId, username } = useAuthedRoute();
3333
const editorRef = useRef<ReactCodeMirrorRef>(null);
3434
const [sharedDocRef, setSharedDocRef] = useState<Y.Map<unknown>>();
3535
const [extensions, setExtensions] = useState<Array<Extension>>(baseExtensions);

frontend/src/lib/hooks/use-page-title.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,15 @@ import { useEffect, useRef } from 'react';
22

33
import { getPageTitle } from '@/lib/routes';
44

5-
export const usePageTitle = (path: string) => {
6-
const isDocumentDefined = typeof document !== 'undefined';
7-
const originalTitle = useRef(isDocumentDefined ? document.title : null);
8-
useEffect(() => {
9-
if (!isDocumentDefined) {
10-
return;
11-
}
5+
export const usePageTitle = (path: string, customTitle?: string) => {
6+
const defaultTitle = useRef(document.title);
7+
const title = customTitle ?? getPageTitle(path);
128

13-
if (document.title !== path) {
14-
document.title = getPageTitle(path);
15-
}
9+
useEffect(() => {
10+
document.title = title;
1611

1712
return () => {
18-
if (originalTitle.current) {
19-
document.title = originalTitle.current;
20-
}
13+
document.title = defaultTitle.current;
2114
};
22-
}, []);
15+
}, [title]);
2316
};

frontend/src/lib/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ const TITLES: Record<string, string> = {
6767

6868
export const getPageTitle = (path: string) => {
6969
const title = TITLES[path];
70-
return title ?? 'Peerprep';
70+
return title;
7171
};

frontend/src/routes/forgot-password/main.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { usePageTitle } from '@/lib/hooks';
2+
import { ROUTES } from '@/lib/routes';
13
import { ForgotPasswordForm } from '@/routes/forgot-password';
24

35
export const ForgotPassword = () => {
6+
usePageTitle(ROUTES.FORGOT_PASSWORD);
47
return (
58
<div className='m-auto flex'>
69
<ForgotPasswordForm />

frontend/src/routes/interview/[room]/main.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PartnerChat } from '@/components/blocks/interview/partner-chat';
99
import { QuestionDetails } from '@/components/blocks/questions/details';
1010
import { Card } from '@/components/ui/card';
1111
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
12-
import { useCrumbs } from '@/lib/hooks';
12+
import { useCrumbs, usePageTitle } from '@/lib/hooks';
1313
import { questionDetailsQuery } from '@/lib/queries/question-details';
1414
import { ROUTES } from '@/lib/routes';
1515

@@ -29,6 +29,7 @@ export const loader =
2929
export const InterviewRoom = () => {
3030
const { questionId, roomId } = useLoaderData() as Awaited<ReturnType<ReturnType<typeof loader>>>;
3131
const { crumbs } = useCrumbs();
32+
usePageTitle(ROUTES.INTERVIEW);
3233
const { data: details } = useSuspenseQuery(questionDetailsQuery(questionId));
3334
const questionDetails = useMemo(() => details.question, [details]);
3435
const [isAIChatOpen, setIsAIChatOpen] = useState(false);

frontend/src/routes/login/main.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { observer } from 'mobx-react';
22

3+
import { usePageTitle } from '@/lib/hooks';
4+
import { ROUTES } from '@/lib/routes';
35
import { Hero, LoginForm } from '@/routes/login';
46

57
export const Login = observer(() => {
8+
usePageTitle(ROUTES.LOGIN);
69
return (
710
<div className='flex w-full py-8'>
811
<Hero />

0 commit comments

Comments
 (0)