- {/* Messages Container and Participants Container */}
-
-
-
-
-
-
-
-
- {currentContact && currentContact.username?.length >= 4 ? (
-
- ) : null}
-
+ {/*Chat area */}
+
+
+ {/* Messages Container and Participants Container */}
+
+
+
+
+
+
+
+
+ {currentContact && currentContact.username?.length >= 4 ? (
+
+ ) : null}
-
- {/* Right Sidebar - Participants */}
- {currentContact?.type === 'group' && (
-
- )}
+
+ {/* Right Sidebar - Participants */}
+ {currentContact?.type === 'group' && (
+
+ )}
-
+
);
}
diff --git a/client/src/pages/Login.tsx b/client/src/pages/Login.tsx
index b2042db..bf0ee8b 100644
--- a/client/src/pages/Login.tsx
+++ b/client/src/pages/Login.tsx
@@ -4,7 +4,8 @@ import { Link, useNavigate } from 'react-router-dom';
import { useContext, useState } from 'react';
import { AuthContext } from '../utils/AuthProvider.tsx';
import LoadingWheel from '../components/chat/LoadingWheel.tsx';
-import { axiosClient } from '../App.tsx';
+
+import { axiosClient } from '@/utils/axiosClient.ts';
export type Inputs = {
username: string;
diff --git a/client/src/pages/Signup.tsx b/client/src/pages/Signup.tsx
index 694504f..892cd9a 100644
--- a/client/src/pages/Signup.tsx
+++ b/client/src/pages/Signup.tsx
@@ -3,8 +3,8 @@ import { useForm, SubmitHandler } from 'react-hook-form';
import { Link, useNavigate } from 'react-router-dom';
import { useContext, useState } from 'react';
import { AuthContext } from '../utils/AuthProvider.tsx';
-import { axiosClient } from '../App.tsx';
import LoadingWheel from '../components/chat/LoadingWheel.tsx';
+import { axiosClient } from '@/utils/axiosClient.ts';
type Inputs = {
username: string;
diff --git a/client/src/types/types.ts b/client/src/types/types.ts
index 3d3ff83..4ac30fe 100644
--- a/client/src/types/types.ts
+++ b/client/src/types/types.ts
@@ -1,4 +1,4 @@
-import { File } from 'lucide-react';
+import { Dispatch, SetStateAction } from 'react';
export type MeProps = {
isGroupAdmin: boolean;
@@ -26,19 +26,46 @@ export type ContactsProps = {
last_message_time: string;
last_message_sender: string;
};
-export type InputProps = {
- message: string;
- attachments: FileList | null;
-};
-export type MessageFormProps = {
- contact: ContactsProps;
- messages: ChatMessagesProps[];
+
+export type ParticipantsProps = {
+ user_id: string;
+ username: string;
+ isadmin: boolean;
+ isowner: boolean;
};
+
export type FileWithPreviewProps = {
file: File;
preview: string | null;
};
+
export type UsernameType = {
username: string | null;
user_id: string | null;
};
+
+export type ChatContextType = {
+ contactsList: ContactsProps[];
+ currentContact: ContactsProps | null;
+ cursor: number;
+ messages: ChatMessagesProps[];
+ errorMessage: string | null;
+ hasMoreMessages: boolean;
+ me: MeProps;
+ groupOwner: string | undefined;
+
+ setContactsList: Dispatch
>;
+ setCurrentContact: Dispatch>;
+ setCursor: Dispatch>;
+ setMessages: Dispatch>;
+ setErrorMessage: Dispatch>;
+ setHasMoreMessages: Dispatch>;
+ setMe: Dispatch>;
+ setGroupOwner: Dispatch>;
+
+ initializeContact: (newContact: ContactsProps) => Promise;
+ fetchMessages: (conversation_id: string) => Promise;
+ messageHandler: (msg: ChatMessagesProps) => void;
+ updateContactStatus: (contactObj: ContactsProps, read: boolean) => void;
+ fetchPreviousMessages: (contact: string | null) => Promise;
+};
diff --git a/client/src/utils/ProtectedRoutes.tsx b/client/src/utils/ProtectedRoutes.tsx
index af39a3e..e09acfb 100644
--- a/client/src/utils/ProtectedRoutes.tsx
+++ b/client/src/utils/ProtectedRoutes.tsx
@@ -2,8 +2,8 @@ import { Navigate, Outlet } from 'react-router-dom';
import { useContext, useEffect, useState } from 'react';
import { AuthContext } from './AuthProvider.tsx';
import LoadingScreen from '../components/LoadingScreen.tsx';
-import { axiosClient } from '../App.tsx';
import { UsernameType } from '@/types/types.ts';
+import { axiosClient } from '@/utils/axiosClient.ts';
function ProtectedRoutes() {
const { authorized, isLoading } = useContext(AuthContext);
diff --git a/client/src/utils/axiosClient.ts b/client/src/utils/axiosClient.ts
new file mode 100644
index 0000000..d8fbcb3
--- /dev/null
+++ b/client/src/utils/axiosClient.ts
@@ -0,0 +1,5 @@
+import axios from 'axios';
+
+export const axiosClient = axios.create({
+ baseURL: '/',
+});
diff --git a/client/src/utils/useAuth.tsx b/client/src/utils/useAuth.tsx
index a097963..44db8f4 100644
--- a/client/src/utils/useAuth.tsx
+++ b/client/src/utils/useAuth.tsx
@@ -1,6 +1,7 @@
import { useState, useEffect } from 'react';
import Cookies from 'js-cookie';
-import { axiosClient } from '../App.tsx';
+
+import { axiosClient } from '@/utils/axiosClient.ts';
function useAuth() {
const [authorized, setAuthorized] = useState(false);