Skip to content

Commit

Permalink
refactor(routes): convert to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
danny-avila committed Aug 18, 2023
1 parent d612cfc commit 8b4d3c2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
18 changes: 10 additions & 8 deletions client/src/routes/Chat.jsx → client/src/routes/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useState, useEffect } from 'react';
import { useAuthContext } from '~/hooks/AuthContext';
import { useAuthContext } from '~/hooks';
import { useNavigate, useParams } from 'react-router-dom';
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';

import Landing from '../components/ui/Landing';
import Messages from '../components/Messages';
import TextChat from '../components/Input/TextChat';
import Landing from '~/components/ui/Landing';
import Messages from '~/components/Messages';
import TextChat from '~/components/Input/TextChat';

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

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

useEffect(() => {
let timeout = setTimeout(() => {
const timeout = setTimeout(() => {
if (!isAuthenticated) {
navigate('/login', { replace: true });
}
Expand Down Expand Up @@ -97,11 +97,12 @@ export default function Chat() {
}
}
document.title = conversation?.title || config?.appTitle || 'Chat';
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [conversation, conversationId, config]);

useEffect(() => {
if (messagesTree === null && conversation?.conversationId) {
messagesQuery.refetch(conversation?.conversationId);
messagesQuery.refetch({ queryKey: [conversation?.conversationId] });
}
}, [conversation?.conversationId, messagesQuery, messagesTree]);

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

if (!isAuthenticated) {
Expand Down
5 changes: 3 additions & 2 deletions client/src/routes/Search.jsx → client/src/routes/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React, { useEffect } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { useRecoilState, useRecoilValue } from 'recoil';

import Messages from '../components/Messages';
import TextChat from '../components/Input/TextChat';
import Messages from '~/components/Messages';
import TextChat from '~/components/Input/TextChat';

import store from '~/store';

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

// if not a search
Expand Down
11 changes: 8 additions & 3 deletions client/src/routes/index.jsx → client/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import { createBrowserRouter, Navigate, Outlet } from 'react-router-dom';
import Root from './Root';
import Chat from './Chat';
import Search from './Search';
import { Login, Registration, RequestPasswordReset, ResetPassword } from '../components/Auth';
import { AuthContextProvider } from '../hooks/AuthContext';
import ApiErrorWatcher from '../components/Auth/ApiErrorWatcher';
import {
Login,
Registration,
RequestPasswordReset,
ResetPassword,
ApiErrorWatcher,
} from '~/components/Auth';
import { AuthContextProvider } from '~/hooks/AuthContext';

const AuthLayout = () => (
<AuthContextProvider>
Expand Down

0 comments on commit 8b4d3c2

Please sign in to comment.