finito
This commit is contained in:
2
client/.gitignore
vendored
2
client/.gitignore
vendored
@@ -16,7 +16,7 @@ dist-ssr
|
|||||||
# Editor directories and files
|
# Editor directories and files
|
||||||
.vscode/*
|
.vscode/*
|
||||||
!.vscode/extensions.json
|
!.vscode/extensions.json
|
||||||
.idea
|
.idea/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.suo
|
*.suo
|
||||||
*.ntvs*
|
*.ntvs*
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import { useChat } from '@/context/chat/useChat.ts';
|
|||||||
import { AuthContext } from '@/utils/AuthProvider.tsx';
|
import { AuthContext } from '@/utils/AuthProvider.tsx';
|
||||||
import { format, isToday, isYesterday, formatDistanceToNow } from 'date-fns';
|
import { format, isToday, isYesterday, formatDistanceToNow } from 'date-fns';
|
||||||
|
|
||||||
type AnimatedMessageProps = {
|
type MessageElementProps = {
|
||||||
message: ChatMessagesProps;
|
message: ChatMessagesProps;
|
||||||
onDelete: (messageId: number) => void;
|
onDelete: (messageId: number) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const MessageElement = ({ onDelete, message }: AnimatedMessageProps) => {
|
const MessageElement = ({ onDelete, message }: MessageElementProps) => {
|
||||||
const { user } = useContext(AuthContext);
|
const { user } = useContext(AuthContext);
|
||||||
const { me, groupOwner } = useChat();
|
const { me, groupOwner } = useChat();
|
||||||
const [isRemoving, setIsRemoving] = useState(false);
|
const [isRemoving, setIsRemoving] = useState(false);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { useContext, useEffect, useRef, useState, useCallback } from 'react';
|
|||||||
import { socket } from '@/socket/socket.ts';
|
import { socket } from '@/socket/socket.ts';
|
||||||
import { sendContact } from '@/api/contactsApi.tsx';
|
import { sendContact } from '@/api/contactsApi.tsx';
|
||||||
import LoadingWheel from '../LoadingWheel.tsx';
|
import LoadingWheel from '../LoadingWheel.tsx';
|
||||||
import AnimatedMessage from '@/components/chat/chatArea/MessageElement.tsx';
|
import MessageElement from '@/components/chat/chatArea/MessageElement.tsx';
|
||||||
import { ChatMessagesProps } from '@/types/types.ts';
|
import { ChatMessagesProps } from '@/types/types.ts';
|
||||||
import { useChat } from '@/context/chat/useChat.ts';
|
import { useChat } from '@/context/chat/useChat.ts';
|
||||||
import { AuthContext } from '@/utils/AuthProvider.tsx';
|
import { AuthContext } from '@/utils/AuthProvider.tsx';
|
||||||
@@ -248,7 +248,7 @@ function MessagesArea() {
|
|||||||
<ul className="flex-grow list-none">
|
<ul className="flex-grow list-none">
|
||||||
{isLoading ? <LoadingWheel /> : null}
|
{isLoading ? <LoadingWheel /> : null}
|
||||||
{messages.map((msg: ChatMessagesProps) => (
|
{messages.map((msg: ChatMessagesProps) => (
|
||||||
<AnimatedMessage
|
<MessageElement
|
||||||
key={msg.message_id}
|
key={msg.message_id}
|
||||||
message={msg}
|
message={msg}
|
||||||
onDelete={() => deleteMessage(msg.message_id)}
|
onDelete={() => deleteMessage(msg.message_id)}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ function ContactForm() {
|
|||||||
|
|
||||||
console.log('Submit contact: ', contactToSubmit);
|
console.log('Submit contact: ', contactToSubmit);
|
||||||
const response: AxiosResponse<ContactsProps> = await axiosClient.post(
|
const response: AxiosResponse<ContactsProps> = await axiosClient.post(
|
||||||
`/api/chat/contact/${contactToSubmit}`,
|
`/api/chat/contacts/${contactToSubmit}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('contact post response: ', response.data);
|
console.log('contact post response: ', response.data);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export const ChatProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
console.log('Initialized contact: ', newContact);
|
console.log('Initialized contact: ', newContact);
|
||||||
try {
|
try {
|
||||||
const joinResult = await joinRoom(newContact.conversation_id);
|
const joinResult = await joinRoom(newContact.conversation_id);
|
||||||
|
|
||||||
if (!joinResult.success) {
|
if (!joinResult.success) {
|
||||||
setErrorMessage(joinResult.message);
|
setErrorMessage(joinResult.message);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import io from 'socket.io-client';
|
import io from 'socket.io-client';
|
||||||
|
|
||||||
import Socket = SocketIOClient.Socket;
|
import Socket = SocketIOClient.Socket;
|
||||||
let socket: Socket | null = null;
|
let socket: Socket | null = null;
|
||||||
function initializeSocket(token: string): Socket | null {
|
function initializeSocket(token: string): Socket | null {
|
||||||
@@ -8,6 +9,7 @@ function initializeSocket(token: string): Socket | null {
|
|||||||
reconnection: true,
|
reconnection: true,
|
||||||
reconnectionAttempts: 5,
|
reconnectionAttempts: 5,
|
||||||
reconnectionDelay: 1000,
|
reconnectionDelay: 1000,
|
||||||
|
transports: ['websocket', 'pooling'],
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('connect', () => console.log('connected'));
|
socket.on('connect', () => console.log('connected'));
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
const res = await axiosClient.get('/api/auth/validate', {
|
const res = await axiosClient.get('/api/auth/validate', {
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
});
|
});
|
||||||
|
if (!res.data.user_id) {
|
||||||
|
console.error('user_id is missing');
|
||||||
|
setAuthorized(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
setUser({ username: res.data.username, id: res.data.user_id });
|
setUser({ username: res.data.username, id: res.data.user_id });
|
||||||
console.info('user: : ', {
|
console.info('user: : ', {
|
||||||
username: res.data.username,
|
username: res.data.username,
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ app.put(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
app.post("/api/chat/contact/:contact", authorizeUser, async (req, res) => {
|
app.post("/api/chat/contacts/:contact", authorizeUser, async (req, res) => {
|
||||||
if (!req.params.contact) {
|
if (!req.params.contact) {
|
||||||
return res.status(400).json({ message: "Missing contact parameter" });
|
return res.status(400).json({ message: "Missing contact parameter" });
|
||||||
}
|
}
|
||||||
@@ -470,12 +470,6 @@ app.get(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
app.get(
|
|
||||||
"/api/chat/messages/lastMessage",
|
|
||||||
authorizeUser,
|
|
||||||
async (req, res) => {},
|
|
||||||
);
|
|
||||||
|
|
||||||
initializeSocket(io);
|
initializeSocket(io);
|
||||||
|
|
||||||
server.listen(PORT, () => {
|
server.listen(PORT, () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user