Skip to content

Commit 8b4d3c2

Browse files
committed
refactor(routes): convert to TS
1 parent d612cfc commit 8b4d3c2

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

client/src/routes/Chat.jsx renamed to client/src/routes/Chat.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useState, useEffect } from 'react';
2-
import { useAuthContext } from '~/hooks/AuthContext';
2+
import { useAuthContext } from '~/hooks';
33
import { useNavigate, useParams } from 'react-router-dom';
44
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
55

6-
import Landing from '../components/ui/Landing';
7-
import Messages from '../components/Messages';
8-
import TextChat from '../components/Input/TextChat';
6+
import Landing from '~/components/ui/Landing';
7+
import Messages from '~/components/Messages';
8+
import TextChat from '~/components/Input/TextChat';
99

1010
import store from '~/store';
1111
import {
@@ -27,12 +27,12 @@ export default function Chat() {
2727
const navigate = useNavigate();
2828

2929
//disabled by default, we only enable it when messagesTree is null
30-
const messagesQuery = useGetMessagesByConvoId(conversationId, { enabled: false });
31-
const getConversationMutation = useGetConversationByIdMutation(conversationId);
30+
const messagesQuery = useGetMessagesByConvoId(conversationId ?? '', { enabled: false });
31+
const getConversationMutation = useGetConversationByIdMutation(conversationId ?? '');
3232
const { data: config } = useGetStartupConfig();
3333

3434
useEffect(() => {
35-
let timeout = setTimeout(() => {
35+
const timeout = setTimeout(() => {
3636
if (!isAuthenticated) {
3737
navigate('/login', { replace: true });
3838
}
@@ -97,11 +97,12 @@ export default function Chat() {
9797
}
9898
}
9999
document.title = conversation?.title || config?.appTitle || 'Chat';
100+
// eslint-disable-next-line react-hooks/exhaustive-deps
100101
}, [conversation, conversationId, config]);
101102

102103
useEffect(() => {
103104
if (messagesTree === null && conversation?.conversationId) {
104-
messagesQuery.refetch(conversation?.conversationId);
105+
messagesQuery.refetch({ queryKey: [conversation?.conversationId] });
105106
}
106107
}, [conversation?.conversationId, messagesQuery, messagesTree]);
107108

@@ -113,6 +114,7 @@ export default function Chat() {
113114
console.error(messagesQuery.error);
114115
setMessages(null);
115116
}
117+
// eslint-disable-next-line react-hooks/exhaustive-deps
116118
}, [messagesQuery.data, messagesQuery.isError, setMessages]);
117119

118120
if (!isAuthenticated) {

client/src/routes/Search.jsx renamed to client/src/routes/Search.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React, { useEffect } from 'react';
22
import { useNavigate, useParams } from 'react-router-dom';
33
import { useRecoilState, useRecoilValue } from 'recoil';
44

5-
import Messages from '../components/Messages';
6-
import TextChat from '../components/Input/TextChat';
5+
import Messages from '~/components/Messages';
6+
import TextChat from '~/components/Input/TextChat';
77

88
import store from '~/store';
99

@@ -34,6 +34,7 @@ export default function Search() {
3434
// conversationId (in url) should always follow conversation?.conversationId, unless conversation is null
3535
navigate(`/chat/${conversation?.conversationId}`);
3636
}
37+
// eslint-disable-next-line react-hooks/exhaustive-deps
3738
}, [conversation, query, searchQuery]);
3839

3940
// if not a search

client/src/routes/index.jsx renamed to client/src/routes/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ import { createBrowserRouter, Navigate, Outlet } from 'react-router-dom';
22
import Root from './Root';
33
import Chat from './Chat';
44
import Search from './Search';
5-
import { Login, Registration, RequestPasswordReset, ResetPassword } from '../components/Auth';
6-
import { AuthContextProvider } from '../hooks/AuthContext';
7-
import ApiErrorWatcher from '../components/Auth/ApiErrorWatcher';
5+
import {
6+
Login,
7+
Registration,
8+
RequestPasswordReset,
9+
ResetPassword,
10+
ApiErrorWatcher,
11+
} from '~/components/Auth';
12+
import { AuthContextProvider } from '~/hooks/AuthContext';
813

914
const AuthLayout = () => (
1015
<AuthContextProvider>

0 commit comments

Comments
 (0)